I’m brand new to OpenGL, so of course I’m having issues.
I have a 24-bit bitmap file, which is an 8x8 checker pattern, black and white. I just want to draw it to the screen using glDrawPixels:
#include <iostream>
#include <fstream>
#include <gl/glut.h>
using namespace std;
void display(void)
{
ifstream inFile;
inFile.open(“checker.bmp”, ios::in | ios::binary);
char contents[246];
inFile.read(contents, sizeof(contents));
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2f(0.0, 0.0);
glDrawPixels(8, 8, GL_UNSIGNED_BYTE, GL_RGB, &contents[54]);
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE);
glutInitWindowSize (600, 600);
glutInitWindowPosition (200, 100);
glutCreateWindow (“Test Program…”);
glutDisplayFunc(display);
glutMainLoop();
return EXIT_SUCCESS;
}
The window gets drawn white and my bitmap is nowhere to be found.
Also, I read that bitmaps are stored BGR style, but passing GL_BGR isn’t recognized by the compiler (???). For black and white it shouldn’t matter, though, since my pixels are stored like FFF000FFF000FFF… anyway. The pixel data starts at byte 54 in the file.
I’m sure there’s a more elegant way to read the file, etc, but I don’t see why this shouldn’t work.