Why? The length of the triangle side is the same as the window's size?
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 )
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).
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement