Gluax Replacement Code
#1 Members - Reputation: 122
Posted 09 October 2004 - 03:19 AM
#3 Members - Reputation: 602
Posted 09 October 2004 - 04:28 AM
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.
#4 Members - Reputation: 432
Posted 09 October 2004 - 06:53 AM
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
//--------------------------------------------------------------
#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;
}
bmp.h
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);
};
#5 Members - Reputation: 122
Posted 10 October 2004 - 02:04 PM
#6 Anonymous Poster_Anonymous Poster_* Guests - Reputation:
Posted 14 October 2004 - 08:13 AM
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?
#7 Members - Reputation: 432
Posted 14 October 2004 - 11:17 AM
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).
#8 Anonymous Poster_Anonymous Poster_* Guests - Reputation:
Posted 14 October 2004 - 11:25 AM
It works. And the file's not in the same folder. Oh well.
Thanks!
#9 Anonymous Poster_Anonymous Poster_* Guests - Reputation:
Posted 15 October 2004 - 12:32 PM
(Google for these image converters)
Irfan View
DIMIN http://www.dimin.net/
The following code will show you how to load them and textrue planets:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8101&lngWId=3
#10 Members - Reputation: 122
Posted 17 October 2004 - 08:05 PM
...\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?
#11 Members - Reputation: 432
Posted 17 October 2004 - 11:34 PM
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.
#12 Members - Reputation: 122
Posted 18 October 2004 - 03:09 PM
#16 Members - Reputation: 100
Posted 06 August 2011 - 10:14 AM
#17 Members - Reputation: 100
Posted 01 January 2012 - 06:37 PM
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 data variable through either the destructor or when data!=NULL. 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 delete[] data, but thats not working either. I may be wrong in hypothesis and thats the reason for me making this request for your help.
#18 Members - Reputation: 432
Posted 02 January 2012 - 05:12 AM
It would probably be better today to just go for the TGA tutorials and drop this whole glAUX nonsence.
#19 Members - Reputation: 100
Posted 04 January 2012 - 04:30 AM






