Jump to content
  • Advertisement
Sign in to follow this  
Jossos

OpenGL Get blank screen in modelview, don't know why

This topic is 2056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not understanding why I can't get anything rendered to the screen. I have code very similar to this in another program which renders fine, but this program just gives me a blank screen.

 

Here's my initialization code:

void GRAPHICS::InitGraphics(SDL_Surface* screen, bool fullscreen, int width, int height)
{
	SDL_Init(SDL_INIT_EVERYTHING);

	glClearColor(0.0, 0.0, 0.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(35.0, width / height, 0.2, 500.0);

	//SetScreenAttributes(screen, fullscreen, width, height);
	SDL_SetVideoMode(width, height, 32, SDL_OPENGL);

	glMatrixMode(GL_MODELVIEW);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

And here's my render function:

void GAME::Render()
{
		// ** Clear the screen and translations for a new render ** //
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glMatrixMode(GL_PROJECTION);
	glOrtho(0, header.scrWidth, header.scrHeight, 0.0, -1.0, 1.0);
	glColor3f(1.0f, 1.0f, 1.0f);

	// 2D drawings here

		// ** Put all Drawing data here ** //

	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	gluPerspective(35.0, (float)header.scrWidth / (float)header.scrHeight, 0.2, 500.0);

	glColor3f(1.0f, 1.0f, 1.0f);

	glBegin(GL_TRIANGLES);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(0.5f, 0.0f, 0.0f);
		glVertex3f(0.0f, 0.5f, 0.0f);
	glEnd();

	SDL_GL_SwapBuffers();
}

I'm sure the fault lies somewhere in one of these functions. I have other code, but for now a simple triangle on the screen would be nice, but I can't even get that. the clear color is black by the way.

 

Help is greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement

You're using glLoadIdentity weirdly, and also you should not use gluPerspective for modelview matrix. Also, you probably want to set the triangle's z to something like -1 so you can actually see it.

// Set up projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Load identity matrix to the current matrix mode, projection
gluPerspective(...);

// Set up modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // Load identity matrix to the current matrix mode, modelview

// Draw
glBegin(GL_TRIANGLES);
// ...
glEnd();

Share this post


Link to post
Share on other sites

 

You're using glLoadIdentity weirdly, and also you should not use gluPerspective for modelview matrix. Also, you probably want to set the triangle's z to something like -1 so you can actually see it.

 

 

Thanks, but I still have a blank screen.

 

My render function now:

void GAME::Render()
{
		// ** Clear the screen and translations for a new render ** //
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(35.0, (float)header.scrWidth / (float)header.scrHeight, 0.2, 500.0);

		// ** Put all Drawing data here ** //

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glColor3f(1.0f, 1.0f, 1.0f);

	glBegin(GL_TRIANGLES);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(0.5f, 0.0f, 0.0f);
		glVertex3f(0.0f, 0.5f, 0.0f);
	glEnd();

	SDL_GL_SwapBuffers();
}

Share this post


Link to post
Share on other sites

Take Sponji's second sentence as an advice again. Your projection matrix has a visible depth range from Z=-0.2 to Z=-500, and you draw your triangle at Z=0, so it's not visible.

Share this post


Link to post
Share on other sites

Take Sponji's second sentence as an advice again. Your projection matrix has a visible depth range from Z=-0.2 to Z=-500, and you draw your triangle at Z=0, so it's not visible.

Yeah sorry, I did that and still nothing. I set the z to -5.0 and still blank. sorry for bein such a noob

Share this post


Link to post
Share on other sites

sorry for bumping, but i really cannot get this working and have no idea why. i have 2 triangles, one at z -5 and z 5, just blank screen -.-

void GAME::Render()
{
		// ** Clear the screen and translations for a new render ** //
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	gluPerspective(35.0, 1280 / 720, 0.2, 500.0);

		// ** Put all Drawing data here ** //

	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	glColor3f(1.0f, 1.0f, 1.0f);
	//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

	glBegin(GL_TRIANGLES);
		glVertex3f(0.0f, 0.0f, -5.0f);
		glVertex3f(0.5f, 0.0f, -5.0f);
		glVertex3f(0.0f, 0.5f, -5.0f);

		glVertex3f(0.0f, 0.0f, 5.0f);
		glVertex3f(0.5f, 0.0f, 5.0f);
		glVertex3f(0.0f, 0.5f, 5.0f);
	glEnd();

	SDL_GL_SwapBuffers();
}

Share this post


Link to post
Share on other sites

You're resetting your projection matrix with glLoadIdentity? You should change to modelview matrix first, then call glLoadIdentity and it will reset the modelview matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!