Hello, I am currently working on a game, a Pacman remake.
So before I thought about using DevIL I used an Bitmap Loader that I found in the internet, the problem with it was though that it could only load .bmp and since I wanted small textures with transparency I decided to look for an image loader that could support multiple image formats and is easy to implement/use.
Now I already found some examples how to use the basic functions of DevIL and I think I have done everything right but somehow OpenGL cant read the data it gets or I dont know but he shows me only a white screen where he should load the textures.
So I decided to use the advanced libaries of DevIL where he directly loads the given image as an OpenGL texture and there he could display it. But it was somewhat blurry like he did something wrong when he converted the texture data (I would love to post a screenshot but my mobile internet doesnt allow me to go on hosting sites)
Anyway, here is the code where I initalize OpenGL:
int windowgl::InitGL(GLvoid) //All Setup For OpenGL Goes Here
{
if (!tex->loadBitmaps()) { return FALSE; } // all Bitmaps are loaded and go into a list
glEnable(GL_TEXTURE_2D); //Enable Texture Mapping
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_SMOOTH); //Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black Background
glClearDepth(1.0f); //Depth Buffer Setup
glEnable(GL_DEPTH_TEST); //Enables Depth Testing
glDepthFunc(GL_LEQUAL); //The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Really Nice Perspective Calculations
return TRUE; //Initialisation Went OK
}
here I draw the field where the texture should be displayed:
int level::DrawGLScene(GLvoid) //Here's Where We Do All The Drawing
{
fbreite = 25.0f * M_X;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear The Screen And The Depth Buffer
glLoadIdentity(); //Reset The Current Modelview Matrix
//Feld zeichnen mit Bildtexturen
for (int i = 0; i < M_Y; i++)
{
for (int j = 0; j < M_X; j++)
{
// Holt sich die derzeit benötigte Bitmap des Levels
glBindTexture(GL_TEXTURE_2D, tex->huii("image.bmp")); //I simplified this to loading only one image because in the game it done to complicated to explain (but the result should be the same)
// Zeichnet ein 25x25 Pixel großes Quadrat mit Textur
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 25.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(25.0f, 25.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(25.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glEnd();
glTranslatef( 25.0f, 0.0f, 0.0f); // Setzt den "Ursprung" 25 Pixel in x Richtung weiter, wo das nächste Quadrat gezeichnet wird
}
glTranslatef(-fbreite, 25.0f, 0.0f); // Geht mit dem "ursprung" die gesamte Pixelbreite des Levels zurück und 25 Pixel in y Richtung um in der nächsten Zeile zu beginnen zu zeichnen
}
}
and here I try to load the image (the exhausting waywhere he doesnt display anything):
GLuint textures::huii(char* fname)
{
char path[30] = ".\\bitmaps\\";
strcat_s(path, 30, fname); //contains now the path to the bitmap
ILuint image, width, height;
GLuint imgid;
ilInit(); // Initialization of DevIL
ilGenImages(1, &image);
ilBindImage(image);
ILboolean loaded = ilLoadImage(path);
if (loaded == IL_FALSE) return -1;
loaded = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); //Convert every colour component into unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA
width = ilGetInteger(IL_IMAGE_WIDTH); // getting image width
height = ilGetInteger(IL_IMAGE_HEIGHT); // and height
glGenTextures(1, &imgid);
glBindTexture(GL_TEXTURE_2D, imgid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), width, height, 0, ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_TYPE), ilGetData());
ilDeleteImages(1, &image);
return imgid;
}
(and the easy way where he displays the images like he had some data loss during the conversion):
GLuint textures::huii(char* fname)
{
char path[30] = ".\\bitmaps\\";
strcat_s(path, 30, fname); //contains now the path to the bitmap
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL);
return ilutGLLoadImage(path);
}
I hope you can help me solve the problem