Jump to content

  • Log In with Google      Sign In   
  • Create Account

Jossos

Member Since 19 Dec 2012
Offline Last Active Today, 04:46 AM

#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

Hi,

 

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)
{
	glEnable(GL_TEXTURE_2D);
	unsigned int id;
	glGenTextures(1, &id);
	SDL_Surface* img = IMG_Load(filename);

	if (img == NULL) 
	{
		OutputDebugString("\"");
		OutputDebugString(filename);
		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("\"");
		OutputDebugString(filename);
		OutputDebugString("\" failed to load. img2 == -1\n");
		return -1;
	}

	glBindTexture(GL_TEXTURE_2D, id);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

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

	// Min Filter
	if (mipmap)
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	else
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

	// 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 );

	SDL_FreeSurface(img);
	SDL_FreeSurface(img2);

	return id;
}

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

void GRAPHICS::Init(int width, int height, bool fullscreen)
{
	SDL_Init(SDL_INIT_EVERYTHING);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	Refresh(width, height, 45.0f, fullscreen);
	glMatrixMode(GL_MODELVIEW);
	glEnable(GL_DEPTH_TEST);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);

	glLoadIdentity();
}

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);
	else
		SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL);
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		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:

 

Jos_Game_Scr_Shot.jpg

 

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
{
public:
	map(int h, int w);
	~map();

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

 

 

My tile struct and map class.

 

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

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

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

	void drawHUD();
	void drawTiles();
private:
	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()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
	glOrtho(0, Screen_Width, Screen_Height, 0, -1, 1);

	drawTiles();

	drawHUD();
	drawCursor();
}

 

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
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D, tileTextures[myMap->getTileTexture(i, j)]);
				glBegin(GL_QUADS);
					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));
				glEnd();
				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!

 

scrshotty.jpg




#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


PARTNERS