I am trying to set up a 2D rendering system using openGl gluOrtho2D(0,640,0,480) .But even though the 2D co-ordinate system is created properly i can only draw textures using normalized co-ordinates in the range from 0 to 1.
eg glTexCoord2f(1.0f, 0.0f); glVertex3d(1.0f, 0.0f,0);
As shown below the textured quad fills 1 quadrant of the screen.But i have distintly seen examples where i can use proper co-ordinates
eg glTexCoord2f(1.0f, 0.0f); glVertex3d(23.0f, 43.0f,0);
Drawing with normalized co-ordinates is inconvenient & i cant understand why its not accepting proper co-ordinates.The textured quad below should not fill 1 quadrant of the screen(from center 0,0,0 to top-right). I also use SDL for Windowing
void DrawGLScene( void )
{
/* Clear the color and depth buffers. */
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity( );
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texture[filter]);//Rotation
glRotatef(xrot, 0.0, 0.0, 1.0);
/* Send our triangle data to the pipeline. */
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3d(0.0f, 0.0f,0);
glTexCoord2f(1.0f, 0.0f); glVertex3d(1.0f, 0.0f,0);
glTexCoord2f(1.0f, 1.0f); glVertex3d(1.0f, 1.0f,0);
glTexCoord2f(0.0f, 1.0f); glVertex3d(0.0f, 1.0f,0);
glEnd();
SDL_GL_SwapBuffers( );
xrot += xspeed;
//yrot += yspeed;
}
How i set up openGL
//set up misc openGL attributes
BOOL setup_opengl(void )
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine
{
return FALSE; // If Texture Didn’t Load Return FALSE
}
//glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
/* Our shading model--Gouraud (smooth). */
glShadeModel( GL_SMOOTH );
/* Set the clear color. */
glClearColor( 0, 0, 0, 0 );
//glClearDepth(1.0f); // Depth Buffer Setup
//glEnable(GL_DEPTH_TEST); // Enables Depth Testing
//glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glColor4f(1.0f, 1.0f, 1.0f, 0.5); // Full Brightness. 50% Alpha
// glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency
return TRUE; // Initialization Went OK
}
How i set up the view volume
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
// Calculate The Aspect Ratio Of The Window
gluOrtho2D(0, 640, 0, 480);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}