Код:
struct oglpic {
SDL_Surface *pic;
//GLuint texture=NULL;
GLuint texture;
//GLenum texture_format=NULL;
GLenum texture_format;
GLint nofcolors;
int x;
int y;
}
oglpic[8];
void init_GL()
{
//glClearColor(0, 0, 0, 0);
glEnable(GL_TEXTURE_2D);
glViewport (0, 0, 590, 590);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 590, 590, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void loadImage(int num)
{
oglpic[num].nofcolors=oglpic[num].pic->format->BytesPerPixel;
if(oglpic[num].nofcolors==3)
{
if(oglpic[num].pic->format->Rmask==0x000000ff) oglpic[num].texture_format=GL_RGBA8;
else oglpic[num].texture_format=GL_BGR;
}
else if(oglpic[num].nofcolors==4)
{
if(oglpic[num].pic->format->Rmask==0x000000ff) oglpic[num].texture_format=GL_RGBA;
else oglpic[num].texture_format=GL_BGRA;
}
else printf("warning: the image is not truecolor…this will break ");
glGenTextures(1, &oglpic[num].texture);
glBindTexture(GL_TEXTURE_2D, oglpic[num].texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, oglpic[num].nofcolors, oglpic[num].pic->w, oglpic[num].pic->h, 0, oglpic[num].texture_format, GL_UNSIGNED_BYTE, oglpic[num].pic->pixels);
SDL_FreeSurface(oglpic[num].pic);
}
void drawImage(int num, int x, int y)
{
glBindTexture(GL_TEXTURE_2D, oglpic[num].texture);
glBegin(GL_QUADS);
// Top-left
glTexCoord2i(0, 0);
glVertex2i(x, y);
// Bottom-left
glTexCoord2i(1, 0);
glVertex2i(x+oglpic[num].x, y);
// Bottom-right
glTexCoord2i(1, 1);
glVertex2i(x+oglpic[num].x, y+oglpic[num].y);
// Top-right
glTexCoord2i(0, 1);
glVertex2i(x, y+oglpic[num].y);
glEnd();
glLoadIdentity();
}
В конце программы естественно выполняется glFlush() и SDL_GL_SwapBuffers(). Пробовал подключить glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT), но не помогает.