Mikhail
Mikhail

Reputation: 8028

Why does my unsigned byte need to be twice as big?

I am in the process of disconnecting the rendering portion of my program from Qt and upgrading it to OpenGL 4.

I ran into an oddity concerning textures, I am getting a segfault for not supplying glTexImage with the right size data. Which is strange because I am pretty sure I am supplying it with the right size data.

int n = 1*g_windowHeight*g_windowHeight;
//int n = 2*g_windowHeight*g_windowHeight; Doesn't segfault but doesn't make sense to me
auto data = (GLbyte*) malloc(n*sizeof(GLbyte));
glBindTexture(GL_TEXTURE_2D,textures[i]);
glTexImage2D(GL_TEXTURE_2D,0,GL_R8,g_windowWidth,g_windowHeight,0,GL_RED,GL_UNSIGNED_BYTE,data); //

Unhandled exception at 0x0000000180012212 (ig4icd64.dll) in renderMan.exe: 0xC0000005: Access violation reading location 0x0000007035F7C000.

Why does GL_R8 want a 2 bytes per pixel if I am using GL_R8?

Upvotes: 2

Views: 140

Answers (1)

trojanfoe
trojanfoe

Reputation: 122391

It's a typo:

int n = 1*g_windowHeight*g_windowHeight;

Should be:

int n = 1*g_windowWidth*g_windowHeight;
//                ^^^^^

Upvotes: 9

Related Questions