OpenGl Texture

OpenGl Texture

Post by Tersiu » Fri, 27 Jun 2003 02:21:35



In the examples dir of c++ builder there is a example under the dir
/OpenGl/Drawing
In this example textures are loaded by using the TBitmap component.
Here folows that code:

     bitmap = new Graphics::TBitmap;
     bitmap->LoadFromFile("red.bmp");
     GLubyte bits[64][64][4];
     for(int i = 0; i < 64; i++)
     {
        for(int j = 0; j < 64; j++)
         {
             bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
             bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
             bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
             bits[i][j][3]= (GLbyte)255;
         }
     }

     glGenTextures(1, &texture1);

     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA,                
GL_UNSIGNED_BYTE, bits);

In this example they allready know the height and width.
How would one load a texture with an unknown height and width?
Would one use dynamic arrays?
Could you please provide some code.
Thanks in advance.
TK

 
 
 

OpenGl Texture

Post by Scott Heima » Fri, 27 Jun 2003 07:55:49


This is untested, uncompiled code written on the fly - but it should give
you the idea...

      bitmap = new Graphics::TBitmap;
      bitmap->LoadFromFile("red.bmp");
      unsigned char *bits = new unsigned
char[4*bitmap->Width*bitmap->Height];
    unsigned char *p = bits;
    for ( unsigned int i = 0; i < bitmap->Height; i++ )
    {
        for ( unsigned int j = 0; j < bitmap->Width; j++ )
        {
            p[0] = (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
            p[1] = (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
            p[2] = (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
            p[3] = (unsigned char)255;
            p += 4;
        }
    }

      glGenTextures(1, &texture1);

      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap->Height, bitmap->Width,
0, GL_RGBA,
 GL_UNSIGNED_BYTE, bits);

    delete [] bits;

There are other solutions as well.  My BMGLib will read several image
formats and convert them to bit arrays, which you can easily convert to
OpenGL textures.  You can download the project from my web site.  Look at
the 'texture' example in the Borland folder for an example.

--
Regards,
Scott
http://members.cox.net/scottheiman/
(a valid e-mail address can be found on my home page)

 
 
 

1. AVI as OpenGL Texture sample (Win32, ms-opengl)

I've made a quick sample of using a Video For Windows movie for an OpenGL
texture.  

There is also an introductory sample for using bitmap stored as resources
as textures.

The sample is at a friend's page at :

http://pages.infinit.net/activate

It's not an OpenGL or Win32 programming tutorial, you've been warned! 8-)

2. Visualization '93 Advance Program

3. help - openGL textures from external files

4. Need Advice for Good book in rotation transformations

5. OpenGL texture tutorials??

6. Help Corel Move?????

7. double buffer OpenGL texture problem on O2

8. look for source code to read and write AVI files

9. Indy/O2 video-in as OpenGL Texture?

10. Performer 2.0 doesn't load OPENGL textures for 3D Studio files

11. Summary: SGI Impact opengl texture implementation is NOT bugged

12. OpenGL Texturing

13. OpenGL texture mapping - constrained to integer coordinates ?