Thank you for the overview. I have some reading to do…
Can you please review the following code for anything that is abnormal or missing? It is a hybrid of the posted example code and some example OpenGl Super Bible code.
The code loads and displays a 720x486 bitmap very badly. The screen is divided into a number of blocky areas where I can not make out details and possibly data is duplicated within the blocks. However, the colors and orientation of contrasts are about right. I’m thinking something to do with size or resolution?
Thanks in advance,
-Ed
void SetupRC(void)
{
StructBitmap* pBitmap = LoadBitMap(“frame_720_486.bmp”);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Black background
GLbyte* textureData = (GLbyte*)pBitmap->pData;
GLsizei width = pBitmap->headerBitMapInfo.biWidth;
GLsizei height = pBitmap->headerBitMapInfo.biHeight;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, m_texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, (GLvoid*)textureData);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
}
void TextureRender(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the window with current clearing color
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glPushMatrix();
glDisable(GL_LIGHTING); // Draw plane that the cube rests on
glEnable(GL_TEXTURE_2D); // should use shader, but for an example fixed pipeline is ok
glBindTexture(GL_TEXTURE_2D, m_texture[0]);
glBegin(GL_TRIANGLE_STRIP); // draw something with the texture on
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, -1.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0, 1.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 1.0);
glEnd();
glPopMatrix();
glutSwapBuffers(); // Flush drawing commands
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(720,486);
m_window = glutCreateWindow(“2D Image Texture 720x486”);
glutKeyboardFunc(&TextureKeyPressFunc);
glutDisplayFunc(&TextureRender);
SetupRC();
glutMainLoop();
glDeleteTextures(1,m_texture);
return 0;
}