Hello Everyone,
i have built this skybox using the following code:
static GLuint texName[6];
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
for (int i = 0; i < 6/* Skybox */; i++) {
readBMP(texFileNames[fileNo++], checkImageWidth, checkImageHeight); // reading from BMP files
glGenTextures(1, texName + i);
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
checkImageHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, texelDataBMP);
}
}
void keyBoard(unsigned char a, int x, int y)
{
if (a == 'a')
rotAng += 10;
glutPostRedisplay();
}
void drawTexturedFace()
{
glBindTexture(GL_TEXTURE_2D, texName[texFlag++]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -2.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 2.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(2.0, 2.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(2.0, -2.0, 0.0);
glEnd();
}
void display(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 1,
0, 0, 0,
0, 1, 0);
glRotatef(rotAng, 0, 1, 0);
// Front face
glPushMatrix();
glTranslatef(0, 0, -2);
drawTexturedFace();
glPopMatrix();
// Top Face
glPushMatrix();
glTranslatef(0, 2, 0);
glRotatef(90, 1, 0, 0);
drawTexturedFace();
glPopMatrix();
// Bottom Face
glPushMatrix();
glTranslatef(0, -2, 0);
glRotatef(-90, 1, 0, 0);
drawTexturedFace();
glPopMatrix();
// Left Face
glPushMatrix();
glTranslatef(-2, 0, 0);
glRotatef(90, 0, 1, 0);
drawTexturedFace();
glPopMatrix();
// Right Face
glPushMatrix();
glTranslatef(2, 0, 0);
glRotatef(90, 0, -1, 0);
drawTexturedFace();
glPopMatrix();
// Back Face
glPushMatrix();
glTranslatef(0, 0, 2);
glRotatef(180, 0, 1, 0);
drawTexturedFace();
glPopMatrix();
glutSwapBuffers();
}
Now, is there any way i can optimize it further(other than using VBOs)
Is there any way i could improve, say drawTexturedFace()?
PS: init() is called just once, initially when the program starts.
Any suggestions would be helpful.
Thanks in advance.