DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Hello World Opengl Bitmap

05.26.2010
| 1985 views |
  • submit to reddit
        // description of your code here

// A simple OpenGL and glut program
#include <GL/gl.h>
#include <GL/glut.h>

GLubyte fire[128] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x01, 0xf0,
    0x00, 0x00, 0x07, 0xf0, 0x0f, 0x00, 0x1f, 0xe0,
    0x1f, 0x80, 0x1f, 0xc0, 0x0f, 0xc0, 0x3f, 0x80,
    0x07, 0xe0, 0x7e, 0x00, 0x03, 0xf0, 0xff, 0x80,
    0x03, 0xf5, 0xff, 0xe0, 0x07, 0xfd, 0xff, 0xf8,
    0x1f, 0xfc, 0xff, 0xe8, 0xff, 0xe3, 0xbf, 0x70,
    0xde, 0x80, 0xb7, 0x00, 0x71, 0x10, 0x4a, 0x80,
    0x03, 0x10, 0x4e, 0x40, 0x02, 0x88, 0x8c, 0x20,
    0x05, 0x05, 0x04, 0x40, 0x02, 0x82, 0x14, 0x40,
    0x02, 0x40, 0x10, 0x80, 0x02, 0x64, 0x1a, 0x80,
    0x00, 0x92, 0x29, 0x00, 0x00, 0xb0, 0x48, 0x00,
    0x00, 0xc8, 0x90, 0x00, 0x00, 0x85, 0x10, 0x00,
    0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00 
};

// Called to draw scene
void RenderScene(void)
{
    int x, y;
    glClear   ( GL_COLOR_BUFFER_BIT );
    glColor3f ( 1.0f, 1.0f, 1.0f );

    glRasterPos2f ( 0.4f, 0 );
    glBitmap ( 32, 32, 0.0, 0.0, 0, 0, fire );
    glRasterPos2f ( 0.8f, 0 );
    glBitmap ( 32, 32, 0.0, 0.0, 0, 0, fire );

    glutSwapBuffers();
}

void display() 
{
    glClear(GL_COLOR_BUFFER_BIT);
    RenderScene ();
    glFlush();
}

int main(int argc, char **argv) 
{
    glutInit(&argc, argv);
    glutInitWindowSize(512,512);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutCreateWindow("The glut hello world program");
    glutDisplayFunc(display);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glutMainLoop(); // Infinite event loop
    return 0;
}