Jump to content

  • Log In with Google      Sign In   
  • Create Account

Get blank screen in modelview, don't know why


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Jossos   Members   -  Reputation: 224

Like
0Likes
Like

Posted 27 October 2013 - 05:12 AM

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!



Sponsor:

#2 Sponji   Members   -  Reputation: 1361

Like
1Likes
Like

Posted 27 October 2013 - 06:52 AM

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

Derp

#3 Jossos   Members   -  Reputation: 224

Like
0Likes
Like

Posted 28 October 2013 - 02:59 AM

 

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();
}


#4 Brother Bob   Moderators   -  Reputation: 8631

Like
1Likes
Like

Posted 28 October 2013 - 03:51 AM

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.



#5 Jossos   Members   -  Reputation: 224

Like
0Likes
Like

Posted 28 October 2013 - 03:21 PM

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



#6 Jossos   Members   -  Reputation: 224

Like
0Likes
Like

Posted 28 November 2013 - 01:35 AM

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();
}


#7 Sponji   Members   -  Reputation: 1361

Like
0Likes
Like

Posted 28 November 2013 - 03:41 AM

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.


Derp

#8 Jossos   Members   -  Reputation: 224

Like
0Likes
Like

Posted 03 December 2013 - 11:29 PM

Edit: Thanks all, working nice now.


Edited by Jossos, 04 December 2013 - 12:10 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS