Hey everyone, well, I’m trying to use openil and apparently something is wrong with my code… It compiles, links, ect with no problems… the problem is though (of course) the image doesn’t display… I draw the quad, and the texture should be mapped onto it, but it isnt… here is my code(all of it since its a small app), knowing me it will be something so stupid I’ll want to slap myself… thanks
note: it was already commented, because my brother wants to learn opengl after I get decent at it, so i was saving myself from commenting later on…
#include <gl/glut.h> #include <il/ilut.h> #include <stdlib.h> int texture[1]; bool loadTexture() { ILuint ImgId; // The image name ilGenImages(1, &ImgId); // Generate an image name ilBindImage(ImgId); // Bind image as the current one if (!ilLoadImage("test.bmp")) // Load the image and check for errors { ilDeleteImages(1, &ImgId); // If it couldn't load, delete it all return false; // return false to show that loading was uncessful } texture[0] = ilutGLBindTexImage(); // Send the image to opengl ilDeleteImages(1, &ImgId); // Delete the image name, since its also been stored int texture[0] return true; // Return successful load } // Called when the prog starts to setup basic stuff void init() { glClearColor(0.0, 0.0, 0.0, 0.0); // Sets it so it clears to black whenever the sceen is cleared glColor3f(1.0, 1.0, 1.0); // Sets the drawing color to white if(!loadTexture()) exit(1); // Exit prog if the texture couldnt be loaded } // Called each time to redraw the scene void display() { glClear(GL_COLOR_BUFFER_BIT); // Clear The Screen glLoadIdentity(); // Reset The View glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); // Lets Make a quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); // Passes the stuff from main to do some init suff. glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); // Sets the drawing pixel method, and enables double buffers glutInitWindowPosition(50, 50); // puts the window 50 pixels down and 50 pixels right from top left of screen glutInitWindowSize(256, 256); // Makes the window 500x500 pixels glutCreateWindow("Some title here"); // Creates a window with this title glutDisplayFunc(display); // Calls display whenever the window needs to be reshown glutIdleFunc(display); // Calls display whenever there is freetime, we dont want freetime, we want drawing init(); // does init stuff that I dont want called each time glutMainLoop(); // Whoohoo, lets run the prog return 0; }