Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ithius

Colored Vertices and Textures don't get along?

This topic is 5325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Having peered long hours at the examples I must not be getting texturing right. I'll explain simply what I'm doing. First the data is not mine, don't obsess over it's format. Second I'm using Borland C++ Builder 5.0 Thirdly I can display OGL information just fine as long as it doesn't have textures ( keep left signs included I suppose.) I have 4 sets of data I am reading to display an object using OGL. Textured Triangles Textured Quads Colored Vertex Triangles Colored Vertex Quads The colored vertex information displays quite nicely (really it does ). What I'm having difficulty with is getting the texture data displayed on the Textured Triangles and Quads. The models I'm reading contained textures (paletted ones I might add much to my aboyance) and UV data for the textures. What I am ending up with is the 'textured' polygons vertices having the last color used for the colored vertex quads and triangles, as there color. Honestly it looks rather silly (if not ugly). here is an example http://memberes.socket.net/~cyberman/E019_03.jpg of what I'm getting as you can see in that image the textured information is all the same color which is the last vertex colored used (from the colored vertice triangles/quads). 'Offending' drawing Code: Note I draw the colored vertex information first then draw the textured information.
         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
                        );
                     FF_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.A>>3]);
                     glTexCoord2f(
                        TTriangles[Index].U1/TexW,
                        TTriangles[Index].V1/TexH
                        );
                     FF_Vert_2_OGL(&Verts[TTriangles[Index].Vertexs.B>>3]);
                     glTexCoord2f(
                        TTriangles[Index].U2/TexW,
                        TTriangles[Index].V2/TexH
                        );
                     FF_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
                        );
                     FF_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.A>>3]);
                     glTexCoord2f(
                        TQuads[Index].U1/TexW,
                        TQuads[Index].V1/TexH
                        );
                     FF_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.B>>3]);
                     glTexCoord2f(
                        TQuads[Index].U2/TexW,
                        TQuads[Index].V2/TexH
                        );
                     FF_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.D>>3]);
                     glTexCoord2f(
                        TQuads[Index].U3/TexW,
                        TQuads[Index].V3/TexH
                        );
                     FF_Vert_2_OGL(&Verts[TQuads[Index].Vertexs.C>>3]);
                  glEnd();
               }
            }
         }
 
Texture creation code (woo).
void TMain::FF_TEX_2_OGL(
   void *tim,
   int PX, int PY,
   int PW, int PH,
   int P
   )
{
   int         ClutC, Index, X, Y, Bytes;
   base_tim_img *ImageDat;
   UINT16     *Image;
   bool        HasTexture;
   GLubyte    *Line;
   TColor      Color;
   Graphics::TBitmap *BM;

   BM = Image1->Picture->Bitmap;
   HasTexture = false;
/// code here checked if there was a valid texture etc.
   Index = 0;
   if (P < 0)
   {
      // clear existing textures out first
      for(Index = 0; Index < TextureCount; Index++)
      {  if (Textures[Index].ImageData != NULL)
         {  delete Textures[Index].ImageData;
            Textures[Index].ImageData = NULL;
         }
      }
      if (HasTexture)
      {
         // resize bitmap to nearest integral of 64 128 256 or 12
         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;
         Image1->Width = X;
         Image1->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);
         }
      }
   }
   else
   {
      glBindTexture(
         GL_TEXTURE_2D,
         Textures[0].texID
         );
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, L_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
         );
   }
}
 
This is called twice one before the texture is generated ( P == -1) and when it is completed (P == 0) [edited by - Ithius on January 15, 2004 3:25:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by DerAnged
before you call the textured object you have to set the color to white glColor3f( 1, 1, 1);






Well that just sort of makes it white


I''ve updated the texture generating part etc. Somehow I think the texture isn''t being MADE or isn''t being applied.

Now comes the more interesting question from me, what should I get when I use glGenTextures() in the second parameter?

I''m just curious where I am going wrong.

Initialization
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);
}



Render ''frame''

//---------------------------------------------------------------------------
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();
}
}


You have already seen what I''m applying the texture too

Construction of Texture

//---------------------------------------------------------------------------
bool TMain::TIM4BPP(
Graphics::TBitmap *BM,
GLubyte *Img,
UINT8 *Data,
UINT16 X1, UINT16 Y1,
UINT16 X2, UINT16 Y2
)
{
tim_4bpp *TIM;
int y, x, Cnt, Idx;
UINT8 *PIX;
int PIX1, PIX2, PIX3, PIX4;
CLUT_4bpp *PAL;
Pallete *PAL2;
base_tim_img *IMG;
GLubyte *Line;
Graphics::TBitmap *BM2;
TColor Color;

TIM = (tim_4bpp *)Data;
if((TIM->INFO.Magic != 16) ||
(TIM->INFO.Type != 8))
{ return false;
}
Cnt = TIM->CLUT_CNT;
BM2 = SP_PAL->Picture->Bitmap;
PalCount = TIM->CLUT_CNT;
BM2->Width = 16;
BM2->Height = PalCount;
SP_PAL->Height = 16 *PalCount;
for (Idx = 0; Idx < ToolBar1->ButtonCount; Idx++)
{ ToolBar1->Buttons[Idx]->Enabled = false;
}
Idx = 0;
PAL = (CLUT_4bpp *)&TIM[1];
while (Cnt > 0)
{ Cnt--;
PAL2 = Pallets[Idx];
PAL2->Size = 16;
for (x = 0; x < 16; x++)
{ PAL2->Pal[x] = BGRTO24BGR(PAL[Idx][x]);
BM2->Canvas->Pixels[x][Idx] = PAL2->Pal[x];
}
if (Idx < 16)
{ ToolBar1->Buttons[Idx]->Enabled = true;
}
Idx++;
}
PAL2 = Pallets[CPal];
IMG = (base_tim_img *)&PAL[TIM->CLUT_CNT];
BM->Width = IMG->Pitch * 4;
BM->Height = IMG->Height;
for (y = Y1; y < Y2; y++)
{
PIX = (UINT8 *)&IMG[1] + ((IMG->Pitch*y) << 1);
Line = Img + (y * BM->Width + X1) * 4;
for (x = X1>>2; x < X2>>2; x++)
{
Cnt = x << 1;
PIX1 = PIX[Cnt];
PIX2 = (PIX1 >>4) & 0xF;
PIX1 &= 0xF;
PIX3 = PIX[Cnt + 1];
PIX4 = (PIX3 & 0xF0) >> 4;
PIX3 &= 0xF;
Cnt <<=1;
Color = PAL2->Pal[PIX1];
BM->Canvas->Pixels[Cnt + 0][y] = Color;
TColor2OGL(Line, Color, (PIX1 > 0));
Color = PAL2->Pal[PIX2];
BM->Canvas->Pixels[Cnt + 1][y] = Color;
TColor2OGL(Line, Color, (PIX2 > 0));
Color = PAL2->Pal[PIX3];
BM->Canvas->Pixels[Cnt + 2][y] = Color;
TColor2OGL(Line, Color, (PIX3 > 0));
Color = PAL2->Pal[PIX4];
BM->Canvas->Pixels[Cnt + 3][y] = Color;
TColor2OGL(Line, Color, (PIX4 > 0));
}
}
//delete PIX;
return true;
}
//---------------------------------------------------------------------------
void TMain::TColor2OGL(GLubyte *Dest, TColor Color, bool Opaque)
{
Dest[0] = GetRValue(Color);
Dest[1] = GetGValue(Color);
Dest[2] = GetBValue(Color);
Dest[3] = (Opaque)?0xFF:0x00;
}
//---------------------------------------------------------------------------


It''s complicated because the original data is paletted and I had to convert from that to an RGBA texture .

Is it because I have colored vertex triangles and then try to paste a DECAL texture in the next set of polygons?

Confused and a bit frustrated here

Ith

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!