hi,
im having a problem with my program. so im trying to draw a viewport, save it as a texture, and draw it on another object. im planning to do a deffered shading and treat the texture as a buffer. i use the glCopyTexSubImage2D to perform this task. here is the sniplet of my code:
void drawOrbit() {
glDisable(GL_TEXTURE_2D);
glPushMatrix();
glViewport(0, 0, (GLsizei)textureWidth, (GLsizei)textureHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (GLdouble)textureWidth/(GLdouble)textureHeight, 0.1, 5);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.0, 0.0, -1.0);
glBegin(GL_QUADS);
{
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.9,0.9,0);
glVertex3f(-0.9,0.9,0);
glVertex3f(-0.9,-0.9,0);
glVertex3f(0.9,-0.9,0);
}
glEnd();
glPopMatrix();
glEnable(GL_TEXTURE_2D);
}
void display() {
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
drawOrbit();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureWidth, textureWidth);
//glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
gluPerspective(20, (GLdouble)width/(GLdouble)height, 0.1, 5);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.0, 0.0, -1.0);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
{
glColor3f(1.0, 0.0, 1.0);
glTexCoord2f(1, 1); glVertex3f(1,1,0);
glTexCoord2f(0, 1); glVertex3f(-1,1,0);
glTexCoord2f(0, 0); glVertex3f(-1,-1,0);
glTexCoord2f(1, 0); glVertex3f(1,-1,0);
}
glDisable(GL_TEXTURE_2D);
glEnd();
//glFlush();
glutSwapBuffers();
glutPostRedisplay();
FPS();
std::cout << gFramesPerSecond << std::endl;
}
its pretty simple: the main display method is display() and the viewport to be saved as a texture is drawOrbit. The performance shows 20 fps. When i disable the texturing (simply by commenting all glEnable(GL_TEXTURE_2D) commands, but still doing other task such as drawing the 2 viewports and copying it as a texture), the fps rise to 120. Is texturing that expensive? How can I trick it? in my program, i simply draw two object. is it normal to have such fps drop when performing texture?
thanks in advance