Jump to content
  • Advertisement
Sign in to follow this  
Snouty

OpenGL DevIL - Problems with loading a jpg-image

This topic is 2426 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,

I have problems to load an jpg-image. I googled for a while and in general, using DevIL seems to be a good way to do this. But unfortunately, everytime I call ilLoadImage("texture.jpg"), IL reports the error 1291 (

IL_INVALID_EXTENSION) and I just don't know why. Does anybody know, where the problem in my code is? Now, I'm really at a loss and would be grateful for any hint.

Thanks a lot for your help smile.png



#include "stdafx.h"
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
#include "Terrain.h"
#include <GL\SDL.h>
#include <SDL_image.h>
#include <GL\glext.h>
#include <IL\il.h>
#include <IL\ilu.h>
#include <IL\ilut.h>
using namespace std;

//#define NO_VBOS // If Defined, VBOs Will Be Forced Off

bool g_vbo_supp = false; // ARB_vertex_buffer_object support
bool g_multitex_supp = false; // ARB_multitexture support
bool g_texcombine_supp = false; // ARB_texture_env_combine support

//global variables for the heightmap
...
GLuint map_tex;
...

ILuint maptex_id;


void initGL(void){
LoadGLTextures();
...
}

int LoadGLTextures(){
ilGenImages(1, &maptex_id);
ilBindImage(maptex_id);
if(!ilLoadImage("texture.jpg")){
ilDeleteImages(1, &maptex_id);
ILenum error = ilGetError();
std::cout << "Image load failed - IL reports error: " << error << " - " << iluErrorString(error) << std::endl;
return false;
}
else{
...
}// Return Success
}

int main(int argc, char** argv)
{
ilutRenderer(ILUT_OPENGL);
ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);
glutInit(&argc, argv);
// init display mode:
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize (mainw_w, mainw_h);
glutInitWindowPosition (mainw_x, mainw_y);
glutCreateWindow (mainw_title);
// init OpenGL
initGL();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);

glutMainLoop();
//Quit SDL
SDL_Quit();
return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
Hello Snouty,
2 years ago I had the same problem on my university opengl project (where I used DevIL). The hint was that this problem was occurred not in all tested PCs. And finally a solution of that was:

// before use any api of DevIL (ILU, ILUT), call their "init" function.
ilInit();
iluInit();
ilutInit();

// loading a texture (GL context must be ready here)
const char *path = "...";// path to texture you want to load
GLuint tex = ilutGLLoadImage(path);
if(tex)
{
// TO DO with loaded texture
}


I hope this would help you!
Best wishes, FXACE.

Share this post


Link to post
Share on other sites
I am using libjpeg. It's pretty easy to use in tearms of loading and saving jpg images. Have a look at this one as an example of using it.

Goodluck

Share this post


Link to post
Share on other sites
How did you compile DevIL?

On my Windows machine (mingw), i don't have libjpeg installed so DevIL compiled without jpeg support.

Share this post


Link to post
Share on other sites
Hey guys,


sorry my laptop broke down last week after I posted my question. -.- Thanks a lot for your answers. I tried the first one and it worked directly :)
I have also another solution: I tried my "old" code together with visual studion 2010 premium and visual studio 2008 express...and it works. So, I am not sure, but for me it seems like there is a bug with respect to visual studio 2010 professional.

So again...thank you :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!