PDA

View Full Version : Texture mapping problem



occamrzr
01-14-2001, 09:23 PM
Hello,


This may be a stupid question, or I could just be stupid, I do not know, but I am having a HELL of a time trying to figure out how to just texture map a polygon with just a normal, everyday, texture (no blending, no mipmap, etc).


Here is my code for setting the texture...

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

glTexImage2D(GL_TEXTURE_2D, 0, 3, Bitmap.GetWidth() - 1, Bitmap.GetHeight() - 1, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, Image);

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


And here is my code for generating Image, which is of type GLubyte*...

struct _pixBGRData{
GLubyte B;
GLubyte G;
GLubyte R;
GLubyte Reserved;
};


void glcBitmap::GetPixels(GLubyte Buffer[], int Type, int R, int G, int B){

int BufferIndex = 0;
int PixIndex = 0;

if (Loaded){
if (Type == 0){

for (; PixIndex < (Info.biWidth *
Info.biHeight); PixIndex++){

Buffer[BufferIndex] = BGR[PixIndex].B;
Buffer[BufferIndex + 1] = BGR[PixIndex].G;
Buffer[BufferIndex + 2] = BGR[PixIndex].R;
BufferIndex += 3;
}
}
}
}


Also, I know the data is intact because I make a call to glDrawPixels and it draws properly.
I just do NOT get it!! Is there a difference between the data passed in glDrawPixels and glTexImage2D, or am I forgetting a function call, messing up the order of calls?

I have a demo on this that works (someone else wrote it), and as far as I can tell, the openGL calls we make are the same, but how we load in the bitmap is different.


One last thing, in this very long problem. I know there is a built in bmp loader in the open gl library (though I didn't know to AFTER I created my bmp loaded), but I want to get this working with MY bmp loader. I want to know what I am really doing wrong!!

Can anyone help?
Thank you for your time,
occamrzr

Nutty
01-15-2001, 12:08 AM
Just a quick check, I didn't see any
glEnable(GL_TEXTURE_2D); 's in there anywhere. You must call this to turn on 2 dimensional texture mapping. Maybe you have it enabled somewhere else?

Nutty http://www.opengl.org/discussion_boards/ubb/smile.gif

Michael Steinberg
01-15-2001, 05:10 AM
Look in that other thread running here.
Additionally to what Nutty said, you don't check wether the texture is a power of 2 big in either direction.

Michael Steinberg
01-15-2001, 05:12 AM
And if your compiler alignes the structure components, you might get an error as well. I would sort the image data in a big byte array.

occamrzr
01-15-2001, 06:38 AM
Hello,


Sorry, I do enable GL_TEXTURE_2D in my setup function.
The image I'm using is 128x128, which I believe is within the acceptable limits for oGL.
I am also storing the image data into a Byte Array.


Thank you,
occamrzr

daveg
01-15-2001, 08:13 AM
Hmm, the glTexImage2D call looks right on a quick glance. Silly question but are you sure your texture coordinates are correct for your polygon? Maybe you could post a snippet where you setup the polygon? You might want to try setting the wrap modes to repeat just to see if you are getting anything and maybe set the texenv mode to replace just to be sure:

glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

dave

occamrzr
01-15-2001, 09:25 AM
Hello,


I tried what was mentioned and it did not work.

This is the code that I use to draw my polygon...

glBegin(GL_QUADS);

CalcNormal(Faces[x].A, Faces[x].B, Faces[x].C, Norm);
glNormal3f(Norm.x, Norm.y, Norm.z);
glTexCoord2f(0.0, 0.0);
glVertex3f(Faces[x].A.x, Faces[x].A.y, Faces[x].A.z);
glTexCoord2f(1.0, 0.0);
glVertex3f(Faces[x].B.x, Faces[x].B.y, Faces[x].B.z);
glTexCoord2f(1.0, 1.0);
glVertex3f(Faces[x].C.x, Faces[x].C.y, Faces[x].C.z);
glTexCoord2f(0.0, 1.0);
glVertex3f(Faces[x].D.x, Faces[x].D.y, Faces[x].D.z);

glEnd();

RobertSI
01-15-2001, 09:41 AM
Where is the path to the texture?

occamrzr
01-15-2001, 10:19 AM
I'm not sure I understand that question. If you mean the physical path of the .bmp file, it's in my main working program directory. The BMP loads fine, because it will display with one of the openGL functions. I just cannot get textures to work, for some reason.

If you mean, where is the Image object within the program, it's a global object of type GLubyte *Image;

It is inited later with...
Image = new GLubyte[NumberOfPixels*3];

Thank you,
Occamrzr

Suvcon
01-15-2001, 12:12 PM
mail your project to me if you can,maybe i can solve it.

my mailbox: suvcon_cn@sina.com

occamrzr
01-15-2001, 12:48 PM
Hello everyone!


Thank you all very much for your help. I was able to solve the problem. I'm not exactly sure how, but it does work perfectly now.

Thank you all,
occamrzr