Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Dec 2012
Offline Last Active Feb 15 2016 02:03 AM

#5270235 why does visual studio do this?

Posted by Jossos on 09 January 2016 - 02:21 AM

In release mode it won't update the file when i clean/rebuild


It hits the first breakpoint, but won't actually enter the function:






Also this problem makes no sense:




it is empty yet it's clearing? i have that if statement specifically to stop it from doing that.

#5268944 Visual studio cannot compile 32bit or Release Mode

Posted by Jossos on 02 January 2016 - 11:21 PM

Ok so the Issue was with Assimp 3.1. I downgraded to 3.0 and now it works fine. 

#5221553 Looking for step my step guide for visual studio

Posted by Jossos on 05 April 2015 - 10:09 PM

Hello, I am working on an RTS myself, and I have been working on it for about a year (off and on). You will need to learn the graphics part separately first. I recommend lazyfoo or some other tutorials to learn the API. What you want is the ability to load and draw objects. I recommend having all of this loading and drawing in a 'Mesh' class, so you can just do 'Mesh.Draw'.


Actually your draw function will look like this:


pipeline.translate(xpos, 0, zpos)

pipeline.translate(unit angle);



You will of course have to write these translate/rotate functions yourself. They can be complicated because of matrix math, but google is your friend to find these functions, and you can wrap them up in a Matrix class.




I am by no means a master at this, as I am just following my gut, but I do have a working game with units that run around and kill each other etc. So I will describe how I did it, and you can take what you like


Firstly You have your main "Game" class, taking in whatever parameters you like, which runs everything and contains everything. You effectively run the game at 5 fps or 10 fps. You just have a timer set to 0.1 or 0.2 (for the seconds per frame a turn takes), and every frame you minus the time passed from that number. If it is below zero, you want to run a while loop that adds 0.1 or 0.2, and does the logic.

while(timer < 0.0)
   // Do Logic
   timer += 0.2;

This is super useful if you ever want to implement multiplayer because it makes the game deterministic rather than having the outcome change slightly depending on your frame rate.


During the logic phase you will step forward the movement, missiles, hits etc.minus hp. What is also good at running the game at 5fps is that it's a lot lighter on your CPU.



For Units, you want two classes.

UnitType - This is the specifications, such as maxHP, attack, speed, range, mesh to draw with etc.

UnitInstance - A generic unit that contains an object of UnitType. I have a reference for this in the class, however I'm not sure how references are done in c#. You could actually just copy over the details to the unit instance, its just each unit of the same time will be using memory to store their speed etc.

class UnitType
	string m_name;
	int m_maxHP;
	float m_speed; // I like to make it distance per second, or you could make it per turn to save some calculations
	int m_attack;
	float m_range;
	float LineOfSight;

		// set parameters to create all members.
class UnitInstance
	UnitType& m_unit;
	int m_hp;
	vector3f m_position;
	vector3f m_previousPosition;
	vector3f m_localPosition;

	int state;

	// Movement variables
	vector3f target;
	UnitInstance* unitTarget;

	Move(seconds passed);
	Attack(seconds passed);
	// etc

And you will have an array of UnitInstance's that you add/remove to as they are created/die (just check if hp < 0, then "kill"). You can start off with 1-3 UnitTypes, for example "Frigate" or "Battleship" etc, since you said its a naval battle game, and create your UnitInstance unit with a parameter of the "Battleship" object, and initialize the UnitInstance with the information from the Battleship (such as speed, hp = maxMP etc).


Also the reason I have "Previous position" in the UnitInstance is so that when the gameplay is occurring, units effectively animate at the machines framerate, going as fast as the GPU can render them. Here's how the function could look:

Game::MainLoop(float timePassed)

	// I'd recommend putting all this logic stuff in its own function
	time -= timePassed;

while(timer < 0.0)


   // Do Logic

   timer += 0.2;










The map design can help with further optimization. What I have is a map of tiles 128x128 (or watever it is), each tile has an array of units currently on it. the UnitInstance class has a variable for localPosition (which is its position on the tile). if the x or z goes below 0.0 or above 1.0, I then remove that unit from the array in the tile, and add it to the new til it's on.


Why this is so good, is that whenever you are check a range, you just check certain tiles. I did it like this:

class Tile
 	int* unitsOnTile;	// Since you're using C#, it will have to be int unitsOnTile[MAX_UNITS_PER_TILE];
	int numOfUnitsOnTile;

	void AddUnit(int ID)'
	void RemoveUnit(int ID);

The reason I made the list of units as an 'int' and not 'UnitInstance' is because the list is referring to the Unit's place in the UnitInstance array in the Game Class.




This is so efficient, because you only do certain functions whenever the unit changes tile. Like if the units tile changes, you then update the fogofwar. I am actually planning to add another list to my tileClass eventually, "int* unitsSeenBy" For units that can see the tile. That way I only ever have to do a checkAgro function every time units change tiles, thus saving even more processing power. Might be unnecessary for this amount of optimization.


Do you have questions about anything else? I am still working on this, and maybe other forum members can contribute more than me.

#5188129 Opengl Spazzing out for no reason

Posted by Jossos on 20 October 2014 - 06:54 AM

Hello everyone, I'm appropriately bumping this thread because once again, opengl is spazzing out just as it did before, only this time if i manually go into system and tell it to update it says I have the latest version, so I can't do what I did last time. Please help, as I cannot do anything productive with this happening

#5181026 Opengl Spazzing out for no reason

Posted by Jossos on 17 September 2014 - 09:08 AM

Well I'm happy to report that I was right all along.


After downloading and installing the driver, turns out i needed to go into my system, and tell the gpu to update its driver (again?). I don't understand this driver business, but all I know now is that it works.


I appreciate all your help. I actually found and tweaked a few little things in my code because you guys made me look.



#5180993 Opengl Spazzing out for no reason

Posted by Jossos on 17 September 2014 - 07:16 AM

So I'm making a c++ and opengl app, with bone transformations, and it is spazzing out for no reason. And I really mean no reason. I spent weeks on this app without any problems. Character walked etc, looked nice. Today I added shadows to the shader, no problem. Later on it started going crazy. like the matrices were totally distorted and the screen is raped with random triangles going crazy. Seizure inspiring.


Luckilly I had backed up this program about 8 times. Every single other previous version is doing the exact same thing. No other project is acting this way.


What the hell is going on? I can't find any problem in the code. This happened right after nvidia update, so not sure how to go about fixing this...


EDIT: If i Freeze the animation (as in only render same animtime constantly), it still spazzes out. What the hell is going on?? Doesn't happen when I negate the bone transformations from the shader though.

#5126910 A couple of small problems

Posted by Jossos on 28 January 2014 - 04:37 AM



I'm having a few issues with my application, and have a few queries. If you can help with any of them it would be greatly appreciated (These were all problems I gathered from not being able to find a solution on google).


I will list them here tl;dr version - maybe you can see what you might know:


1. Mipmapping isn't working

2. blending textures/quads to make a smooth transition between separate textures - not sure how to approach this

3. Being able layer 2 textures, or one texture with transparent parts showing a unique color (need multiple possible colors for a single object)

4. Importing Maya/3dsMax animation - More looking for guidance - will not attempt this in the next few months, but maybe after.



(Not OpenGL related, but I don't want to make too many topics - let me know if I should put these in a seperate thread)


5. How to determine if a chunk is in camera view - i.e. what to not render.

6. RTS drag selection - I know how to do one selection (with unit represented as a sphere and raysphering with the mouse), but how to drag a box like in all rts games, and have all units within that selected? I'm sure the math is really simple but I can't think of it.




Ok here are the questions in full:




1. Firstly, when I load a texture with mipmapping it just gives me a plain white texture (with value of -1). If I don't use mipmapping (enter mipmap as false), the texture renders fine, but looks like crap a long distance away.


My code is here:

int GRAPHICS::LoadTexture(const char *filename, bool mipmap, bool repeat)
	unsigned int id;
	glGenTextures(1, &id);
	SDL_Surface* img = IMG_Load(filename);

	if (img == NULL) 
		OutputDebugString("\" failed to load.\n");
		return -1;

	SDL_PixelFormat form = {NULL, 32, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 0, 255};
	SDL_Surface *img2 = SDL_ConvertSurface(img, &form, SDL_SWSURFACE);

	if (img2 == NULL)
		OutputDebugString("\" failed to load. img2 == -1\n");
		return -1;

	glBindTexture(GL_TEXTURE_2D, id);


	// Mipmapping
	if (mipmap)
		gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, img2->w, img2->h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img2->pixels);

	// Min Filter
	if (mipmap)

	// Repeat
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat ? GL_REPEAT : GL_CLAMP );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat ? GL_REPEAT : GL_CLAMP );


	return id;

Here's my Init function if you want to know that:

void GRAPHICS::Init(int width, int height, bool fullscreen)
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	Refresh(width, height, 45.0f, fullscreen);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations


And the refresh function:

void GRAPHICS::Refresh(int width, int height, float fov, bool fullscreen)
	if (fullscreen)
		SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL | SDL_FULLSCREEN);
		SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL);
	glViewport(0, 0, width, height);
		gluPerspective(fov, ((float)width*2) / (float)height, 0.1, 500.0);

2. Secondly, I need to have my textures blend together. I can't really describe it with words so I will post an image:




Left is my game so far, you can see the tiles don't blend, on the right is empire earth, the kind of thing I'm wanting to do. It's early enough that I can restructure my tile system. but I am not wanting to make a unique texture for blending every combination of tiles (coz there's a tonne if I want many variants of the tiles)




3. Thirdly, I want part of a texture to change color. I'm wanting to make an RTS - meaning many players can use the same units, but each unit needs to have part of their texture be a different colour. I do not know how to do this. I want to only need to load each object once. Look at right image above, see the blue on the little man, you can make this color anything in that game. That is what I am wanting.


What I was thinking with this is that If I could somehow just apply first a color (like blue or red), and on top of that apply the normal texture, and that texture's transparent parts will show through the color underneath. (For example, I could do glColor3f(1.0f, 0.0f, 0.0f) then glCallList of the object)




4. Fourthly, this is not so urgent, as I don't think I will implement this anytime soon, but is there a way to export animation the same way I export obj files? obj files are so good because they display each vertex, and I just read this data in. That's how I got the trees and the white dude in my scene, but I can't bring in any animation unless I export each frame as an object - something I'm not wanting to do.


I use Maya/3dsMax, any guidance is appreciated.




5. In my game, I have the world made of chunks, and each chunk contains 4x4 reference to tiles(I think it's better than just tiles on their own, maybe not feel free to give your opinion - I'm sure they might be helpful) - Is there a way to determine if one of these areas is not in view? At the moment I just draw everything, even if I can only see a few tiles.





6. RTS drag selection - Most info given in tl;dr -  I already have a way to get opengl positions from the mouse (close and far to cast ray in right direction), I'm just not sure of how to draw a box (which would be 2D for the player) and have it know everything inside. I mean, the camera can rotate, then might start dragging from a spot, and drag across many screens, making the start point actually off screen. So many problems, not sure how to solve.




Any help/or suggestions with any of these things will be greatly appreciated. I will tend to this thread when I'm not working. I am not a good programmer, so some of these might be really obvious, and I'm sorry if that is so.

#5020835 How to create minimap? (sdl/opengl)

Posted by Jossos on 12 January 2013 - 02:35 PM

Then show some code pls. I cant foresee what you've already implemented and what you are lacking or what the problem precisely is.. =/

I'm not sure if u really need code to tell me how to draw pixels, but I'll provide some relevant code as you wish.


struct TILE
	int TileType;
	bool obstructed;

class map
	map(int h, int w);

	int getTileTexture(int x, int y);
	int m_height, m_width;
	TILE **m_map;



My tile struct and map class.


class Game : public GameState
	Game(int w, int h);

	void HandleEvents();
	void logic();
	void render();
	void loadTiles();

	void scroll();
	void scrollStuff();
	void checkScreen();

	void drawHUD();
	void drawTiles();
	map *myMap;
	int m_width;
	int m_height;

	float scrPosX;
	float scrPosY;

	float scrTilesW;
	float scrTilesH;

	unsigned int hud;
	unsigned int *tileTextures;

	bool scrMoveDown;
	bool scrMoveUp;
	bool scrMoveLeft;
	bool scrMoveRight;

	bool scrBMoveDown;
	bool scrBMoveUp;
	bool scrBMoveLeft;
	bool scrBMoveRight;


My game class (all you really need to care about is the "map *myMap;")


void Game::render()
	glOrtho(0, Screen_Width, Screen_Height, 0, -1, 1);




The render function


void Game::drawTiles()
	// Set i to the very left tile (in regards to the screen)
	for (int i = (scrPosX - (scrTilesW / 2)); i < scrPosX + (scrTilesW / 2); i++)
		// Set j to the very top tile (in regards to the screen)
		for (int j = (scrPosY - (scrTilesH / 2)); j < scrPosY + (scrTilesH / 2); j++)
			if (i >= 0 && i < m_width && j >= 0 && j < m_height)
				int startX = (i - (scrPosX - (scrTilesW / 2))) * (Screen_Width / scrTilesW);
				int startY = (j - (scrPosY - (scrTilesH / 2))) * (Screen_Height / scrTilesH);

				// Bind tile texture
				glPushMatrix();		// Start phase
				glBindTexture(GL_TEXTURE_2D, tileTextures[myMap->getTileTexture(i, j)]);
					glTexCoord2d(0, 0); glVertex2f(startX, startY);
					glTexCoord2d(1, 0); glVertex2f(startX + (Screen_Width / scrTilesW), startY);
					glTexCoord2d(1, 1); glVertex2f(startX + (Screen_Width / scrTilesW), startY + (Screen_Height / scrTilesH));
					glTexCoord2d(0, 1); glVertex2f(startX, startY + (Screen_Height / scrTilesH));
				glPopMatrix();		// End phase


The function that actually draws the tiles on the screen (and only tiles u can actually see)


No idea what kinda code you really wanted, so I just provided everything that's relevant. I think I underestimated the difficulty of creating a minimap. Still, I'm waiting for a genius to solve this ;)

#5020658 How to create minimap? (sdl/opengl)

Posted by Jossos on 12 January 2013 - 05:21 AM

Hey there. I was wondering how I would go about creating a minimap for this application. It needs to be dynamic, in that the screen could be any size, and the map could be any size (probably no more than 256x256). binding this to an opengl quad would solve any resizing issues, but i dont know if that's possible.


Help is appreciated!



#5012913 SDL IMG_load function crashing the program

Posted by Jossos on 20 December 2012 - 02:25 PM

Alright, so apparently I had to paste zlib1.dll in my project. Works fine now