I'm trying to use OpenGL to display images read from disk by Microsoft CImage library.
The image now can be roughly seen in the window, but clearly there are something wrong. The image is gray, and it's sheared. I can't figure out where is the problem because every pixel should be corresponding to the its slot in _data.
OpenGL image:

Original image:

Below is my code:
int _w = 300;
int _h = 300;
GLubyte ***_data;
void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, _w, 0.0, _h);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0, 0);
glDrawPixels(_w, _h, GL_RGB,
GL_UNSIGNED_BYTE, _data);
glFlush();
}
int main(int argc, char** argv) {
CImage img_handler;
img_handler.Load(_T("bg.jpg"));
_w = img_handler.GetWidth();
_h = img_handler.GetHeight();
COLORREF pixel;
_data = new GLubyte**[_h];
for (int y = 0; y < _h; y++) {
_data[_h-y-1] = new GLubyte*[_w];
for (int x = 0; x < _w; x++) {
pixel = img_handler.GetPixel(x, y);
_data[_h-y-1][x] = new GLubyte[3];
_data[_h-y][x][0] = (GLubyte)GetRValue(pixel);
_data[_h-y][x][1] = (GLubyte)GetGValue(pixel);
_data[_h-y][x][2] = (GLubyte)GetBValue(pixel);
}
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH/*enable depth buffer*/);
glutInitWindowSize(_w, _h);
glutCreateWindow("test");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}