PDA

View Full Version : Questions abt Nehe's tutorial 6(texture loading)



nicky
01-17-2002, 04:28 AM
Hi, I'm using the code from Nehe's example 6 to load a texture. At the same time I would like to render a model. my code is as follows:

glPushMatrix();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glPolygonMode(GL_BACK, GL_LINE);
glDepthFunc(GL_LEQUAL);
glCullFace(GL_FRONT);
glDepthMask(GL_FALSE);
glColor3f(1.0f, 1.0f, 1.0f);
glLineWidth(5.0);

for (i=0; i<model.numberofface; i++)
{
if (rendermode == 1)
glLoadName(i);
glBegin(GL_TRIANGLES);
.
.
.
glEnd();

}
glPopMatrix();
ImageSetup(); //code from Nehe
DrawGLScene(); //code from Nehe

The problem is, the bmp would not get displayed at all. However, when I disable the RGBA bits in glColor, the bmp will display. Is there any way I can display both the bmp and model? I need to enable the color bits cos I disabled them earlier in the program. Actually, I need to display the bmp as it is and not as a texture, but am first trying with the Nehe code first. Will it be better if I load the bmp only and not as a texture?

Also, I'd like to know why in the code by nehe, there is a need for a translation into the screen by 5.0? The size of the cube is 2*2*2 right?

nicky

nexusone
01-17-2002, 05:32 AM
If you just want to display the BMP image, you still need to create a surface to place it on.

glBindTexture(GL_TEXTURE_2D, BMPimage);

glBegin(GL_QUADS);
// Draw a square to place the image on.
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

Hope this helps.

nicky
01-18-2002, 01:27 AM
I thought to draw a bitmap, i should use glDrawPixels(), does that require a surface to bind to?

andrei
01-18-2002, 01:38 AM
Any object composed of triangles can be texture mapped.

remember to enable texture mapping
glEnable(GL_TEXTURE_2D);

activate your texture
glBindTexture(GL_TEXTURE_2D, texture);

and remember to set texture coordinates
glBegin(GL_TRIANGLE);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
...
glEnd();

Andrei

nexusone
01-18-2002, 05:30 AM
I am still sort of a newbe at GL but from your example it look like you wanted to put a image on a object as per the nehe example.

Do you want the image behind the object or maybe to image to be simi transparent so that you can see the object behind it?

I think that glDrawPixels may not be the function you need to use.

Can you give a little more feed back as to what you want to do with the image and object?


Originally posted by nicky:
I thought to draw a bitmap, i should use glDrawPixels(), does that require a surface to bind to?

nicky
01-18-2002, 04:17 PM
Hi guys,
thanks for all your replies.

nexusone, yeah, in fact i would like cover part of the object and still be able to see the covered portion through the image. I have an image which consists of two dominant colors, yellow and red, and I would like the object to appear behind the yellow portion, and still see it. So, yellow portion transparent, red portion opaque. Can it be done using glDrawPixels?

chowe6685
01-18-2002, 05:38 PM
yes, but don't use drawpixels. DrawPixels is very slow. Instead map the texture to a quad, or two quads if you want one section to be opaque.

nexusone
01-19-2002, 11:42 AM
Then you need to map the image to an quad object per my last message.

This will let you pull off some neat effects that you find in some demos.

Buy putting the image on a object you can scale it, rotate it, adjust the transparent.

image1 object image2

back <> front
Transpartent

Hopes this helps.



Originally posted by nicky:
Hi guys,
thanks for all your replies.

nexusone, yeah, in fact i would like cover part of the object and still be able to see the covered portion through the image. I have an image which consists of two dominant colors, yellow and red, and I would like the object to appear behind the yellow portion, and still see it. So, yellow portion transparent, red portion opaque. Can it be done using glDrawPixels?

nicky
01-20-2002, 07:30 PM
Hi guys,

thanks for all your help, i am able to display both the 3d model and the bitmap now. nexusone, i see your point, it is indeed easier for me to play around with the image by putting the image on the object. thanks a lot.

I have a new problem though. The model now takes the color of the bitmap whenever it gets displayed. It is supposed to be a white model, but it now appears blue due to the blue bitmap. How can I restore the original color of the 3d model?

nexusone
01-25-2002, 07:12 AM
Sorry but have been traveling and have not been on-line for a week.

Just like when you look through a red lens, everything you see will have a red tint.
You will always have some amount of tint on the object behind the front bit map.

Maybe you need to use a bitmap with a Alpha channel, use the Alpha channel as a mask to create completely transparent areas.

Then your object would move in and out of the filtered areas. This maybe the effect you are looking for?

The other option is to just put your object in front of all the bit maps to keep it white.

The more advanced option would be to render your object and back ground image first. The use the stencil buffer to map a transparent hole the shape of your object in the front bitmap image. This way the object will have its, correct color.



Originally posted by nicky:
Hi guys,

thanks for all your help, i am able to display both the 3d model and the bitmap now. nexusone, i see your point, it is indeed easier for me to play around with the image by putting the image on the object. thanks a lot.

I have a new problem though. The model now takes the color of the bitmap whenever it gets displayed. It is supposed to be a white model, but it now appears blue due to the blue bitmap. How can I restore the original color of the 3d model?