runtime error, maybe to do with glauz

Started by
2 comments, last by Gage64 15 years, 5 months ago
When i compile my code, i get the error

1>skybox.cpp
1>c:\users\nick\desktop\university\graphics, c++\skybox\skybox\skybox.cpp(12) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : see declaration of 'fopen'
1>c:\users\nick\desktop\university\graphics, c++\skybox\skybox\skybox.cpp(14) : error C2664: 'auxDIBImageLoadW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 
So i have added the glaux replacement code, found from this site i think, but i am unsure how to impliment it. I have added the bmp.cpp and bmp.h files to my project, but then i have this code which was there originally

bool skybox::Load_Texture(unsigned int & aTexture, char * fileName) {

	if(!fileName) return false;					//if no file name is given return

	FILE *aFile = NULL;
	AUX_RGBImagm *image_record = NULL;

	if((aFile = fopen(fileName, "rb")) == NULL) return false;

	image_record = auxDIBImageLoad(fileName);	//Function to load BMP

	if(!image_record) return false;				//check that BMP loaded

	glGenTextures(1, &aTexture);				//generates 1 texture name

	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);		//sets how the pixels of the texture are stored

	glBindTexture(GL_TEXTURE_2D, aTexture);		//binds the name to the target
	

												//build prefiltered textures at different resolutions
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image_record->sizeX, 
					  image_record->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image_record->data);

												//give the texture its attributes
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	// Now we need to free the image data that we loaded since openGL stored it as a texture
	if (image_record) {							//if we stored data then free the memory
		if (image_record->data) {				//check if there is any data
			free(image_record->data);			//free the memory
		}
		free(image_record);						//free the image record
	}

	return true; //everything should have worked so return true
}
How would i change this to use the replacement glaux code? cheers
Advertisement
Sounds like you have UNICODE enabled in your project.
auxDIBImageLoadW is the UNICODE version.
You should disabled it or just use
auxDIBImageLoadA (the ASCII version)
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I am going to try an dget it working with the replacement code, but i have also remove unicode from my settings. So this is the code i got from nehe as a replacement to glaux
#include "stdafx.h"#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"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;}  


What i am struggling to understand now is how to use this. So i have the above and its h file saved in my project folder and linked to my project. Now in another class i am working in, i want to get a texture id, so i have this
#include "stdafx.h"#include <windows.h>#include <stdio.h>  //for file access							#include <gl\gl.h>							#include <gl\glu.h>							#include "skybox.h"#include "BMP.h"bool skybox::Load_Texture(unsigned int & aTexture, char * fileName) {	if(!fileName) return false;					//if no file name is given return	FILE *aFile = NULL;	AUX_RGBImageRec *image_record = NULL;	if((aFile = fopen(fileName, "rb")) == NULL) return false;	image_record = auxDIBImageLoadA(fileName);	//Function to load BMP	if(!image_record) return false;				//check that BMP loaded	glGenTextures(1, &aTexture);				//generates 1 texture name	glPixelStorei (GL_UNPACK_ALIGNMENT, 1);		//sets how the pixels of the texture are stored	glBindTexture(GL_TEXTURE_2D, aTexture);		//binds the name to the target													//build prefiltered textures at different resolutions	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image_record->sizeX, 					  image_record->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image_record->data);												//give the texture its attributes	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);	// Now we need to free the image data that we loaded since openGL stored it as a texture	if (image_record) {							//if we stored data then free the memory		if (image_record->data) {				//check if there is any data			free(image_record->data);			//free the memory		}		free(image_record);						//free the image record	}	return true; //everything should have worked so return true}


So what changes would i need to make to the above to make it use the first class i posted? I think i have to change the first few lines of the above class but not sure what i am changing them too.
Reading this might help.

This topic is closed to new replies.

Advertisement