Simple texturing problem
Hi, I''ve been having trouble getting texturing going in some of my apps.
I downloaded the NeHe texture example, which compiles and works fine. Then I downloaded NeHe base code to try and get texturing working using its framework.
Trouble is, (just like in my other applications), the texture never gets displayed.
In this example I simply end up with a white spinning cube.
I was hoping somone might be able to tell me what I''m doing wrong.
The changes I made to the NeHe base code are fairly trivial.
in app.cpp, I insert at the begining of InitGL these lines...
glGenTextures(1, &g_texture);
int l_x, l_y;
for (l_x = 0; l_x != 64; ++l_x) {
for (l_y = 0; l_y != 64; ++l_y) {
int c = (((l_x & 0x8) == 0) ^ ((l_y & 0x8) == 0))*255;
l_image[l_x + l_y*64] = 0xFF | (c << 16) | (c << 8) | c;
}
}
glBindTexture(GL_TEXTURE_2D, g_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_image);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
where l_image and g_texture are defined as...
GLuint g_texture;
int l_image[64*64];
in the global variables section.
I then simply replaced the Draw code with that from lesson 6 (replacing texture[0] with g_texture)
If anyone could help thatad be greate.
I can only assume that there is some sort of OpenGL state which I am using that hasnt been set correctly.
IMHO, thanks in advance for your help!
- Pog
1) change ++I_x and ++I_y to I_x++ and I_y++ : array subscripting starts at count zero - you''re skipping the first pixel in the bitmap.
2) try changing I_image to char[64 * 64 * 4] and filling it in:
to see if you get a red mesh. Everything else seems correct at the first glance (okay, okay, I admit I''m too lazy to go through the color calcutlation thng thingy
)
3) use [ -- source -- ] and [ -- /suorce -- ] tags to post your code (omit the dashes)
Hope this helps,
Crispy
2) try changing I_image to char[64 * 64 * 4] and filling it in:
for(unsigned i = 0; i < 64 * 64; i += 4) { I_image[i] = 255; I_image[i + 1] = 0; I_image[i + 2] = 0; I_image[i + 3] = 255; }
to see if you get a red mesh. Everything else seems correct at the first glance (okay, okay, I admit I''m too lazy to go through the color calcutlation thng thingy

3) use [ -- source -- ] and [ -- /suorce -- ] tags to post your code (omit the dashes)
Hope this helps,
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Thanks for your help, but I''m afraid there isnt actualy anything wrong with the seduo texture I generate (ie, the bitmap on the stack).
The third part of a for loop dosnt get called until the end of an iteration, so in practice ++i is the same as i++ because you never actualy use the local result. Incrementing and then checking the loop are two seperate operations.
Infact ++i is better if your using non-atomic types, since i++ returns a temporary which can be non trivial (especialy if i is a user class).
Aside from that, I''ve tested putting the seudo image in the lesson 6 example code, works fine.
Thanks for your help though!
The third part of a for loop dosnt get called until the end of an iteration, so in practice ++i is the same as i++ because you never actualy use the local result. Incrementing and then checking the loop are two seperate operations.
Infact ++i is better if your using non-atomic types, since i++ returns a temporary which can be non trivial (especialy if i is a user class).
Aside from that, I''ve tested putting the seudo image in the lesson 6 example code, works fine.
Thanks for your help though!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement