Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

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
    Intern 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
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Breda, Netherlands
    Posts
    58

    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).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •