   the imagine I loaded is different from the original file
  main.cpp code:#include <iostream>#include <stdlib.h>#ifdef __APPLE__#include <OpenGL/OpenGL.h>#include <GLUT/glut.h>#else#include <GL/glut.h>#endif#include "imageloader.h"using namespace std;const float BOX_SIZE = 7.0f; //The length of each side of the cubefloat _angle = 0;  //The rotation of the boxGLuint _textureId; //The OpenGL id of the texturevoid handleKeypress(unsigned char key, int x, int y) {switch (key) {case 27: //Escape keyexit(0);}}void initRendering() {glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_NORMALIZE);glEnable(GL_COLOR_MATERIAL);Image* image =new Image("vtr.bmp");_textureId = image->textureId;delete image;}void handleResize(int w, int h) {glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);}void drawScene() {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f, 0.0f, -20.0f);GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f};GLfloat lightPos[] = {-2 * BOX_SIZE, BOX_SIZE, 4 * BOX_SIZE, 1.0f};glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);glLightfv(GL_LIGHT0, GL_POSITION, lightPos);glRotatef(-_angle, 1.0f, 1.0f, 0.0f);glBegin(GL_QUADS);//Top faceglColor3f(1.0f, 1.0f, 0.0f);glNormal3f(0.0, 1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);//Bottom faceglColor3f(1.0f, 0.0f, 1.0f);glNormal3f(0.0, -1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);//Left faceglNormal3f(-1.0, 0.0f, 0.0f);glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);//Right faceglNormal3f(1.0, 0.0f, 0.0f);glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glEnd();glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, _textureId);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glColor3f(1.0f, 1.0f, 1.0f);glBegin(GL_QUADS);//Front faceglNormal3f(0.0, 0.0f, 1.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);//Back faceglNormal3f(0.0, 0.0f, -1.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(0.0f, 1.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glEnd();glDisable(GL_TEXTURE_2D);glutSwapBuffers();}//Called every 25 millisecondsvoid update(int value) {_angle += 1.0f;if (_angle > 360) {_angle -= 360;}glutPostRedisplay();glutTimerFunc(25, update, 0);}int main(int argc, char** argv) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(400, 400);glutCreateWindow("Putting It All Together - videotutorialsrock.com");initRendering();glutDisplayFunc(drawScene);glutKeyboardFunc(handleKeypress);glutReshapeFunc(handleResize);glutTimerFunc(25, update, 0);glutMainLoop();return 0;}imageloader.h code:#ifndef IMAGE_LOADER_H_INCLUDED#define IMAGE_LOADER_H_INCLUDED#include <GL/glut.h>//Represents an imageclass Image {public:Image(char* fileName);~Image();GLuint textureId;int width;int height;};imageloader.cpp code:#include "imageloader.h"#include <SDL/SDL_image.h>#include <SDL/SDL.h>#include <stdlib.h>using namespace std;Image::Image(char* fileName){    /*load image*/    SDL_Surface* surface;    GLuint textureid;    int mode;    surface = IMG_Load(fileName);   if (!surface){   printf("Could not load image: %s", fileName);   exit(0);    }   /* Work out what format to tell glTexImage2D to use... */    if (surface->format->BytesPerPixel == 3) /* RGB 24bit */    {    mode = GL_RGB;    }else if (surface->format->BytesPerPixel == 4) /* RGBA 32bit */    {    mode = GL_RGBA;    }else{   printf("Could not determine pixel format of image: %s", fileName);   SDL_FreeSurface(surface);   exit(0);}    /* Create one texture name */    glGenTextures(1, &textureid);    /* Tell opengl to use the generated texture name */    glBindTexture(GL_TEXTURE_2D, textureid);    /* Read from the sdl surface and put it into an opengl texture */    glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);    /* Set up texture filters */    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);   this->textureId = textureid;    this->height=surface->h;    this->width=surface->w;/* Clean up */    SDL_FreeSurface(surface);}Image::~Image() {}[Edited by - HuaMuLan on September 29, 2009 9:35:06 PM]
  http://i486.photobucket.com/albums/rr230/HuaMuLanChina/test1.jpg http://i486.photobucket.com/albums/rr230/HuaMuLanChina/vtr.jpg original image   ;  It is upside down and the R and B channels are reversed.You could manually swap the channels, or try using GL_BGR / GL_BGRA is they are supported.Inverting the image isn't a big deal you can do that during drawing.   ;  so you mean the image I load with SDL was in format GL_BGR / GL_BGRA not GL_RBG / GL_RBGA ?   ;  Some bad code there, commented:#include <iostream>#include <stdlib.h>#ifdef __APPLE__#include <OpenGL/OpenGL.h>#include <GLUT/glut.h>#else#include <GL/glut.h>#endif#include "imageloader.h"using namespace std;const float BOX_SIZE = 7.0f; //The length of each side of the cubefloat _angle = 0; //The rotation of the boxGLuint _textureId; //The OpenGL id of the texturevoid handleKeypress(unsigned char key, int x, int y) {switch (key) {case 27: //Escape keyexit(0); //not good}}void initRendering() {glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_NORMALIZE);glEnable(GL_COLOR_MATERIAL);Image* image =new Image("vtr.bmp");_textureId = image->textureId;delete image;}void handleResize(int w, int h) {glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);}void drawScene() {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f, 0.0f, -20.0f);GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f};GLfloat lightPos[] = {-2 * BOX_SIZE, BOX_SIZE, 4 * BOX_SIZE, 1.0f};glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);glLightfv(GL_LIGHT0, GL_POSITION, lightPos);glRotatef(-_angle, 1.0f, 1.0f, 0.0f);glBegin(GL_QUADS);//Top faceglColor3f(1.0f, 1.0f, 0.0f);glNormal3f(0.0, 1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);//Bottom faceglColor3f(1.0f, 0.0f, 1.0f);glNormal3f(0.0, -1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);//Left faceglNormal3f(-1.0, 0.0f, 0.0f);glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);//Right faceglNormal3f(1.0, 0.0f, 0.0f);glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glEnd();glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, _textureId);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glColor3f(1.0f, 1.0f, 1.0f);glBegin(GL_QUADS);//Front faceglNormal3f(0.0, 0.0f, 1.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);//Back faceglNormal3f(0.0, 0.0f, -1.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(0.0f, 1.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glEnd();glDisable(GL_TEXTURE_2D);glutSwapBuffers();}//Called every 25 millisecondsvoid update(int value) {_angle += 1.0f;if (_angle > 360) {_angle -= 360;}glutPostRedisplay();glutTimerFunc(25, update, 0);}int main(int argc, char** argv) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(400, 400);glutCreateWindow("Putting It All Together - videotutorialsrock.com");initRendering();glutDisplayFunc(drawScene);glutKeyboardFunc(handleKeypress);glutReshapeFunc(handleResize);glutTimerFunc(25, update, 0);glutMainLoop();return 0;}imageloader.cpp code:#ifndef IMAGE_LOADER_H_INCLUDED#define IMAGE_LOADER_H_INCLUDED#include <GL/glut.h>//Represents an imageclass Image {public:Image(char* fileName);~Image();GLuint textureId;int width;int height;};imageloader.cpp code:#include "imageloader.h"#include <SDL/SDL_image.h>#include <SDL/SDL.h>#include <stdlib.h>using namespace std;Image::Image(char* fileName){/*load image*/SDL_Surface* surface;GLuint textureid;int mode;surface = IMG_Load(fileName);if (!surface){printf("Could not load image: %s", fileName);exit(0);// no good}/* Work out what format to tell glTexImage2D to use... */if (surface->format->BytesPerPixel == 3) /* RGB 24bit */{mode = GL_RGB;}else if (surface->format->BytesPerPixel == 4) /* RGBA 32bit */{mode = GL_RGBA;}else{printf("Could not determine pixel format of image: %s", fileName);SDL_FreeSurface(surface);exit(0);//no good}/* Create one texture name */glGenTextures(1, &textureid);/* Tell opengl to use the generated texture name */glBindTexture(GL_TEXTURE_2D, textureid);/* Read from the sdl surface and put it into an opengl texture */glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);/* Set up texture filters */glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);this->textureId = textureid;this->height=surface->h;this->width=surface->w;/* Clean up */SDL_FreeSurface(surface);}Image::~Image() {}   ;  Why exit(0) bad code? Is there other ways to exit?   ;FIXED:#include <iostream>#include <stdlib.h>#ifdef __APPLE__#include <OpenGL/OpenGL.h>#include <GLUT/glut.h>#else#include <GL/glut.h>#endif#include "imageloader.h"using namespace std;const float BOX_SIZE = 7.0f; //The length of each side of the cubefloat _angle = 0; //The rotation of the boxGLuint _textureId; //The OpenGL id of the texturevoid handleKeypress(unsigned char key, int x, int y) {switch (key) {case 27: //Escape keyexit(0); //not good}}void initRendering() {glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_NORMALIZE);glEnable(GL_COLOR_MATERIAL);Image* image =new Image("vtr.bmp");_textureId = image->textureId;delete image;}void handleResize(int w, int h) {glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);}void drawScene() {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f, 0.0f, -20.0f);GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f};GLfloat lightPos[] = {-2 * BOX_SIZE, BOX_SIZE, 4 * BOX_SIZE, 1.0f};glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);glLightfv(GL_LIGHT0, GL_POSITION, lightPos);glRotatef(-_angle, 1.0f, 1.0f, 0.0f);glBegin(GL_QUADS);//Top faceglColor3f(1.0f, 1.0f, 0.0f);glNormal3f(0.0, 1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);//Bottom faceglColor3f(1.0f, 0.0f, 1.0f);glNormal3f(0.0, -1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);//Left faceglNormal3f(-1.0, 0.0f, 0.0f);glColor3f(0.0f, 1.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glColor3f(0.0f, 0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);//Right faceglNormal3f(1.0, 0.0f, 0.0f);glColor3f(1.0f, 0.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glColor3f(0.0f, 1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glEnd();glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, _textureId);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glColor3f(1.0f, 1.0f, 1.0f);glBegin(GL_QUADS);//Front faceglNormal3f(0.0, 0.0f, 1.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(1.0f, 0.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);glTexCoord2f(0.0f, 1.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);//Back faceglNormal3f(0.0, 0.0f, -1.0f);glTexCoord2f(0.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(1.0f, 0.0f);glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(1.0f, 1.0f);glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);glTexCoord2f(0.0f, 1.0f);glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);glEnd();glDisable(GL_TEXTURE_2D);glutSwapBuffers();}//Called every 25 millisecondsvoid update(int value) {_angle += 1.0f;if (_angle > 360) {_angle -= 360;}glutPostRedisplay();glutTimerFunc(25, update, 0);}int main(int argc, char** argv) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(400, 400);glutCreateWindow("Putting It All Together - videotutorialsrock.com");initRendering();glutDisplayFunc(drawScene);glutKeyboardFunc(handleKeypress);glutReshapeFunc(handleResize);glutTimerFunc(25, update, 0);glutMainLoop();return 0;}imageloader.cpp code:#ifndef IMAGE_LOADER_H_INCLUDED#define IMAGE_LOADER_H_INCLUDED#include <GL/glut.h>//Represents an imageclass Image {public:Image(char* fileName);~Image();GLuint textureId;int width;int height;};imageloader.cpp code:#include "imageloader.h"#include <SDL/SDL_image.h>#include <SDL/SDL.h>#include <stdlib.h>using namespace std;Image::Image(char* fileName){/*load image*/SDL_Surface* surface;GLuint textureid;int mode;surface = IMG_Load(fileName);if (!surface){printf("Could not load image: %s", fileName);exit(0);// no good}/* Work out what format to tell glTexImage2D to use... */if (surface->format->BytesPerPixel == 3) /* RGB 24bit */{mode = GL_RGB;}else if (surface->format->BytesPerPixel == 4) /* RGBA 32bit */{mode = GL_RGBA;}else{printf("Could not determine pixel format of image: %s", fileName);SDL_FreeSurface(surface);exit(0);//no good}/* Create one texture name */glGenTextures(1, &textureid);/* Tell opengl to use the generated texture name */glBindTexture(GL_TEXTURE_2D, textureid);/* Read from the sdl surface and put it into an opengl texture */glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);/* Set up texture filters */glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);this->textureId = textureid;this->height=surface->h;this->width=surface->w;/* Clean up */SDL_FreeSurface(surface);}Image::~Image() {};  actually , I did not seen any changes in your fixed code ,speciesUnknown.Can you point out which parts you have changed?   ;Quote:Original post by Jason PetraskoIt is upside down and the R and B channels are reversed.Can you give me more information about the reversed situation? any links?thanx in advance   ;Quote:Original post by HuaMuLanactually , I did not seen any changes in your fixed code ,speciesUnknown.Can you point out which parts you have changed?Looks like my plan went kaputt. What I really wanted to show is that posting large dumps of sourcecodes blindly into this forum is not best thing you can do (no indendation, no syntax highlighting, wastes pages of browser display).And what speciesUnknown fixed was to enclose that dump into a pair of source-tags. See FAQ.But about exit() anyways: exit() is bad because it basically immediately exits your application without proper stack unwinding, meaning that destructor calls and cleanup code might not be executed. See also the posix manpage.   