Opengl + SDL + DevIL Problem
I don't know where is a problem,
My image won't load on Quad
but quad is loaded :
#include <windows.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_main.h>
#include <il/il.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glut.h>
int main(int argc, char** argv)
{
SDL_Event event;
ILuint texid; //nazwa zdjecia
ILboolean success; //wartosc dla zwrotu z zapytania czy zostalo zaladowne zdjecie
GLuint image;
int finished;
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_HWSURFACE);
glViewport(0, 0, 640, 480);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 640.0, 480.0, 0.0, 0.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(ilGetInteger(IL_VERSION_NUM) < IL_VERSION)
{
return -1;
}
ilInit();
ilGenImages(1, &texid);
ilBindImage(texid);
success = ilLoadImage("Logo.jpg"); // Loading image
if (success)
{
success = ilConvertImage (IL_RGBA , IL_UNSIGNED_BYTE); //Convert colors into unsigned byte
if (!success)
{
return -1;
}
glGenTextures(1, ℑ); //Texture name generator
glBindTexture(GL_TEXTURE_2D, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
ilGetData()); //Texture specification
}
else
{
SDL_Quit();
return -1;
}
//ilDeleteImages(1, &texid); //because we copied image to the texture data
//Main Loop
finished = 0;
while(!finished)
{
while (SDL_PollEvent(&event))
{
switch ((event.type))
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
finished = 1;
break;
case SDL_QUIT:
finished = 1;
break;
}
}
//draw a Quad
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex2i(0, 0);
glTexCoord2i(0,1); glVertex2i(0, 480);
glTexCoord2i(1,1); glVertex2i(640,480 );
glTexCoord2i(1,0); glVertex2i(640, 0);
glEnd();
SDL_GL_SwapBuffers();
glFlush();
}
glDeleteTextures(1, ℑ);
SDL_Quit();
return 0;
}
Please help Me
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement