Sign in to follow this  
Mooncabbage

Gluax Replacement Code

Recommended Posts

Mooncabbage    122
Please bear with me here, my computer is doing some funky cookie crap and I keep logging out, so I can't be bothered writing a long explanation of why I am asking this, only to have it all disappear again. Can someone please tell me how to use the Gluax Replacement Code?

Share this post


Link to post
Share on other sites
Mooncabbage    122
Someone reply, please? I can't be bothered looking for gluax.dll after all the effort it took to find the other depreciated libraries, and once you get to tutorial no. 6 that becomes a real problem.

Share this post


Link to post
Share on other sites
_DarkWIng_    602
a) you might wat to wait a bit longer than half an hour before posting again.. this is forum.. it takes time..
b) look at later tutorials that use TGA loading code. It's far from perfect, but it willget you started. Of you could use one of many image loading libs.

Share this post


Link to post
Share on other sites
lc_overlord    436
I really wish nehe would rewrite that tuturial, all those "the tururial doesn't work?", "where can i get the glaux thingy?" and "could somebody send me the glaux replacementcode?" posts are really starting to bug me.

NeHe, if i write a bmp loader for you, will you include it in your Tuturials.


either way, i think these are the files.
bmp.cpp
[code]
//--------------------------------------------------------------
#include <windows.h> // Header File For Windows - has structures for BMP format
#include <stdio.h> // Header File For Standard Input/Output
#include <stdlib.h>
#include "BMP.h"

/*------------------------------------------------------------------
BMP Loader - a quick and dirty substitute for GLaux
if you only use GLaux to load BMP files will load any format of a
windows DIB BMP format graphics file Only works on a windows box
Caution! memory for the data is allocated using 'new'.
In the NeHe tutorials the memory is reclaimed using 'free'.
For the small tutorials its not a big deal but not a good practice in
larger projects (heap trashing not good). J.M. Doyle : 12 Jan 2003
------------------------------------------------------------------*/

AUX_RGBImageRec *auxDIBImageLoad(const char *FileName)
{
return new AUX_RGBImageRec(FileName);
}


void AUX_RGBImageRec::convertBGRtoRGB()
{
const DWORD BitmapLength = sizeX * sizeY * 3;
byte Temp; // not quick but it works
for(DWORD i=0; i< BitmapLength; i += 3)
{
Temp = data[i];
data[i] = data[i+2];
data[i+2] = Temp;
}
}

AUX_RGBImageRec::AUX_RGBImageRec(const char *FileName): data(NULL), NoErrors(false)
{
loadFile(FileName);
}

AUX_RGBImageRec::~AUX_RGBImageRec()
{
if (data != NULL) delete data;
data = NULL;
}

bool AUX_RGBImageRec::loadFile(const char* Filename)
{
BITMAPINFO BMInfo; // need the current OpenGL device contexts in order to make use of windows DIB utilities
const HDC gldc = wglGetCurrentDC(); // a handle for the current OpenGL Device Contexts
// assume there are errors until file is loaded successfully into memory
NoErrors = false; // release old data since this object could be used to load multiple Textures
if(data != NULL) delete data; // windows needs this info to determine what header info we are looking for
BMInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); // Get windows to determine color bit depth in the file for us
BMInfo.bmiHeader.biBitCount = 0; // Get windows to open and load the BMP file and handle the messy decompression if the file is compressed
// assume perfect world and no errors in reading file, Ha Ha
HANDLE DIBHandle = LoadImage(0,Filename, IMAGE_BITMAP, 0, 0,LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); // use windows to get header info of bitmap - assume no errors in header format

GetDIBits(gldc, (HBITMAP)DIBHandle, 0,0, NULL, &BMInfo, DIB_RGB_COLORS);
sizeX = BMInfo.bmiHeader.biWidth;
sizeY = BMInfo.bmiHeader.biHeight; // change color depth to 24 bits (3 bytes (BGR) / pixel)
BMInfo.bmiHeader.biBitCount = 24; // don't want the data compressed
BMInfo.bmiHeader.biCompression = BI_RGB;
const DWORD BitmapLength = sizeX * sizeY * 3; // 3 bytes (BGR) per pixel (24bp)
// allocate enough memory to hold the pixel data in client memory
data = new byte[BitmapLength]; // Get windows to do the dirty work of converting the BMP into the format needed by OpenGL
// if file is already 24 bit color then this is a waste of time but makes for short code
// Get the actual Texel data from the BMP object

if (GetDIBits(gldc, (HBITMAP)DIBHandle, 0, sizeY, data, &BMInfo, DIB_RGB_COLORS))
{
NoErrors = true;
convertBGRtoRGB(); // NOTE: BMP is in BGR format but OpenGL needs RGB unless you use GL_BGR_EXT
}

DeleteObject(DIBHandle); // don't need the BMP Object anymore
return NoErrors;
}
[/code]

bmp.h
[code]
class AUX_RGBImageRec {
void convertBGRtoRGB();
public:
byte *data;
DWORD sizeX;
DWORD sizeY;
bool NoErrors;
AUX_RGBImageRec(): NoErrors(false), data(NULL) {};
AUX_RGBImageRec(const char *FileName);
~AUX_RGBImageRec();
bool loadFile(const char *FileName);
friend AUX_RGBImageRec *auxDIBImageLoad(const char *FileName);
};
[/code]

Share this post


Link to post
Share on other sites
Mooncabbage    122
Thanks for the help. The impatience was due to the time i posted... waaaaaaaaaaaay too early in the morning (or late at night). Neways, it's not finding the replacement code that is a problem, it is using it. Perhaps the original/early tutorials just need a facelift or something? Someone to go thru and get rid of gluax and update it a bit.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I'm sorry. I probably seem like an idiot, but...

How do I use this code?

I've saved the two files as bmp.h and bmp.cpp.

I replaced the glaux include line in lesson 6 with #include "bmp.cpp"

But that doesn't compile either.

Am I supposed to do something with glAux Replacement.cpp?

Share this post


Link to post
Share on other sites
lc_overlord    436
1. you have to include the bmp.cpp file in your project so it will be compiled and linked into your exe.
2. it's #include "bmp.h" not #include "bmp.cpp"

there are no guaranties that this code will work, but i think it will.

Regarding "glAux Replacement.cpp", i think not,
this code replaces AUX_RGBImageRec class(witch is the only real reason to use glAux), it works for me most of the times (allthough only if the imagefile is in the same dir as the .exe, odd).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Ah. I see. So including a file in your porject is like merging the source files.
It works. And the file's not in the same folder. Oh well.

Thanks!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Just use load RAW Bitmaps. There are no includes to worry about. Just need an image converter to convert your textures from .bmp or .jpeg or..... whateva to RAW extension. It´s as easy as... "save as" RAW into your exe folder-

(Google for these image converters)

Irfan View
DIMIN [url]http://www.dimin.net/[/url]

The following code will show you how to load them and textrue planets:

[url]http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8101&lngWId=3[/url]

Share this post


Link to post
Share on other sites
Mooncabbage    122
OK, I finally got around to trying to use the code. I copied the bmp.h file into a bmp.h file, and included it in lesson 7, but upon compiling i get an error. Duh, i think, the two classes have different names. So first i try to change the class name in bmp.h to auxDIBImageLoad and compile, and get the same error. So i change it back, and replace all the auxDIBImageLoad words with the one in bmp.h and get:

...\OpenGL7.cpp In function `AUX_RGBImageRec* LoadBMP(char*)':
58 ...\OpenGL7.cpp cannot convert `AUX_RGBImageRec' to `AUX_RGBImageRec*' in return
Linker error] undefined reference to `auxDIBImageLoad(char const*)'

What is my problem?

Share this post


Link to post
Share on other sites
lc_overlord    436
Strange, when i did it it worked fine, no bugs no warnings, no nothing.

maybe you need step by step instructions.

1. take the bmp.cpp and bmp.h files and copy them to the same directory as lesson7.cpp(in your case it's probobly OpenGL7.cpp instead of lesson7.cpp).

2. open up the project in vc++ 6.0 (other versions should work to)

3. under file view find the "source files" folder, right click on it an select add files to folder, choose "bmp.cpp".

4. do the same for the "header files" folder but choose "bmp.h".

5. in "lesson7.cpp" change the folowing line
#include <gl/glaux.h> // Header File For The Glaux Library
to
#include "bmp.h" // Header File For The Glaux replacement Library

6. compile, run and be happy.

Share this post


Link to post
Share on other sites
Mooncabbage    122
I use dev cpp, but that shouldn't be a problem, i probably forgot to tell the compiler to link it properly or something... However i didn't even touch the .cpp... figured it was an example file, doh ><. Thanks for the help, i'll try and figure out the source file bit in dev cpp, i think i've seen it somewhere before, however, i'm fairly new to actual c++, so things like source files and having to link included things as well as include them are new and strange to me.

Share this post


Link to post
Share on other sites
ulair    100
There is a little error in the bmp.h of yours. You need to add the line AUX_RGBImageRec *auxDIBImageLoad(const char *FileName); The function is only defined in the .cpp. That's probably why it didn't work for Mooncabbage :) Well it works for me now. Thank you! Now on to limit that hyperfast framerate a bit O_o ...

Share this post


Link to post
Share on other sites
CLOUGHAX    100
[b] [font="helvetica, arial, verdana, tahoma, sans-serif"][color="#5a5a5a"]@[/color][/font][url="http://www.gamedev.net/user/37987-lc_overlord/"]lc_overlord[/url][font="helvetica, arial, verdana, tahoma, sans-serif"][color="#5a5a5a"] Run-time error when deallocating the [font=courier new,courier,monospace]data[/font] pointer[/color][/font][/b]

[b] [color=#5A5A5A][font=helvetica, arial, verdana, tahoma, sans-serif]I have tested your AUX_RGBImage class and for the most part it works until when the program reaches the point of deallocating the byte [font=courier new,courier,monospace]data[/font] variable through either the destructor or when [font=courier new,courier,monospace]data!=NULL[/font]. I have been trying to solve the problem ever since but it keeps crashing when i reach that point and the only conclusion is can come to is that i overlooked something concerning classes and dynamic allocation or the microsoft visual 2010 compiler is not working cause i even realize that from the code you allocated an byte array so to actually deallocate it wold be [font=courier new,courier,monospace]delete[] data,[/font] but thats not working either. I may be wrong in hypothesis and thats the reason for me making this request for your help.[/font][/color][/b]

Share this post


Link to post
Share on other sites
lc_overlord    436
This pice of code is pretty ancient and im unsure if it even works with the latest Visual studio or how easy it is to fix it as i havn't run this code in a few years, i know it works for MSVC++ 6.0 but that version didn't even have namespace implemented.

It would probably be better today to just go for the TGA tutorials and drop this whole glAUX nonsence.

Share this post


Link to post
Share on other sites
CLOUGHAX    100
Well thanks for the advice ill try and give it another shot although the last tutorial i did on bitmap was a total garbage and it seemed as if the writer got fed up at the end and just pasted the rest of the code which was in fact incomplete and had me stuck for a couple hours trying to figure out his gibberish. But i got fed up and just download an incredible library named free freeImage that works but i dont feel satisfied knowing that it wasnt me who wrote the code. So ill give it a next shot

Share this post


Link to post
Share on other sites
Caste    973
I added an explanation on how to load textures with SOIL a while ago. I strongly recommend using this easy and reliable method to load your textures instead of GLAUX or any replacement code...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this