Jump to content
  • Advertisement
Sign in to follow this  
project6

OpenGL DevIL help & some string problems

This topic is 3806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys. I'm working on a plugin for a CAD application in VS2008, C++. I work with an API which is made for OpenGL, but I wont be using OGL at all (I hope) since the actual images (otherwise rendered) are already availible as image files. This API has a function that takes a vector of GLuints. I have a bunch of images I want to load there. I thought I might use DevIL for this, since I heard it's an easy task to convert an image (.JPG in this case) to GLuint, also I need to focus more on the rest of the plugin rather than this. I've been stuck with this for a long time now and would love to get some help on the subject. If someone could assist me with some pseudo code for doing this would be much appreciated. I have a function which is responsible for doing it, which is called in a for loop x times (depending on the number of images). It takes as parameter a pointer to the current .JPG. ( Cstring* fileName )
        ILuint imageName;
	GLuint image;
	ILboolean success;

	// Error check
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION)
	{
		return;
	}

	// Initialization
	ilInit();
	iluInit();
	ilutRenderer(ILUT_OPENGL);

	ilGenImages(1, &imageName);		// grab a new image name
	ilBindImage(imageName);			// bind it

	// Error should be 0 if everything went well
	ILenum Error = ilGetError();
	
	success = ilLoadImage( (const wchar_t*) fileName );

	Error = ilGetError();
The Error variable is ALWAYS != 0 (0 is when everything went well) and I don't know what to do. String issues. I hate it. THIS works:
success = ilLoadImage((const wchar_t*)"Z:/mypath/image0.jpg");
But not when I use the variable fileName :( Any help with this would be lovely. Thanks in advance [Edited by - project6 on July 9, 2008 5:30:22 AM]

Share this post


Link to post
Share on other sites
Advertisement
What's the error code your getting? Or are you getting different errors with every run? The only real problem I can see you may have is in the cast. It might not be returning actually what you want.

Share this post


Link to post
Share on other sites
Hint #1: never use C-style casts in C++. Use C++ casts instead, as they make it easier to notice errors.

Hint #2: never tell the compiler to shut up. (const wchar_t*) fileName is what C++ programmers call a reinterpret_cast. This basically takes the memory layout of fileName (which is a CString instance) and treats it as if it were a pointer to a wide string—which it isn't.

Converting a CString to a wchar_t is not difficult, but it's not that simple either. Google is your friend.

Share this post


Link to post
Share on other sites
ToohrVyk, thanks for your input.

Quote:
Hint #1: never use C-style casts in C++. Use C++ casts instead, as they make it easier to notice errors.


I'm not sure what you mean by this, is it the actual casting syntax you refer to? Like this:
(int) double


Isn't that really up to the developer, I mean what's easiest to read? I'm used to that syntax since we used it in every course in school and every project I've been part of so far.

Naturally I tried Google and some of the code snippets to convert the Cstring to a wchar_t but without success, therefore this post. I wouldn't go through the trouble to post here and wait for replies if I found the solution on Google. ;)

I probably tried three different methods of converting, none of them worked.

Share this post


Link to post
Share on other sites
Quote:
Original post by project6
Isn't that really up to the developer, I mean what's easiest to read? I'm used to that syntax since we used it in every course in school and every project I've been part of so far.


A given C-style cast can be a static-cast, a reinterpret-cast or a const-cast, depending on the context. Actually writing down the type of cast lets the compiler check that the programmer did not overlook some property of the context, while telling readers (and the search-in-files functionality) what the cast actually does without having to examine the context.

In this situation, did you know that your cast was a reinterpret-cast, as opposed to a static-cast, for instance?

Quote:
Naturally I tried Google and some of the code snippets to convert the Cstring to a wchar_t but without success, therefore this post. I wouldn't go through the trouble to register here and wait for replies if I hadn't tried Google first. ;)


For instance, what did the solution proposed here do?

Share this post


Link to post
Share on other sites
Hey ToohrVyk, thanks for your quick reply! :)

I'm not at work now so I can't test it in my code, I remember this solution though since I found it compact and I'm sure I tried it. If I'm not totally mistaken, the compiler didn't recognize the L2W function.

Can't say 100%, but I'm pretty certain.

Edit: and thanks for the cast description, I never put much effort into casting since I usually only cast int and doubles, I usually program with numbers not strings.

Share this post


Link to post
Share on other sites
The code snippet ToohrVyk linked to passes the compiler without errors, but I still get error code 1290.

I suspect there's something else going on here, since I tried several of these Cstring to wide and I still can't get pass the error check.

Share this post


Link to post
Share on other sites
0x050A = 1290 and if you look into il.h, you can find this line
#define IL_COULD_NOT_OPEN_FILE 0x050A



Share this post


Link to post
Share on other sites
I just found out that DevIL doesn't support unicode, how can I disable unicode in VS2008?

I have '_T' in front of all my strings ( _T("EXAMPLE") ) and If I understood this correctly, that will automatically treat the string according to what my project settings are? ( L"EXAMPLE" for unicode and simply "EXAMPLE" without? )

I tried changing to Multi-Byte in project properties, but my strings are still 'L' when I debug.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!