Guy Shalom
Guy Shalom

Reputation: 41

glTexImage2D is not working when using GL_TEXTURE_RECTANGLE

I am trying to write a "BMP player". My main objective is to do it fast! I need to get to 60fps. I am loading all images to memory and then using glTexImage2D to switch the texture content.

when I use the command:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_width, g_height, 0, GL_RGB, GL_UNSIGNED_BYTE, currentlyPlatedFrame->data);

the movie works fine (60fps) on low resolutions (720p and lower) but it has a very low frame rate on HD or higher (I need to get to 1600p).

I did some search online and found that GL_TEXTURE_2D works on square textures with power of 2, which means that when playing 1920x1080 I am actually playing 2048x2048 (a squer with the next power of 2 after 1280) and to make my program faster I need to use GL_TEXTURE_RECTANGLE.

my problem is that when I change all the GL_TEXTURE_2D in my code to GL_TEXTURE_RECTANGLE my player shows only the first pixel on the entire screen.

is there something else that I need to change when switching from 2D to RECTANGLE? can anyone see what I'm doing wrong? or if you have an idea on how to use GL_TEXTURE_2D but do it faster it would help me a lot.

i'm working on win7 and VS2010

my code (the relevant part):

#include <glew.h>
#include <glfw.h>

glfwInit();
glEnable(GL_DEPTH_TEST);
glEnable( GL_TEXTURE_2D );  
if( !glfwOpenWindow( g_width, g_height, 8, 8, 8, 0, 0, 0, GLFW_FULLSCREEN ))
{
    glfwTerminate(); //terminating glfw window
    return 0;
}

glfwSetWindowTitle("Texture");
glfwSetWindowSizeCallback(handleResize);
glfwSetKeyCallback(handleKeypress);
glfwEnable(GLFW_MOUSE_CURSOR);
glfwSwapInterval(1);

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //clear background screen to black

    //Clear information from last draw
glClear( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); 

    glGenTextures(1,&Texture); //allocate the memory for texture
    glBindTexture(GL_TEXTURE_2D,Texture); //Binding the texture

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D); //Enable texture

currentlyPlatedFrame = goToFirstFrameToPlay(headOfList,startFrameNum);

glBindTexture(GL_TEXTURE_2D,Texture);
while (1)
{ 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_width, g_height, 0, GL_RGB, GL_UNSIGNED_BYTE, currentlyPlatedFrame->data);

    glPushMatrix();//move out of loop
    glBegin(GL_POLYGON); //Begin quadrilateral coordinates
    glNormal3f(0.0f, 0.0f, 1.0f);//normal vector
    glTexCoord2f(0.0f, 0.0f); //Texture co-ordinate origin or  lower left corner
    glVertex3f(-1.0f,-1.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f); //Texture co-ordinate lower right corner
    glVertex3f(1.0f,  -1.0f,0.0f);
    glTexCoord2f(1.0f, 1.0f);//Texture co-ordinate top right corner
    glVertex3f(1.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f, 1.0f);//Texture co-ordinate top left corner
    glVertex3f(-1.0f, 1.0f, 0.0f);
    glEnd(); //End quadrilateral coordinates
    glPopMatrix();//move out of loop
    glFinish();//add glfinish
    glfwSwapBuffers();
    numOfPlayedFrames++;

    currentlyPlatedFrame = currentlyPlatedFrame->next;
}

Upvotes: 3

Views: 2722

Answers (1)

shinji
shinji

Reputation: 21

For those visitors who came here for a solution; When using a rectangle texture, coordinates must be specified in (0,0) - (tex_width, tex_height) range, not (0,0) - (1,1).

Upvotes: 2

Related Questions