Sign in to follow this  

Why? The length of the triangle side is the same as the window's size?

This topic is 4863 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

this is the code I wrote: int InitGL ( GLsizei Width, GLsizei Height ) { glClearColor(1.0f, 1.0f, 1.0f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glViewport ( 0, Width, 0, Height ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Reset The Projection Matrix gluOrtho2D ( 0, Width, 0, Height ); glMatrixMode(GL_MODELVIEW); } GLvoid ReSizeGLScene ( GLsizei Width, GLsizei Height ) { if ( Height == 0 ) Height = 1; glViewport ( 0, 0, Width, Height ); glMatrixMode ( GL_PROJECTION ); glLoadIdentity (); // gluOrtho2D ( 0, Width, 0, Height ); gluPerspective ( 0.0f, (GLfloat) Width / (GLfloat) Height, 0.1f, 100.0f ); glMatrixMode ( GL_MODELVIEW ); } GLvoid DrawGLScene ( GLvoid ) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glBegin(GL_POLYGON); // start drawing a polygon glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red glVertex3f( 0.0f, 0.1f, 0.0f); // Top glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green glVertex3f( -0.1f,-0.1f, 0.0f); // Bottom Right glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue glVertex3f(0.1f,-0.1f, 0.0f); // Bottom Left glEnd(); glutSwapBuffers (); } The triangle I draw is like this : one side from the middle point of the top of the window to the right bottom point of the window, one side from the middle point to the left bottom point of the window, one side is from right bottom point to left bottom point of the window. I donot understand why I get this result. If I want to draw a triangle in pixels , how can I do? thanks a lot. ( confusing )

Share this post


Link to post
Share on other sites
actually, I want to draw in pixels ,

I found code below on opengl resources webpage which said I can use to change unit to pixel :

glViewport(0, 0, screen_width, screen_height);
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ();
gluOrtho2D ( 0, screen_width, 0, screen_height );


But after I added this in DrawGLScreen(), it didnot work.

Share this post


Link to post
Share on other sites
Quote:
Original post by doutmost
actually, I want to draw in pixels ,

I found code below on opengl resources webpage which said I can use to change unit to pixel :

glViewport(0, 0, screen_width, screen_height);
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ();
gluOrtho2D ( 0, screen_width, 0, screen_height );


But after I added this in DrawGLScreen(), it didnot work.


Replace your ReSizeGLScene function with:


GLvoid ReSizeGLScene ( GLsizei Width, GLsizei Height )
{
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Width, 0, Height, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


Note that the polygon you're trying to draw will probably be too small to see at this point.

Share this post


Link to post
Share on other sites

This topic is 4863 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this