Jump to content
  • Advertisement
Sign in to follow this  
doutmost

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

This topic is 5150 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
Advertisement
After the glLoadIdentity call, try adding glTranslatef(0, 0, -10). I assume you're expecting the screen to be in some 3:2 ratio like 800x600, you can simulate that with an orthographic projection (see glOrtho).

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
one more question: Does how to explain opengl function depend on different operation system? say, for windows, linux, unix,..., it is possible they they will show different figures for the same code?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!