Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:42:22+00:00 2026-06-18T07:42:22+00:00

Trying to get an bmp to wrap an object (cylinder). I got an non

  • 0

Trying to get an bmp to wrap an object (cylinder). I got an non image texture to wrap the
cylinder, but when i tried to do the same with an image it comes out
with a fuzzy/white tv screen black and white color to it? I am going to post what i had changed to try and get bmp to work. Hopefully i can get some answers :d

First I needed a 24 bit true color 256×256 image. I created this in Paint
resized it to 256 pixels by 256 pixels and saved as 24 bit (.bmp)

Second here is the interface part. As it has a few types and const that may help
figure this out. In this i added the type RTGB, and TWrap along with the var wapper. Also
made Const “ColorComps=3” instead of 4 due to 24 bit windows bmp file has no alpha
component. This is the interface , as it might help. But i think the issue is with the function readbitmap.

unit zap1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls,opengl,shapes, Vcl.Forms, Vcl.Dialogs, Transfrm, cOpenGL;

type
 TTexe13=packed record
    red,
    green,
    blue: GLubyte;
  end;

  TTexe14=packed record
    red,
    green,
    blue,
    alpha: gLubyte;
  end;
  TForm2 = class(TForm)
    OpenGL1: TOpenGL;
    Transform1: TTransform;
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure Transform1Paint(Sender: TObject);
    procedure CylinderT(sTex,tTex:glFloat);
  private
    { Private declarations }
    deltax,
    deltaY,
    deltaZ:GLfloat;
    procedure idle(Sender:TObject;var Done:boolean);
  public
    { Public declarations }
    Function ReadBitmap(const FilePath:string;var sWidth,tHeight:glsizei):pointer;
  end;

var
  Form2: TForm2;

const
  Level=0;
  Border=0;
  ColorComps=3;

type
  TRGB=packed record
    r,g,b: byte;
  end;
  TWrap=array[0..0] of TRGB;
var
  Wrapper: pointer;

Next i added the ReadBitmap (which i think my problem lies here).
What it should do..
Opens the designated file, gets the file size and subtracts the header sizes to obtain the size of the actual bitmap. Then it reads the file header and checks for a valid bitmap signature. Next the function reads the info header and extracts the width and height in pixels, which it communicates to the caller via the var parameters

  finally it allocates the required memory and asigns the bimap into that memory. the function then returns a pointer to the memory containing the raw true-color bitmap. Then at the end i added a pixel-flipping loop. due to openGL uses RGB and windows BGR.



Function TForm2.ReadBitmap(const FilePath:String;var sWidth,tHeight:GLsizei):pointer;
const
  szh=SizeOf(TBitmapFileHeader);
  szi=SizeOf(TBitmapInfoHeader);
var
  bmpfile: file;
  bfh:TBitmapFileHeader;
  bmi:TBitmapInfoHeader;
  t:byte;
  x,
  fpos,
  size: integer;
begin
  assignfile(bmpfile,FilePath);
  reset(bmpfile,1);
  size := FileSize(bmpfile)-szh-szi;
  blockread(bmpfile,bfh,szh);
  if bfh.bfType<>$4D42  then
    raise EinvalidGraphic.Create('Invalid Bitmap');
  blockread(bmpfile,bmi,szi);
  with bmi do
  begin
    sWidth := biWidth;
    tHeight := biHeight;
  end;
  getmem(result,size);
  blockread(bmpfile,result^,size);
  for x  := 0 to sWidth*tHeight-1 do
  with TWrap(result^)[x] do
  begin
    t := r;
    r := b;
    b := t;
  end;
end;

last of all i added a few updates to oncreate event. the var sWidth and tHeight
which should get the width / height from the read bitmap function. and the openGL command
for wrapping

 Wrapper := ReadBitmap('SomeImage.bmp',sWidth,tHeight);
  glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGB,GL_UNSIGNED_BYTE,Wrapper);
  freemem(Wrapper);

WHich now looks like

procedure TForm2.FormCreate(Sender: TObject);
var
  swidth,
  theight: GLsizei;
begin
  glPixelStorei(GL_UNPACK_ALIGNMENT,1);
  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_FILTER,GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  Wrapper := ReadBitmap('Fig11-11.bmp',sWidth,tHeight);
  glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGBA,GL_UNSIGNED_BYTE,Wrapper);
  freemem(wrapper);
  glEnable(GL_TEXTURE_2D);
  glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
  application.OnIdle := idle;
  deltaX := 0.01;
  deltaY := 0.01;
  deltaZ := 0.01;
  cylinderBase;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:42:23+00:00Added an answer on June 18, 2026 at 7:42 am
    glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGBA,GL_UNSIGNED_BYTE,Wrapper);
    

    To

    glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGB,GL_UNSIGNED_BYTE,Wrapper);
    

    just took the A out of GL_RGB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a bunch of div's to wrap around an image, but
I'm trying to get all the data from image file (jpg/jpeg/gif/png/bmp etc.) use Lua's
trying to get same string on tooltip as is in the Text e.g. Text=<%#
Trying to get a random string out of ListArray on the button pressed. Always
Trying to get my arrow image to stick to the right of the anchor
I'm trying to get an image to display with one of the colors replaced
I'm trying to get an Image from a WCF service. I have an OperationContract
I have been trying to get thumbnails to work with an AsyncTask for image
I've been trying to load a bitmap in a non-activity class but everything I've
I'm trying to read a BMP image (greyscales) with C, save values into an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.