Loading BMP in BCB 5

I have been trying to learn how to load a texture in BCB 5 for a very long time now. I have visited nehe and gone to many different tutorials and none of them work. The main problem seems to be a function that is something like auxDIBLoadBMP()
and BCB has trouble with it. If I comment it out, the code programmed into it gives me an error that says that it can’t create a rendering context. Can someone give me code that I can copy right into my compiler so I can learn how to do it myself? Thanks in advance for any help.

You did not think taking a piece of code out would not cause problems?
It is one of the most inportant part of that program, it loads the texture file. The error is bacause the texture was not loaded.

I think borland does not have support for the glaux library.

Your other option is to download one of the glut versions of the nehe tutors, which has a TGA files loader. Just convert the BMP texture file to a TGA and use the code supplied. I also think he has a BMP file loader that does not use the glaux library.

Originally posted by DragonMage3000:
I have been trying to learn how to load a texture in BCB 5 for a very long time now. I have visited nehe and gone to many different tutorials and none of them work. The main problem seems to be a function that is something like auxDIBLoadBMP()
and BCB has trouble with it. If I comment it out, the code programmed into it gives me an error that says that it can’t create a rendering context. Can someone give me code that I can copy right into my compiler so I can learn how to do it myself? Thanks in advance for any help.

http://www.thebits.org
or http://www.richplum.co.uk/cbuilder
Document :: Open GL Tutorial.
Author :: John R. Thomas Jr.
From “The Bits…” the C++Builder Information & Tutorial Site http://www.cbuilder.dthomas.co.uk

//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include “TextureMap.h”
#include <math.h>

//---------------------------------------------------------------------------
#pragma resource “*.dfm”

TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
xRot = yRot = 0.0f;
sphere = gluNewQuadric();
cylinder = gluNewQuadric();
cylindertop = gluNewQuadric();
cylinderbottom = gluNewQuadric();
cone = gluNewQuadric();
conebottom = gluNewQuadric();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject*, bool& done)
{
done = false;
RenderGLScene();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RenderGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawObjects();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetupRC()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);

}
//---------------------------------------------------------------------------
void __fastcall TForm1: rawObjects()
{
/*
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, -50.0, 0.0);
glTexCoord2f(0.0, 2.0); glVertex3f(-50.0, 50.0, 0.0);
glTexCoord2f(2.0, 2.0); glVertex3f(50.0, 50.0, 0.0);
glTexCoord2f(2.0, 0.0); glVertex3f(50.0, -50.0, 0.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
*/

glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture1);
gluQuadricTexture(cone, GL_TRUE);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(-150.0f, 0.0f, -50.0f);
gluCylinder(cone, 50, 0, 100, 50, 10);
glPopMatrix();

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture1);
gluQuadricTexture(conebottom, GL_TRUE);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(-150.0f, 0.0f, -50.0f);
gluDisk(conebottom, 0, 50, 10, 10);
glPopMatrix();

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture2);
gluQuadricTexture(sphere, GL_TRUE);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 0.0f);
gluSphere(sphere, 50, 50, 50);
glPopMatrix();

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture3);
gluQuadricTexture(cylinder, GL_TRUE);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(150.0f, 0.0f, -50.0f);
gluCylinder(cylinder, 50, 50, 100, 50, 10);
glPopMatrix();
glEnd();

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture3);
gluQuadricTexture(cylindertop, GL_TRUE);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(150.0f, 0.0f, -50.0f);
gluDisk(cylinderbottom, 0, 50, 50, 50);
glPopMatrix();
glEnd();

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture3);
gluQuadricTexture(cylinderbottom, GL_TRUE);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(150.0f, 0.0f, 50.0f);
gluDisk(cylindertop, 0, 50, 50, 50);
glPopMatrix();
glEnd();

glPopMatrix();
glFlush();
glDisable(GL_TEXTURE_2D);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, PixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
GLfloat nRange = 200.0f;
w = ClientWidth;
h = ClientHeight;
glViewport(0, 0, w, h);

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();

 
 if (w &lt;= h)
 glOrtho(-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
 else
 glOrtho(-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);


 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
wglMakeCurrent(hdc, NULL);
wglDeleteContext(hrc);
ReleaseDC(Handle, hdc);
gluDeleteQuadric(cone);
gluDeleteQuadric(cylinder);
gluDeleteQuadric(cylindertop);
gluDeleteQuadric(cylinderbottom);
gluDeleteQuadric(sphere);
gluDeleteQuadric(conebottom);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormKeyDown(TObject Sender, WORD &Key,
TShiftState Shift)
{
switch(Key)
{
case VK_UP:
xRot-= 5.0f;
break;
case VK_DOWN:
xRot += 5.0f;
break;
case VK_LEFT:
yRot -= 5.0f;
break;
case VK_RIGHT:
yRot += 5.0f;
break;
}
if(xRot > 356.0f)
xRot = 0.0f;
if(xRot < -1.0f)
xRot = 355.0f;
if(yRot > 356.0f)
yRot = 0.0f;
if(yRot < -1.0f)
yRot = 355.0f;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetTextureMap()
{
/

bitmap = new Graphics::TBitmap;
GLubyte bits[64][64][4];

bitmap-&gt;LoadFromFile("square.bmp");

for(int i = 0; i &lt; 64; i++)
{
	for(int j = 0; j &lt; 64; j++)
    {
     	bits[i][j][0]= (GLbyte)GetRValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][1]= (GLbyte)GetGValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][2]= (GLbyte)GetBValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][3]= (GLbyte)255;
    }
}

glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
*/
bitmap = new Graphics::TBitmap;
bitmap-&gt;LoadFromFile("seaside.bmp");
GLubyte bits[64][64][4];
for(int i = 0; i &lt; 64; i++)
{
	for(int j = 0; j &lt; 64; j++)
    {
     	bits[i][j][0]= (GLbyte)GetRValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][1]= (GLbyte)GetGValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][2]= (GLbyte)GetBValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][3]= (GLbyte)255;
    }
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);

bitmap-&gt;LoadFromFile("swimming pool.bmp");
for(int i = 0; i &lt; 64; i++)
{
	for(int j = 0; j &lt; 64; j++)
    {
     	bits[i][j][0]= (GLbyte)GetRValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][1]= (GLbyte)GetGValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][2]= (GLbyte)GetBValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][3]= (GLbyte)255;
    }
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);

bitmap-&gt;LoadFromFile("prairie wind.bmp");
for(int i = 0; i &lt; 64; i++)
{
	for(int j = 0; j &lt; 64; j++)
    {
     	bits[i][j][0]= (GLbyte)GetRValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][1]= (GLbyte)GetGValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][2]= (GLbyte)GetBValue(bitmap-&gt;Canvas-&gt;Pixels[i][j]);
        bits[i][j][3]= (GLbyte)255;
    }
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture3);
glBindTexture(GL_TEXTURE_2D, texture3);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
delete bitmap;

}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hdc = GetDC(Form1->Handle);
Canvas->CopyMode = cmSrcCopy;
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
if(hrc == NULL)
ShowMessage(“:-)~ hrc == NULL”);
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage(“Could not MakeCurrent”);
w = ClientWidth;
h = ClientHeight;
SetupRC();
SetTextureMap();
}
//---------------------------------------------------------------------------

[This message has been edited by HJ (edited 10-20-2002).]