Results 1 to 3 of 3

Thread: Problems with texture

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    7

    Problems with texture

    I want to put a texture in a polygon. But i don't know which before running my application. So I create a dynamic matrix, BUT (threre is a BUT) something is wrong, but I don't what!! The matrix is well initialise.
    Please help me...

    void __fastcall TForm1::OpenGLPanel1Init(TObject *Sender)
    {
    glViewport(0,0,(GLsizei)OpenGLPanel1->Width,(GLsizei)OpenGLPanel1->Height);
    glMatrixMode(GL_PROJECTION);

    glOrtho(-100.0,100.0,-100.0,100.0,-2000.0,2000.0);

    glLoadIdentity();
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0,0.0,0.0,0.0);

    OpenGLPanel1TextureInit("earth.bmp");
    }
    //-------------------------------------------void __fastcall TForm1::OpenGLPanel1TextureInit(char *Name)
    {
    Graphics::TBitmap *bitmap;

    bitmap = new Graphics::TBitmap;
    bitmap->LoadFromFile(Name);

    static GLubyte ***bits;

    bits = (GLubyte***)malloc(bitmap->Height*sizeof(GLubyte**));
    for(int i=0;i<bitmap->Height;i++)
    {
    bits[i] = (GLubyte**)malloc(bitmap->Width*sizeof(GLubyte*));
    for (int j=0;j<bitmap->Width;j++)
    bits[i][j] = (GLubyte*)malloc(4*sizeof(GLubyte));
    }


    for (int i=0; i<bitmap->Height; i++)
    for (int j=0; j<bitmap->Width; j++)
    {
    bits[i][j][0] = (GLubyte) GetRValue(bitmap->Canvas->Pixels[i][j]);
    bits[i][j][1] = (GLubyte) GetGValue(bitmap->Canvas->Pixels[i][j]);
    bits[i][j][2] = (GLubyte) GetBValue(bitmap->Canvas->Pixels[i][j]);
    bits[i][j][3] = (GLubyte) 255;
    }

    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    glGenTextures(1,&texName);
    glBindTexture(GL_TEXTURE_2D,texName);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,
    bitmap->Width,bitmap->Height,0,
    GL_RGBA,GL_UNSIGNED_BYTE,bits);


    delete bitmap;
    }
    //-------------------------------------------void __fastcall TForm1::OpenGLPanel1Texture()
    {
    // Draw the Background Image

    glEnable(GL_TEXTURE_2D);
    glLoadIdentity();
    glPushMatrix();
    glTranslatef(0.0,0.0,-500);

    glBindTexture(GL_TEXTURE_2D,texName);

    glBegin(GL_POLYGON);
    glTexCoord2f(0.0, 1.0); glVertex3f(-100.0, 100.0,-500.0);
    glTexCoord2f(1.0, 1.0); glVertex3f( 100.0, 100.0,-500.0);
    glTexCoord2f(1.0, 0.0); glVertex3f( 100.0,-100.0,-500.0);
    glTexCoord2f(0.0, 0.0); glVertex3f(-100.0,-100.0,-500.0);
    glEnd();

    glPopMatrix();
    glFlush();

    glDisable(GL_TEXTURE_2D);


    }

  2. #2
    Member Newbie
    Join Date
    Mar 2000
    Location
    New Jersey
    Posts
    30

    Re: Problems with texture

    I don't see you initializing texName anywhere. Is this a global ? If I were you I'd throw in some error handling for both the c and the openGL. Check glGetError and gluGetErrorDesc ( I think ). These function names are from memory but should give you something to look up. Hope this helps,
    fs
    Francis Shanahan
    Architect

  3. #3
    Member Contributor
    Join Date
    Feb 2000
    Location
    Breda, Netherlands
    Posts
    57

    Re: Problems with texture

    Originally posted by Le Bayonnais:

    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,
    bitmap->Width,bitmap->Height,0,
    GL_RGBA,GL_UNSIGNED_BYTE,bits);
    shouldn't the first GL_RGBA just be the number 4, telling OpenGL the about of elements in the picture?
    GL_RGBA is defined in my gl.h as 0x1908. now 6408 elements per pixel seem as a lot to me

    Oh, and the call to gluBuild2DMipmaps(...) is missing. I'm not sure if this is really required, but most people I've seen code from do this after the other call I just mentioned.

    John

    [This message has been edited by Sjonny (edited 03-20-2000).]

Similar Threads

  1. Problems Texture Mapping with Float Texture
    By CelticBlues in forum OpenGL: GLSL
    Replies: 21
    Last Post: 02-08-2009, 04:13 AM
  2. More texture problems: here we go....again!
    By gui24a in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-25-2008, 12:30 PM
  3. Texture Problems ...
    By Saintex in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-22-2002, 07:38 AM
  4. Texture Problems
    By spectrum in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 01-09-2002, 02:58 AM
  5. AVI texture problems
    By dmsy in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-12-2000, 01:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean