OpenGL help – Assign Bitmap to texture

Hi,

I am learning OpenGL in Delphi, experimenting with code others had written.

I found out a way to display information to the user, by writing the text to a bitmap and displaying the bitmap.

The existing code loaded the bitmap from a file, so I have been using the same technique (as below).

What I am wanting to know is how to assign the bitmap directly to the PTAUX_RGBImageRec texture (without needing to save it first).

var Bmp: TBitmap;
    texture: PTAUX_RGBImageRec;
    TextArry: ARRAY[0..9] OF GLuint;

   // Update User
   Bmp:= TBitmap.Create;
   Bmp.Width:= 100;
   Bmp.Height:= 30;
   Bmp.Canvas.Brush.Style:= bsClear;
   Bmp.Canvas.Font.Color:= clBlack;
   Bmp.Canvas.Font.Name:= 'Roboto';
   Bmp.Canvas.Font.Size:= 16;
   Bmp.Canvas.TextOut(2, 2,'Info to the user');
   Bmp.SaveToFile('imgXX.bmp');
   Bmp.Free;

   // Sign
   texture:= auxDIBImageLoadA('imgXX.bmp');
   glGenTextures(1, TextArry[9]);
   glBindTexture(GL_TEXTURE_2D, TextArry[8]);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
   glTexImage2D(GL_TEXTURE_2D, 0, 3, texture^.sizeX, texture^.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture^.data);

(Note: I googled for info on this, but was unable to find the answer.)

This is not an area I know a lot about but I think it might be worth looking at this repo: nehe-opengl/delphi at master · gamedev-net/nehe-opengl · GitHub

It’s pretty old but most of the code is still going to apply. Go up to the main part of the repo to see links to the lessons. Apparently, the guy who created them all passed away but I believe there are lots of tutorials available still.

I expect if you clone the repo and do a Grep search on it you might find plenty of example that will do what you want.

Just to offer a close to the discussion,

I was already looking at the NeHe lessons, as well as the Sulaco OpenGL Projects, and had not found a BMP to Texture example.
Now I have been all the NeHe lessons and Sulaco OpenGL Projects, but all the projects utilised loading textures from file or resource.

With internet searches, I found complicated ways of (almost hacking) a VCL Bitmap to a OpenGL Texture. Yet the complexity and resource requirements meant it was no better than “save to temp file, load the texture” process.

I might try and ask the Skia4Delphi guys - they are experts on this kind of thing and I’m pretty certain one of them will have a solid answer.

Did anyone try asking an LLM? :slight_smile: