What's new

More Broken GL Texturing :)

Cyberman

Moderator
Moderator
Here is some 'clearer' source for something different, I still have the same problem NO texturing so I'm baffled. I've had texturing working on some other code a year or two back but lately this is my 'white polygon' in a snow storm days (so I changed the background to grey to see them ;) ).

I'm fairly sure I'm generating the texture correctly NO alpha channel is used on this texture also.

Any ideas? I know I'm doing something wrong (heh) just not sure which thing I'm doing is erroneous. It's that thing thing (makes sense to me).

Polygon Rendering code:
Code:
void TMain::FF8_BMDL_OGL(void)
{
   PSX_FF8_MDL_HDR  *DIR;
   PSX_FF8_MDL_HDR2 *MODEL;
   PSX_FF8_FACE     *Faces;
   PSX_FF7_VERTEX   *Verts;
   PSX_FF8_SKJ      *Skel;
   int               Index;

   DIR = (PSX_FF8_MDL_HDR *)DEC_BAT;
   glBindTexture(
      GL_TEXTURE_2D,
      Textures[0].texID
      );
   MODEL =(PSX_FF8_MDL_HDR2 *) (DEC_BAT +
      DIR->REFS[TextureCount + 1]);
   Skel = (PSX_FF8_SKJ *)&MODEL[1];
   Verts = (PSX_FF7_VERTEX *)&Skel[MODEL->SKJ];
   Faces = (PSX_FF8_FACE *)&Verts[MODEL->Vert];
   for(Index = 0; Index < MODEL->Face; Index++)
   {
      FF8_FACE_OGL(Faces[Index], Verts);
   }
}
//---------------------------------------------------------------------------

FF8_FACE_OGL() function
Code:
void TMain::FF8_FACE_OGL(PSX_FF8_FACE & Face, PSX_FF7_VERTEX * Verts)
{
   if(Face.Type & 0x08000000)
   {  // Quad
      glBegin(GL_QUADS);
         glTexCoord2f(
            Face.UV[0].U/128.0,
            Face.UV[0].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[0]]);
         glTexCoord2f(
            Face.UV[1].U/128.0,
            Face.UV[1].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[1]]);
         glTexCoord2f(
            Face.UV[3].U/128.0,
            Face.UV[3].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[3]]);
         glTexCoord2f(
            Face.UV[2].U/128.0,
            Face.UV[2].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[2]]);
      glEnd();
   }
   else
   {  // Triangle
      glBegin(GL_TRIANGLES);
         glTexCoord2f(
            Face.UV[0].U/128.0,
            Face.UV[0].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[0]]);
         glTexCoord2f(
            Face.UV[1].U/128.0,
            Face.UV[1].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[1]]);
         glTexCoord2f(
            Face.UV[2].U/128.0,
            Face.UV[2].V/128.0
            );
         FF7_Vert_2_OGL(&Verts[Face.Edge[2]]);
      glEnd();
   }
}

Texture Generation code
Code:
typedef struct
{
   tim_8bpp       INFO;
   CLUT_8bpp      CLUT;
   base_tim_img   IMAGEDAT;
}
FF8_TIM_TEX;
void TMain::FF8_BMDL_OGL_TEX(void)
{
   Graphics::TBitmap *BM;
   PSX_FF8_MDL_HDR   *DIR;
   FF8_TIM_TEX       *TEX[4];
   int               TexCount, Index, Start;
   int               X, Y;
   TColor            Color;
   UINT8             *Pix, *Store;

   DIR = (PSX_FF8_MDL_HDR *)DEC_BAT;
   TexCount = 0;
   while(DIR->REFS[TexCount] != 0xFFFFFFFF)
   {
      TEX[TexCount] =(FF8_TIM_TEX *)(DEC_BAT +DIR->REFS[TexCount]);
      TexCount++;
   }
   // FF8 bitmaps are opaque no alpha needed
   // so they are R8G8B8 raw bit maps when decoded
   *TEX[0];
   BM = Image1->Picture->Bitmap;
   BM->Width = TEX[0]->IMAGEDAT.Pitch * 2;
   BM->Height= 0;
   TextureCount = TexCount;
   for (Index = 0; Index < TexCount; Index++)
   {
      Start = BM->Height;
      BM->Height += TEX[Index]->IMAGEDAT.Height;
      Pix = (UINT8 *)(TEX[Index] + 1);
      if (Textures[Index].ImageData != NULL)
         delete Textures[Index].ImageData;
      Store = new UINT8[BM->Width * BM->Height * 3];
      Textures[Index].ImageData = Store;
      Textures[Index].Width =    BM->Width;
      Textures[Index].Height =   BM->Height;
      for (Y = Start; Y < BM->Height; Y++)
      {
         for (X= 0; X < BM->Width; X++)
         {
            Color = BGRTO24BGR(TEX[Index]->CLUT[*Pix++]);
            BM->Canvas->Pixels[X][Y] = Color;
            *Store++ = GetRValue(Color);
            *Store++ = GetGValue(Color);
            *Store++ = GetBValue(Color);
         }
      }
      glGenTextures(1, &Textures[Index].texID);
      glBindTexture(
         GL_TEXTURE_2D,
         Textures[Index].texID
         );
      gluBuild2DMipmaps(
         GL_TEXTURE_2D,
         3,
         Textures[Index].Width,
         Textures[Index].Height,
         GL_RGB,
         GL_UNSIGNED_BYTE,
         Textures[Index].ImageData
         );
      glTexParameteri(
         GL_TEXTURE_2D,
         GL_TEXTURE_MAG_FILTER,
         GL_LINEAR_MIPMAP_NEAREST
         );
      glTexParameteri(
         GL_TEXTURE_2D,
         GL_TEXTURE_MIN_FILTER,
         GL_LINEAR_MIPMAP_NEAREST
         );
   }
}

OGL Render frame code
Code:
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)
      {
         switch(DEC_BAT_TYPE)
         {
            case FF7_BAT_DAT:
               FF7_BMDL_OGL();
               break;
            case FF8_BAT_DAT:
               FF8_BMDL_OGL();
               break;
            case FF9_BAT_DAT:
               FF9_BMDL_OGL();
               break;
         }
      }
      glPopMatrix();
      glFlush();
   }
}

OGL initialization
Code:
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_REPLACE);// 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);
}
First image is the Texture I'm pasting
Then a rotated image of what it looks like textured with my lovely code.
Screen Shots Thread for this post
 
Last edited:

blight

New member
Did you try drawing the texture onto a plain square or something simple?
It might also help when you enable culling (to remove unneeded polygons)
The default mode for OpenGL is to linearly interpolate textures pixels to map them onto the polygon so if the texture is loaded correctly you should get anything but white (unless you specify a white area of the texture of course ;))

HTH
 
OP
Cyberman

Cyberman

Moderator
Moderator
blight said:
Did you try drawing the texture onto a plain square or something simple?
It might also help when you enable culling (to remove unneeded polygons)
The default mode for OpenGL is to linearly interpolate textures pixels to map them onto the polygon so if the texture is loaded correctly you should get anything but white (unless you specify a white area of the texture of course ;))

HTH
Ok after a few attempts at debugging what's going on:
  1. It's not allocating a texture name in OGL the texture reference does not change
  2. None of your suggestions will do any good unless I can get the above to work ;)
I attempted to use glGetError() however it doesn't seem to work the way I expected (sadly). The current error state of it is GL_INVALID_OPERATION unfortunately I can't CLEAR the damned error. Acording to the GL spec one should exhaust the errors quickly.. or at least I would think in a nice tight loop of waiting tell there were no returned errors. This doesn't work. So I'm a bit anoyed with that :)

Code:
while ((Error = glGetError()) != GL_NO_ERROR)
{
}
doesn't work in otherwords because either it has 50000 errors OR something else is messed up. Should I attempt to hook into nvidia's drivers to be sure it isn't a microsoft Fark up?

Cyb
 

blight

New member
Maybe there is MesaGL (software GL rendering lib) for windows ;)
sorry for asking but are you sure that the texture ref does not get changed? the first one will be 0 i think and not some random number...
unless your drivers are fucked up this should apply for glGetError():
GL_INVALID_OPERATION is generated if glGetError is executed between the execution of glBegin and the corresponding execution of glEnd. In this case glGetError returns 0.

glGetError cannot create an infinite loop by setting an error flag which it returns
very strange... i have no more ideas atm, sorry :plain:
 

bjz

New member
Not really a solution but this will do the same thing.

while(glGetError() != GL_NO_ERROR)
{
}
 

ZeZu

New member
OGL texturing

First of all,

if glGetError() is returning tons of errors you should really fix it

you should have NO errors in opengl .. try something like :

GLvoid CheckErrorsGL( void )
{
GLenum err;
const GLubyte *pszErrStr;

if((err = glGetError()) != GL_NO_ERROR)
{
pszErrStr = gluErrorString(err);
printf( "OpenGL Error %s\n", pszErrStr );
}
}

and call this at least once per frame

if you have an error it is serious and will 99% of the time stop something from working

another thing is .. make sure your texture sizes are powers of 2 ie: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 .. etc or else you will either have to resize them or use an extension to load them...

now after you call glTexImage2D you should check your texture id before you assume your texture is loaded and the id is valid..

use glIsTexture(texid) and it will return true/false whether its a valid texture...

once you do not have any errors, and your texture id is valid, your texture should show up ; )

you might also try adding a routine to dump textures to a bitmap of some kind ( tga is good/easy ) as this will help in debugging various texture formats later

hope this helps, if you find a more specific problem let me know as the code looks ok as far as i can tell

_ZeZu_
 
OP
Cyberman

Cyberman

Moderator
Moderator
Well first thing I noticed was that the OGL initialization routine wasn't being called before I was creating the texture. So I solved that by doing some screen fliping, it gets called when the window with the OGL view is displayed (not a big deal).

I am still getting an error (1282) that states that glgentexture() is not valad to call when I'm creating the texture, it's a trite confusing to me to say the least (heh). Acording to OGL 1.3 spec glgentexture() does not change the variable if there is an error which is exactly what is happening. It throws an error the first OGL function I call after generating the texture actually. It's rather strange.

Calling glGetError() also DOES NOT clear any of the errors. In otherwords I get an infinate number of errors (endless power! ).

I can't really see what I've done wrong either.

However there is a nice symptom of my computer locking up and having to reboot when I run the code ;)

Cyb
 
OP
Cyberman

Cyberman

Moderator
Moderator
linker said:
good old 98 :p

Windows 98 and for that matter Me's primary instability is the way MS handled memory management. In fact, I am surprised they weren't sued for it, essentially win98 has no memory management. It never deallocates anything unless it's needed. This creates lots of failures because (ahem), what happens is a program thinks it's out of resources/memory and throws an exception. I have 512M of memory and my computer will go ape throwing exceptions because of that one moron thing with win98.

I suppose MS thought it was an optimization :) (do nothing when something is dallocated!).

HOWEVER your comment has nothing to do with my conundrum with openGL if you have ideas on what it is please come forth with them! ;)

Cyb
 

ZeZu

New member
-> Broken OpenGL Texturing :

Cyberman:

Your issues with your OpenGL call not being valid are likely due to OpenGL not being initialized or not initialized correctly. Understand that all calls to OpenGL API have to be on the same thread or it will fail. OpenGL is not thread friendly and I think this is the problem your having. Also make sure your textures are a power of 2 in size.

If your still getting errors,

you can find me on iRC ( efnet ) in #emudev

i will help you out if I can


_ZeZu_
 
OP
Cyberman

Cyberman

Moderator
Moderator
ZeZu said:
Cyberman:

Your issues with your OpenGL call not being valid are likely due to OpenGL not being initialized or not initialized correctly. Understand that all calls to OpenGL API have to be on the same thread or it will fail. OpenGL is not thread friendly and I think this is the problem your having. Also make sure your textures are a power of 2 in size.

If your still getting errors,

you can find me on iRC ( efnet ) in #emudev

i will help you out if I can


_ZeZu_
Oh cool, GL code sent my system to oblivion again too. fortunately CTRL-ALT-DEL and killing it with the task manager worked. It's hard to debug something that's.. expiring all the time (sigh).
FF7 Models aren't a problem unless they have a texture in them it seems, not sure what's going on <head scratch>. Does the base implementation of OGL on windows not support textures or something?

I guess I had better modify the OGL component to prob more and be sure the factory supplied drivers from NVidia are being used and not microsofts library (sigh).
All things considered I'm using floating point and doing real time calculation it operates too smoothly to be software rendered I think (hmmm),

Cyb
 

Top