PDA

View Full Version : NeHe Borland 5.0 C++ Lesson number 6



darketernal
08-12-2002, 04:04 PM
Dear Reader
http://nehe.gamedev.net/tutorials/borland/lesson06.zip

i've downloaded this Borland tutorial 6 file that explains texture mapping And it works perfectly but

after painstakingly trying to write this code myself i am encountering an external error AUX_RGBImageRec *pTexImage = auxDIBImageLoad("Data/NeHe.bmp"); saying it can't find the file.

after

#include <glaux.h>

and including the glaux.lib , it still cannot find the neccessary information it is looking for.

How do i link this in my project in Borland 5.0 c++ Correctly?

Any Feedback Would Be Greatly Appreciated.

chowe6685
08-12-2002, 05:48 PM
perhaps you don't have a file nehe.bmp in the data directory

nexusone
08-12-2002, 06:13 PM
Make sure that you have created a directory called data in your project folder and copy the file "NeHe.bmp" to it.

example:
c:/...../projects/lesson6/data

note projects could be anyname, it is what every directory your program is being compiled to.



Originally posted by darketernal:
Dear Reader
http://nehe.gamedev.net/tutorials/borland/lesson06.zip

i've downloaded this Borland tutorial 6 file that explains texture mapping And it works perfectly but

after painstakingly trying to write this code myself i am encountering an external error AUX_RGBImageRec *pTexImage = auxDIBImageLoad("Data/NeHe.bmp"); saying it can't find the file.

after

#include <glaux.h>

and including the glaux.lib , it still cannot find the neccessary information it is looking for.

How do i link this in my project in Borland 5.0 c++ Correctly?

Any Feedback Would Be Greatly Appreciated.

darketernal
08-13-2002, 11:33 AM
i have the data directory at it's correct place, remember that if BMP does not exists, the cube will return white, what we see here is a unresolved external linker error to the auxDIBImage, i putted the glaux.lib in my own lesson6 learning created project,and i #include <glaux.h> in my project but i don't know were to LINK it in Borland Options? It's difficult i don't know how http://www.opengl.org/discussion_boards/ubb/frown.gif

chowe6685
08-13-2002, 11:36 AM
#pragma comment(lib, "glaux.lib")

darketernal
08-13-2002, 11:44 AM
although there were errors it LINKED http://www.opengl.org/discussion_boards/ubb/biggrin.gif hurrah *big smile*

darketernal
08-13-2002, 11:50 AM
Although it seemedly linked i only got a gray empty form on my screen :rolleyes

which is nice of course v.s a external error , ah any ways i posted the header and the cpp file down here, see if you can find any errors in my lesson6 code.


CPP FILE>>
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#pragma comment(lib, "glaux.lib")
//Opengl
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#include <float.h>
#include <fstream.h>

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
_control87(MCW_EM, MCW_EM);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject*, bool& done)
{
done = false;
wglMakeCurrent(m_hDC, m_hRC);
RenderGLScene();
SwapBuffers(m_hDC);
wglMakeCurrent(m_hDC, NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SetWindowStats(640, 480, 16);

m_hDC = GetDC(Handle);
SetPixelFormatDescriptor();
m_hRC = wglCreateContext(m_hDC);
wglMakeCurrent(m_hDC, m_hRC);

m_fXRot = 0.0f;
m_fYRot = 0.0f;
m_fZRot = 0.0f;

FormResize(NULL);

InitGL();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
if(BorderStyle == bsNone)
ChangeDisplaySettings(NULL,0);

ReleaseDC(Handle, m_hDC);
wglMakeCurrent(m_hDC, NULL);
wglDeleteContext(m_hRC);
}
//---------------------------------------------------------------------------
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
};
m_iPixelFormat = ChoosePixelFormat(m_hDC, &pfd);
SetPixelFormat(m_hDC, m_iPixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
wglMakeCurrent(m_hDC, m_hRC);

glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, static_cast<double>(ClientWidth) /
static_cast<double>(ClientHeight),
0.1,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

wglMakeCurrent(m_hDC, NULL);
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::SetWindowStats(int iWidth_, int iHeight_, int iColor_)
{
ClientWidth = iWidth_;
ClientHeight = iHeight_;

if(Application->MessageBox("Would You Like To Run In Fullscreen Mode?",
"Start FullScreen?",
MB_YESNO|MB_ICONQUESTION)==IDYES)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmPelsWidth = iWidth_;
dmScreenSettings.dmPelsHeight = iHeight_;
dmScreenSettings.dmBitsPerPel = iColor_;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWID TH|DM_PELSHEIGHT;

if(ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCC ESSFUL)
{
return false;
}
else
{
BorderStyle = bsNone;
Left = 0;
Top = 0;
}
}

return true;
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::InitGL()
{
wglMakeCurrent(m_hDC, m_hRC);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
LoadGLTextures();
wglMakeCurrent(m_hDC, NULL);
return TRUE;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RenderGLScene()
{

glLoadIdentity();
glTranslatef(0.0f, 0.0f, -5.0f);

glRotatef(m_fXRot, 1.0f, 1.0f, 0.0f);
glRotatef(m_fYRot, 0.0f, 1.0f, 0.0f);
glRotatef(m_fZRot, 0.0f, 0.0f, 1.0f);

glBindTexture(GL_TEXTURE_2D, m_uiTexture[0]);

glBegin(GL_QUADS);
//Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
//Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
//Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
//Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
//Right Face
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
//Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();

m_fXRot += 0.3f;
m_fYRot += 0.2f;
m_fZRot += 0.4f;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if(Key == VK_ESCAPE)
Close();
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::LoadGLTextures()
{
bool boStatus = false;

AUX_RGBImageRec *pTexImage = auxDIBImageLoad("Data/NeHe.bmp");

if (pTexImage != NULL)
{
boStatus = true;

glGenTextures(1, &m_uiTexture[0]);

glBindTexture(GL_TEXTURE_2D, m_uiTexture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, pTexImage->sizeX, pTexImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pTexImage->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

if (pTexImage->data)
free (pTexImage->data);

free(pTexImage);
}

return boStatus;
}
//---------------------------------------------------------------------------


HEADER FILE >>

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <GL/glaux.h>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormKeyPress(TObject *Sender, char &Key);
private: // User declarations
HDC m_hDC;
HGLRC m_hRC;
int m_iPixelFormat;

// Rotation Variables
float m_fXRot;
float m_fYRot;
float m_fZRot;

// Texture Storage
GLuint m_uiTexture[1];

bool __fastcall InitGL();
bool __fastcall SetWindowStats(int iWidth_, int iHeight_, int iColor);
bool __fastcall LoadGLTextures();


public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall IdleLoop(TObject *, bool&);
void __fastcall RenderGLScene();
void __fastcall SetPixelFormatDescriptor();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

remember that this is a BORLAND C++ 5.0 code.

It's a big mystery why it doesn't display a spinning cube with bmp in it. http://www.opengl.org/discussion_boards/ubb/eek.gif

darketernal
08-13-2002, 03:34 PM
Dear Chowe

after trying many times to insert

#pragma comment(lib, "glaux.lib")
it refused to work,

i put glaux.lib in the directory
i #include <gl/glaux.h>
i putted the #pragma comment in it,

after doing all these things it still didn't work, so i copy pasted the Borland working 5.0 C++ lesson 6 code into an empty form along with the header file, i included the #pragma comment(lib, "glaux.lib") but i still only receive a empty compiled gray screen as result http://www.opengl.org/discussion_boards/ubb/frown.gif how is this possible? did i link something in the incorrect way?

chowe6685
08-13-2002, 05:22 PM
well, glaux is an ancient library, and I never got it to work with my copy of borland, my recommendation is to just forget glaux and use something else like glut, devil or something you write yourself, its not worth the effort to get glaux running

darketernal
08-14-2002, 10:12 AM
Yeah great so now what? ,im only a beginner. I don't know why jeff created it with glaux then, if it isn't up to date why use it? I don't understand how to implement an alternative, this is very difficult http://www.opengl.org/discussion_boards/ubb/cool.gif

nexusone
08-15-2002, 12:07 PM
Very simpe use a graphics editor to change you BMP files to TGA files.
Then goto the nehe site or Nate Robins site and download the code for loading TGA files as a texture.



Originally posted by darketernal:
Yeah great so now what? ,im only a beginner. I don't know why jeff created it with glaux then, if it isn't up to date why use it? I don't understand how to implement an alternative, this is very difficult http://www.opengl.org/discussion_boards/ubb/cool.gif