Jump to content

  • Log In with Google      Sign In   
  • Create Account


glTexImage2D does nothing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Somone else   Members   -  Reputation: 112

Like
0Likes
Like

Posted 24 May 2012 - 08:14 AM

I'm using SDL_image to load textures for my game, I then try to load them into OpenGL using glTexImage2D.

Using the following code I've found out, that the problem lies in glTexImage2D, as it simply does nothing. (at least the width and height of the texture remains unchanged)
int ID,Width,Height;

glGetIntegerv(GL_TEXTURE_BINDING_2D,&ID);
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&Width);
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&Height);

std::cout << ID << ": " << Width << "*" << Height << std::endl;

The weird thing is that I have another program, and it uses the exact same code, but it works in that program.

glGetError returns 0 ie no error.

The code loading the texture and all is compiled and linked into a static library, and I have a test project that links with it, so I can see, if the code I've written works or not.

Sponsor:

#2 FLeBlanc   Crossbones+   -  Reputation: 3101

Like
0Likes
Like

Posted 24 May 2012 - 08:46 AM

Post the relevant code where glTexImage2D is actually called.

#3 Somone else   Members   -  Reputation: 112

Like
0Likes
Like

Posted 24 May 2012 - 09:05 AM

Here you go:
Clear();

SDL_Surface *Surf = IMG_Load(File.c_str());

if(!Surf) return false;

GLenum Mode = GL_RGB;
if(Surf->format->BytesPerPixel == 4){
    Mode = GL_RGBA;
}

Width = Surf->w;
Height = Surf->h;

glGenTextures(1,&Tex);
glBindTexture(GL_TEXTURE_2D,Tex);

glTexImage2D(GL_TEXTURE_2D,0,Mode,Width,Height,0,Mode,GL_UNSIGNED_BYTE,Surf->pixels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

int Min,Mag;

glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,&Min);
glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,&Mag);

SDL_FreeSurface(Surf);

glBindTexture(GL_TEXTURE_2D,0);


#4 FLeBlanc   Crossbones+   -  Reputation: 3101

Like
0Likes
Like

Posted 24 May 2012 - 10:07 AM

Have you checked to make sure that the GL context is valid and initialized?

#5 Somone else   Members   -  Reputation: 112

Like
0Likes
Like

Posted 24 May 2012 - 02:25 PM

wglGetCurrentContext() doesn't return NULL. I don't know if there is more to check than that.

#6 mhagain   Crossbones+   -  Reputation: 7823

Like
0Likes
Like

Posted 24 May 2012 - 07:08 PM

Check your width and height to make sure that they're powers of two if you have older hardware that doesn't support non-power-of-two textures. Also given that you're using GL_RGB formats you should be setting your glPixelStorei parameters appropriately.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 26 May 2012 - 08:00 AM

Check your width and height to make sure that they're powers of two if you have older hardware that doesn't support non-power-of-two textures. Also given that you're using GL_RGB formats you should be setting your glPixelStorei parameters appropriately.


If it is a power of 2 problem, then glGetError() would return something other than GL_NO_ERROR.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#8 Somone else   Members   -  Reputation: 112

Like
0Likes
Like

Posted 27 May 2012 - 05:07 AM

After fiddling around with the code for a bit, it appears that I've solved the problem.
I don't know what caused it though.

#9 Sponji   Members   -  Reputation: 1215

Like
0Likes
Like

Posted 27 May 2012 - 12:28 PM

I'm not sure, but shouldn't glTexParameters be called before glTexImage2D? Maybe that fixed it?
Derp

#10 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 27 May 2012 - 08:51 PM

I'm not sure, but shouldn't glTexParameters be called before glTexImage2D? Maybe that fixed it?


No, it doesn't matter of you call it after or before.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#11 Somone else   Members   -  Reputation: 112

Like
0Likes
Like

Posted 28 May 2012 - 03:03 PM

Turns out I only fixed the code for "power of 2"-textures.
My graphics card does support GL_ARB_texture_non_power_of_two, and in my other project it worked absolutely fine.

#12 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 30 May 2012 - 07:30 AM

Turns out I only fixed the code for "power of 2"-textures.
My graphics card does support GL_ARB_texture_non_power_of_two, and in my other project it worked absolutely fine.


Are you sure glGetError doesn't detect any problems?
Also, what is your GL version?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#13 Somone else   Members   -  Reputation: 112

Like
0Likes
Like

Posted 30 May 2012 - 09:18 AM

Are you sure glGetError doesn't detect any problems?
Also, what is your GL version?

This time, errors did appear.
I traced (due to the lack of a better word) it back to the SDL OpenGL configuration: I apparently didn't enable SDL_GL_MULTISAMPLEBUFFERS.

~Solved




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS