I’m new in OpenGL.
I want to draw an bitmap image in my Windows application using OpenGL. But image should be draw in its same width and height. For example, let say image size is width:156px & Height:93px.
I don’t know how to render this image in my Windows GUI using OpenGL by keeping the same width and height.
See my code below,
Assume that already bitmap image is loaded as texture, I want to load full image in its original size in Windows
void drawImage()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, m_unTextureId);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 1.0f); glVertex2f( -0.5, 0.5 ); // Top Left Vertex
glTexCoord2f(1.0f, 1.0f); glVertex2f( 0.5, 0.5 ); // Top Right Vertex
glTexCoord2f(1.0f, 0.0f); glVertex2f( 0.5, -0.5 ); // Bottom Right Vertex
glTexCoord2f(0.0f, 0.0f); glVertex2f( -0.5, -0.5 ); // Bottom Left Vertex
glEnd();
glFlush();
glFinish();
SwapBuffers( m_hDC );
}
Above code will draw the bitmap correctly, but size is not as original image.
Texture loading code as shown below,
bool LoadTexture(CString csTextureFile_i)
{
AUX_RGBImageRec *pTextureImage = auxDIBImageLoad( csTextureFile_i );
if( pTextureImage != NULL )
{
glGenTextures( 1, &m_unTextureId );
glBindTexture( GL_TEXTURE_2D, m_unTextureId );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, 3, pTextureImage->sizeX, pTextureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pTextureImage->data );
}
if( pTextureImage )
{
if( pTextureImage->data )
free( pTextureImage->data );
free( pTextureImage );
}
return true;
}
Please help.
Thanks.