Sign in to follow this  
EmrldDrgn

DevIL is giving me headaches...

Recommended Posts

I can't get OpenIL to make textures in the NeHe texture tutorial. I've been trying to figure it out for the last 3 days... please help! Here is my code for texture loading... please tell me what I'm missing! All that happens when I run this code is that my cube appears with grey sides.

int LoadGLTextures ()
{
	ilInit();
	iluInit();
	ilutRenderer(ILUT_OPENGL);
	ILuint ImgId;										// The Image Name

	ilGenImages(1, &ImgId);								// Generate Image Name
	ilBindImage(ImgId);									// Bind Image Name to Be Current
	if (ilLoadImage("Data/Eggs.bmp"))
	{// Load the Bitmap and Check for Errors
		ilDeleteImages(1, &ImgId);						// If Could Not Load, Delete Image
		return FALSE;									//  and Return False
	}

	texture[0] = ilutGLBindTexImage();
	ilDeleteImages(1, &ImgId);

	return true;
}

//There's some stuff here... but it's not important.

//Then in DrawGLScene, there's this line...

	glBindTexture(GL_TEXTURE_2D, texture[0]);
//And that's all I have about textures.




[Edited by - EmrldDrgn on July 26, 2006 6:19:49 PM]

Share this post


Link to post
Share on other sites
I don't think you're supposed to call ilDeleteImages(1, &ImgId) in loadGLTextures(). This would just delete the texture you're trying to use.

Why can't you just use:
texture[0] = ImgId;

Since ilLoadImage returns a boolean value, should not the check for a failed imageload be:
if (!ilLoadImage("Data/Eggs.bmp"))
{
...//LoadImage failed
}


Make sure to call glEnable(GL_TEXTURE_2D);.

Make sure the texture coordinates are correct.

Good Luck.

Share this post


Link to post
Share on other sites
I think that the problem is, I'm not initializing ILUT correctly. I don't know exactly how to do it, but I think the problem is definitly with ilutGlBindTexImage();.

Anyone who uses DevIL, can you help me to initialize ILUT? I've looked at the documentation, but I still can't figure it out.

Share this post


Link to post
Share on other sites
Perhaps this will work:

void InitDevIL()
{
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);
ilutInit();
}

void ShutDownDevIL()
{
ilShutDown();
}

GLuint LoadGLTexture(const char* str)
{
return ilutGLLoadImage(str);
}

InitDevIL();
GLuint id = LoadGLTexture("Data/Eggs.bmp");
glBindTexture(GL_TEXTURE_2D,id);

Share this post


Link to post
Share on other sites
I tried that, and it just... won't... WORK! I cannot believe how long this is taking me to work out! I'm so annoyed, that I am just going to post the entire source file and ask if anyone could fix it. I know that that's "frowned upon" in the forum FAQ, but I am dying of frustration over here.

#include <windows.h>		// Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
#include <il\il.h> // Header File For OpenIL
#include <il\ilu.h> // Header File For OpenILU
#include <il\ilut.h> // Header File For OpenILUT

HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application

bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

GLfloat xrot; // X Rotation ( NEW )
GLfloat yrot; // Y Rotation ( NEW )
GLfloat zrot; // Z Rotation ( NEW )

GLuint texture[1]; // Storage For One Texture ( NEW )

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc


int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);
ilutInit();
ILuint ImgId; // The Image Name

ilGenImages(1, &ImgId); // Generate Image Name
ilBindImage(ImgId); // Bind Image Name to Be Current
if (ilLoadImage("Data/Eggs.bmp")) { // Load the Bitmap and Check for Errors
ilDeleteImages(1, &ImgId); // If Could Not Load, Delete Image
return FALSE; // and Return False
}

texture[0] = ilutGLBindTexImage(); // Send the Image to OpenGL
ilDeleteImages(1, &ImgId); // Delete the Image Name, As GL Has a Copy

return TRUE; // Return Success
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}

glViewport(0,0,width,height); // Reset The Current Viewport

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}

int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE
}

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return TRUE; // Initialization Went OK
}

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-5.0f);

glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);

glBindTexture(GL_TEXTURE_2D, texture[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, 1.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();

xrot+=0.3f;
yrot+=0.2f;
zrot+=0.4f;
return TRUE; // Keep Going
}

GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}

if (hRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL
}

if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}

if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}

if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
}

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height

fullscreen=fullscreenflag; // Set The Global Fullscreen Flag

hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name

if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
}
else
{
// Pop Up A Message Box Letting User Know The Program Is Closing.
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE; // Return FALSE
}
}
}

if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size

// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen

if (!InitGL()) // Initialize Our Newly Created GL Window
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

return TRUE; // Success
}

LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
{
switch (uMsg) // Check For Windows Messages
{
case WM_ACTIVATE: // Watch For Window Activate Message
{
if (!HIWORD(wParam)) // Check Minimization State
{
active=TRUE; // Program Is Active
}
else
{
active=FALSE; // Program Is No Longer Active
}

return 0; // Return To The Message Loop
}

case WM_SYSCOMMAND: // Intercept System Commands
{
switch (wParam) // Check System Calls
{
case SC_SCREENSAVE: // Screensaver Trying To Start?
case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
return 0; // Prevent From Happening
}
break; // Exit
}

case WM_CLOSE: // Did We Receive A Close Message?
{
PostQuitMessage(0); // Send A Quit Message
return 0; // Jump Back
}

case WM_KEYDOWN: // Is A Key Being Held Down?
{
keys[wParam] = TRUE; // If So, Mark It As TRUE
return 0; // Jump Back
}

case WM_KEYUP: // Has A Key Been Released?
{
keys[wParam] = FALSE; // If So, Mark It As FALSE
return 0; // Jump Back
}

case WM_SIZE: // Resize The OpenGL Window
{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
return 0; // Jump Back
}
}

// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop

// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE; // Windowed Mode
}

// Create Our OpenGL Window
if (!CreateGLWindow("NeHe's Texture Mapping Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}

while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}

if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's Texture Mapping Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}

// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}


I know... I'm not supposed to do this, and you are under no obligation to actually read this code. But if you would, I would really, REALLY appreciate it. TIA.

Share this post


Link to post
Share on other sites
I don't understand what your problem is. That code that you are posting works fine if you use the code I posted before.

In your code, replace the function LoadGLTextures with this:
int LoadGLTextures()
{
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);
ilutInit();

texture[0] = ilutGLLoadImage("Data/Eggs.bmp");

return TRUE;
}



I have compiled it and it rendered a cube with the texture. What errors are you getting?

Share this post


Link to post
Share on other sites
I wasn't getting any errors, that's what was bugging me. It's fixed now. The code you just posted works, but only if I go into the debug directory of my project and run the EXE compiled from the code, not if I just hit F5 to run in debug mode. I'm not sure why that is, but it works! That's all that matters. Thanks a ton for all your help and patience with my idiocy.

Share this post


Link to post
Share on other sites
I'm back, and I need a little more help. I'm trying to generalize my texture loading functions, and I tried to change it so that it took a parameter and returned a GLuint, like so:

GLuint GLLoadTexture (std::string loader)
{
texture = ilutGLLoadImage("Data/" + loader + ".bmp");

return texture;
}

but I get an error (cannot convert std::string to const ILstring). I tried to get around this in the following ways:

Make the function take a const char *.
Make the std::string const.
Make the function take an ILstring.

The char * and ILstring gave me "cannot add two pointers", the const string gave the same as a normal string. How can I fix this problem? It seems like ILstring doesn't define a + operator to operate with strings, but that seems shortsighted at best. Some help, please?

PS sorry for the double post but editing doesn't move it up the page... and that's kind of a long post for an edit.

Share this post


Link to post
Share on other sites
Quote:
Original post by EmrldDrgn
I'm back, and I need a little more help. I'm trying to generalize my texture loading functions, and I tried to change it so that it took a parameter and returned a GLuint, like so:

GLuint GLLoadTexture (std::string loader)
{
texture = ilutGLLoadImage("Data/" + loader + ".bmp");

return texture;
}

but I get an error (cannot convert std::string to const ILstring). I tried to get around this in the following ways:

Make the function take a const char *.
Make the std::string const.
Make the function take an ILstring.

The char * and ILstring gave me "cannot add two pointers", the const string gave the same as a normal string. How can I fix this problem? It seems like ILstring doesn't define a + operator to operate with strings, but that seems shortsighted at best. Some help, please?

PS sorry for the double post but editing doesn't move it up the page... and that's kind of a long post for an edit.

can you post the code for ilutGLLoadImage? because i'm looking on the DevIL and I see no such function. also most loading functions, especially those based OGL, which is based in C, AFAIK, are gonna take a C-string as opposed to a C++ string.

Share this post


Link to post
Share on other sites
Ummm... no, no I can't, mostly because I don't know where I can find it. It's not a function I programmed. However, I've changed my idea to a slightly less easy to use and slightly easier to program one, where my function simply takes an ILstring and is not added to anything.

I'm now getting very wierd errors... all from this bit of code:

*(map[y][x].front().tile) -> image = loader;

map is a two-dimentional array of lists of map_tiles (a struct). front returns the first item in the list, tile is a pointer to a struct named tile_struct.
Loader is of type ILstring, and so is image, which is defined in tile_struct.

However, when I try to compile this code, I get this error: cannot convert from ILstring to char. This means that it thinks image is a char, right? Image used to be a char, but I modified the parameter to be an ILstring. Why am I getting this error? It seems like the compiler is lagging behind what I've actually coded, but I don't understand how this is possible, or how I might fix it. I also tried changing the ILstring parameter to a char, just to see what would happen, and I got the same error, with an additional one:

illegal indirection.

[Edited by - EmrldDrgn on July 27, 2006 1:37:52 AM]

Share this post


Link to post
Share on other sites
I believe that ILstring is actually a typedef'd char*. your immediate problem is that long piece of code is being evaluated a char as opposed to a char*. try just this: (map[y][x].front().tile) ->image = loader;

edit: try it with and without the parentheses.

Share this post


Link to post
Share on other sites
That works, and the code compiles, but I get an "assertion" error when I try to run the program. I don't know what causes this, only that the code which displays it is buried deep in the bowels of the list header. It then says "List iterator not derefrencable". I'm currently looking through the help on assertions, as is suggested by the error message, but I'm really not understanding what's going wrong.

Share this post


Link to post
Share on other sites
post the map and tile codes. it could be the way you are dereferencing the map variables. also is the item in the list a pointer? if it is you'll have to change it to: map[y][x].front()->tile->image = loader;

Share this post


Link to post
Share on other sites
As usual, I was just being an idiot. Apparently that's the error that it gives you when you don't have anything in a list and try to use front. I had forgotten to call my wonderful InitList function I spent most of today writing, so all my lists were empty. I fixed it up, and my code now works. Thanks for all your help, everyone. Now I just have to get the movement code hammered out and I'll have a working demo... in theory. Thanks again for everything.

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