🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Gaux.h

Started by
3 comments, last by Ventas 16 years, 12 months ago
Ok, I did as one of the guys in one of the other NeHe topics said to do, to make gaux.h work. I am currently using Code::Blocks and yes; I am a bit noob aswell. I wanted to go try the OpenGL tutorials NeHe are so kind to give out. The only problem seems to make gaux working. I made theese following steps: made a bmp.cpp file like this:
//--------------------------------------------------------------
#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;
	    data = 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;
}
Then a header(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);
};
http://i121.photobucket.com/albums/o216/Ventasmentos/maincpp.jpg - and you can see the main.cpp and how in this pic. Please help me. My book won't come before a week or so, and I am really interrested in this! :) PS: The tags didn't work so it's a bitm essy you see >.> Best Regards, Ventas
Advertisement
It sounds that you mean glaux, and you have to include that header file in your code:
#include <Gl/Glaux.h> Wrong of me, I see now that you are coding a substitute for Glaux as a class and you cannot include BMP.h
If you try; #include "bmp.h" with small letters as it is. Or it looks on your picture that bmp.h is excluded from build. your picture
But on your picture of the project your bmp source file is bmp.c and here you say it's bmp.cpp

[Edited by - programering on July 4, 2007 6:39:52 AM]
Does this fix your problem then?
A little piece of advice: stop using GLaux, it's dead and you should acknowledge that. It was a small intermediate solution to a now well known and solved problem.

Here's some reading material:
http://openil.sourceforge.net/ - DevIL
http://cimg.sourceforge.net/ - CImg

A bit tired today but:

Do you mean that I should try with a .cpp instead? Well if I do so then Code::Blocks fickmichs it up. I don't know why, but it can figure out having two .cpp's in one project :S

I know it is old, but this is the only resource that I have about OpenGL programming atm. I want to get ready asap, without getting in a rush of course,w because this is one of the most interresting things I have ever participated in(C++ generally), and as I said my book won't come before a week or so :)


Best Regards,

Carver Smith

This topic is closed to new replies.

Advertisement