OpenGL basic question

Started by
4 comments, last by Fella 17 years, 11 months ago
I am trying to draw a single big rectangle representing ground. The following code displays nothing. I have tried translating the ground forward and backwards the z axis but still the ground does not get displayed. Can anybody help?

void drawGround(){
	glBegin( GL_QUADS );
		glVertex3f( -200.0f, 0.0f, 200.0f );
		glVertex3f( 200.0f, 0.0f, 200.0f );
		glVertex3f( 200.0f, 0.0f, -200.0f);
		glVertex3f( -200.0f, 0.0f, -200.0f);
	glEnd();
}

void setupRC(){
	glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
	glEnable( GL_DEPTH_TEST );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 45.0f, width/height, 1, 500 );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
}

void render(){
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	glColor3f( 1.0f, 0.0f, 0.0f );
	drawGround();

	glutSwapBuffers(); 
}

int main( int argc, char* argv[] ){
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
	glutInitWindowSize( width, height );
	glutCreateWindow("test");
	glutDisplayFunc( render );
	glutIdleFunc( render );
	setupRC();
	glutMainLoop();

	return 0;
}



People of the Earth unite!
Advertisement
At first look - when is setupRC being called? And I'm pretty sure that by default the view is set up to look down the -Z axis from point 0,0,0. Your camera will be on the quad - try setting glutLookAt() to something appropriate so you know definitely where it is supposed to be - something like

prototype:
glutLookAt(float fromX, float fromY, float fromZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ);

glutLookAt(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f).

forgive me if I'm incorrect - haven't used glut stuff for yonks
Sorry there was a typo - setupRC does get called in main(). After putting gluLookAt(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f) in the code now the whole screen is filled with red color. This means the ground is getting rendered but why can not I see it when using the above code?
People of the Earth unite!
glutLookAt sets up the projection matrix to simulate a camera with those parameters. You've essentially said: I want a camera. Put it at position (0, 10, 0), and orientate it so that it looks at the point (0,0,0). In addition, make the up vector for the camera (0, -1, 0) - giving the final information needed to properly transform the viewing matrix.

So basically, your camera is above the quad you've set up, looking straight down at it.

Previously you hadn't specified this - and your camera was at 0,0,0, looking parallel to the plane, whilst also being on the plane. Crap analogy time: Think of it as putting your eye at the same level as an infinitely thin piece of paper. It has no thickness from that perspective, so it's not visible
Got it thanks!
People of the Earth unite!
Quote:Original post by Anonymous Poster
glutLookAt(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f).


Why did you set the 'UP' vector as ( 0.0, 0.0, -1.0 ). Should it be (0.0, 1.0, 0.0)?

People of the Earth unite!

This topic is closed to new replies.

Advertisement