PDA

View Full Version : Broken OGL texturing (sigh)



Cyberman
December 23rd, 2003, 06:47
I'm fine in OGL as long as I don't try to UV map a texture or use a texture for that matter.

First I realized I had made the texture a non integral value of 64 128 256 etc.
No biggie!
Then I generate the map from the data I have setting anything black level to transparent <not a problem>
Code used to create a texture

X = BM->Width;
if (X < BM->Height) X = BM->Height;
if (X < 64)
{ X = 64;
}
else
{ if (X < 128)
{ X = 128;
}
else
{ X = 256;
}
}
BM->Width = X;
BM->Height = X;
Textures[0].Width = X;
Textures[0].Height = X;
Textures[0].bpp = 32;
Bytes = X*X*4;
Textures[0].ImageData = new GLubyte[Bytes];
if (Textures[0].ImageData != NULL)
{
memset(Textures[0].ImageData, 0, Bytes);
// select palette and convert
BCB2OGL(Textures[0].ImageData, BM);
glGenTextures(1, &Textures[0].texID);
glBindTexture(
GL_TEXTURE_2D,
Textures[0].texID
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(
GL_TEXTURE_2D,
3,
Textures[0].Width,
Textures[0].Height,
GL_RGBA,
GL_UNSIGNED_BYTE,
Textures[0].ImageData
);
}

Code I use to apply a texture

glBindTexture(
GL_TEXTURE_2D,
Textures[0].texID
);
glBegin(GL_TRIANGLES);
glTexCoord2f(
TTriangles[Index].U0/TexW,
TTriangles[Index].V0/TexH
);
FF7_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.A>>3]);
glTexCoord2f(
TTriangles[Index].U1/TexW,
TTriangles[Index].V1/TexH
);
FF7_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.B>>3]);
glTexCoord2f(
TTriangles[Index].U2/TexW,
TTriangles[Index].V2/TexH
);
FF7_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.C>>3]);
glEnd();


Lots of code is missing but it's mostly creating the bitmap that becomes the texture.

The result is less than satisfying.. essentially the textured surface glows closest to the last colored vertex information sent. Anyone got a clue? Textures aren't my forte' <who would have guessed>.


Cyb

blight
December 23rd, 2003, 12:25
hmm... you know the origin of the texture coordinate system is the lower left corner of the texture? you could also try manipulating the texture view stack (or whatever it's called) to get the same results - that's fun ;)

Cyberman
January 14th, 2004, 21:31
hmm... you know the origin of the texture coordinate system is the lower left corner of the texture? you could also try manipulating the texture view stack (or whatever it's called) to get the same results - that's fun ;)
First I had to generate the textures corrrectly.
At the moment I generate a 64x64 128x128 256x256 size texture. Not a problem I have that working just fine, still looks like crap however, I wonder if I should be blending the two layers. Basically I have two sets of polygons. One the basic model and the second set has textures on it. The models have color vertices (I didn't make them), and I'm pasting this polys over them, They should be transparent accept for where there are details from the texture. I call it a decal texture myself. :)

It still doesn't work however and this is what I get, the polygons are obviously using the last vertex color I used on the prior set of polygons. Unfortunately it's supposed to be using a texture for it's looks not that (heh) so I'm a bit baffled as to what I'm doing wrong here.
http://members.socket.net/~cyberman/TIFA_02.jpg

Here is the code I'm using... even if my maping direction etc. is just wrong I should SEE SOMETHING, all I am seeing is flat colored triangles and quadrics.


if (TTriC)
{
if ( Count == PART_LB->ItemIndex)
{
//glBindTexture(GL_TEXTURE_2D, textures
for(Index = 0; Index < TTriC; Index++)
{ //auxDIBImageLoad
glBindTexture(
GL_TEXTURE_2D,
Textures[0].texID
);
glBegin(GL_TRIANGLES);
glTexCoord2f(
TTriangles[Index].U0/TexW,
TTriangles[Index].V0/TexH
);
FF7_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.A>>3]);
glTexCoord2f(
TTriangles[Index].U1/TexW,
TTriangles[Index].V1/TexH
);
FF7_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.B>>3]);
glTexCoord2f(
TTriangles[Index].U2/TexW,
TTriangles[Index].V2/TexH
);
FF7_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.C>>3]);
glEnd();
if ((Error = glGetError()) != NO_ERROR)
{
Line.printf(
"GL Error %03d",
Error
);
}
}
}
}
if (TQuadC)
{
if ( Count == PART_LB->ItemIndex)
{
for(Index = 0; Index < TQuadC; Index++)
{
glBindTexture(
GL_TEXTURE_2D,
Textures[0].texID
);
glBegin(GL_QUADS);
glTexCoord2f(
TQuads[Index].U0/TexW,
TQuads[Index].V0/TexH
);
FF7_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.A>>3]);
glTexCoord2f(
TQuads[Index].U1/TexW,
TQuads[Index].V1/TexH
);
FF7_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.B>>3]);
glTexCoord2f(
TQuads[Index].U2/TexW,
TQuads[Index].V2/TexH
);
FF7_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.D>>3]);
glTexCoord2f(
TQuads[Index].U3/TexW,
TQuads[Index].V3/TexH
);
FF7_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.C>>3]);
glEnd();
}
}
}


Obviously the vertices work right.. however the rest of the texturing has be befuddled.

Orkin
January 14th, 2004, 23:53
I didn't notice you enabling texturing anywhere in there. Plus, you need to make sure your texture environment is set up correctly.

Try adding these lines somewhere in there:


glEnable( GL_TEXTURE_2D );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );


That's assuming you want to use decal mode (which it sounded like you did by your earlier description). If not, change the last parameter to GL_REPLACE, or GL_MODULATE.

Cyberman
January 15th, 2004, 07:38
I didn't notice you enabling texturing anywhere in there. Plus, you need to make sure your texture environment is set up correctly.

Try adding these lines somewhere in there:


glEnable( GL_TEXTURE_2D );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );


That's assuming you want to use decal mode (which it sounded like you did by your earlier description). If not, change the last parameter to GL_REPLACE, or GL_MODULATE.

Well maybe DECAL is wrong then.. hmm it doesn't really show anything to be onest at all sadly I wonder if GL_REPLACE will let me at least SEE the texture.


void __fastcall TMain::OGL_MODELInit(TObject *Sender)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glViewport(0,0,(GLsizei)OGL_MODEL->Width,(GLsizei)OGL_MODEL->Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( OGL_MODEL->Height==0)
gluPerspective(
45,
(GLdouble)OGL_MODEL->Width,
1.0,
2000.0);
else
gluPerspective(
45,
(GLdouble)OGL_MODEL->Width/
(GLdouble)OGL_MODEL->Height,
1.0,
2000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
}
//---------------------------------------------------------------------------

void __fastcall TMain::OGL_MODELPaint(TObject *Sender)

{
if (MDL_View)
{
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0, 0.0, ZAxis);
glRotatef(RotX, 1.0, 0.0, 0.0);
glRotatef(RotY, 0.0, 1.0, 0.0);
glRotatef(RotZ, 0.0, 0.0, 1.0);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
if (HEX_OGL_CB->Checked)
{
BMDL_OGL();
}
glPopMatrix();
glFlush();
}
}
//---------------------------------------------------------------------------


Well I kind of didn't put it up because I was trying to prevent posting five six hundred lines of code :)

I do it before I refresh the 'model' drawing function BMDL_OGL() :)

Setting the glvertexf(1.0, 1.0, 1.0);
as was suggested by someone just leaves lovely white triangles :)

Changing it to REPLACE or MODULATE doesn't seem to change anything.

I must be missing something it's obviously drawing the polygons just without the texture. Maybe I should check if I'm making the texture right?