Board index » cppbuilder » OpenGL Texture image from a TBitmap

OpenGL Texture image from a TBitmap

I am trying to generate a Texture image for OpenGL using a TBitmap.
OpenGL is expecting something along the lines of the following image
variable.

struct color
{
        int red;
        int green;
        int blue;

Quote
};

color image[IMAGE_SIZE];

I knwo passing canvas->Pixels wont work as the TColor does not
correspont to the color array mentioned above. Is there any easy way to
do this or do I have to convert pixel by pixel to the above format?

Damon

 

Re:OpenGL Texture image from a TBitmap


http://www.jsinfo.net/nsfz/personal/pinxue/OpenGL/OpenGLStepByStepPrj...
aux_demo.zip

Quote
"Damon Jacobsen" <codedra...@runbox.com> wrote in message

news:3B98049E.5020006@runbox.com...
Quote
> I am trying to generate a Texture image for OpenGL using a TBitmap.
> OpenGL is expecting something along the lines of the following image
> variable.

> struct color
> {
> int red;
> int green;
> int blue;
> };
> color image[IMAGE_SIZE];

> I knwo passing canvas->Pixels wont work as the TColor does not
> correspont to the color array mentioned above. Is there any easy way to
> do this or do I have to convert pixel by pixel to the above format?

> Damon

Re:OpenGL Texture image from a TBitmap


On Thu, 06 Sep 2001 16:19:58 -0700, Damon Jacobsen
<codedra...@runbox.com> wrote :

Quote
>I am trying to generate a Texture image for OpenGL using a TBitmap.
>OpenGL is expecting something along the lines of the following image
>variable.

>struct color
>{
>    int red;
>    int green;
>    int blue;
>};
>color image[IMAGE_SIZE];

Not very efficient. Try chars instead of ints, and set structure
alignment for that part to 1.

Quote

>I knwo passing canvas->Pixels wont work as the TColor does not
>correspont to the color array mentioned above. Is there any easy way to
>do this or do I have to convert pixel by pixel to the above format?

Convert pixel by pixel.

--
Martin

What I say is not true; I never speak the truth.

Re:OpenGL Texture image from a TBitmap


Try like this...

TMemoryStream *pm = new TMemoryStream ();
for (int i = 0; i < Canvas->Width; i++)
    for (int j = 0; j < Canvas->Height; j++)
    {

       pm->Write(GetRvalue( Canvas->Pixels[i][j]));
       pm->Write(GetGvalue( Canvas->Pixels[i][j]));
       pm->Write(GetBvalue( Canvas->Pixels[i][j]));
      // May be add alpfa channel here....

    }

GLubyte *bitmap= (GLubyte*) pm->Memory;
//-----------------------------------------------
Next, use
void glBitmap(
GLsizei width,
GLsizei height,
GLfloat xorig,
GLfloat yorig,
GLfloat xmove,
GLfloat ymove,
const GLubyte *bitmap
);

"Damon Jacobsen" <codedra...@runbox.com> ???????/???????? ? ????????
?????????: news:3B98049E.5020006@runbox.com...

Quote
> I am trying to generate a Texture image for OpenGL using a TBitmap.
> OpenGL is expecting something along the lines of the following image
> variable.

> struct color
> {
> int red;
> int green;
> int blue;
> };
> color image[IMAGE_SIZE];

> I knwo passing canvas->Pixels wont work as the TColor does not
> correspont to the color array mentioned above. Is there any easy way to
> do this or do I have to convert pixel by pixel to the above format?

> Damon

Re:OpenGL Texture image from a TBitmap


Martin,

        I have forgotten how to set structure alignment. I don't want to have to
set the entire program to byte alignment.

Damon

Quote
martin wrote:
> On Thu, 06 Sep 2001 16:19:58 -0700, Damon Jacobsen
> <codedra...@runbox.com> wrote :

>>I am trying to generate a Texture image for OpenGL using a TBitmap.
>>OpenGL is expecting something along the lines of the following image
>>variable.

>>struct color
>>{
>>        int red;
>>        int green;
>>        int blue;
>>};
>>color image[IMAGE_SIZE];

> Not very efficient. Try chars instead of ints, and set structure
> alignment for that part to 1.

>>I knwo passing canvas->Pixels wont work as the TColor does not
>>correspont to the color array mentioned above. Is there any easy way to
>>do this or do I have to convert pixel by pixel to the above format?

> Convert pixel by pixel.

> --
> Martin

> What I say is not true; I never speak the truth.

Re:OpenGL Texture image from a TBitmap


On Mon, 10 Sep 2001 14:56:30 -0700, Damon Jacobsen
<codedra...@runbox.com> wrote :

Quote
>Martin,

>    I have forgotten how to set structure alignment. I don't want to have to
>set the entire program to byte alignment.

>Damon

There are several ways to do this.

one :

#pragma pack(push, 1)

Your 1-byte-aligned code

#pragma pack(pop)

You can also just use #pragma pack(1), but using push & pop enables
you to restore the previous (global) setting.

two :

#include <pshpack1.h>

Your 1-byte-aligned code

#include <poppack.h>

--
Martin

What I say is not true; I never speak the truth.

Other Threads