Advertisement
Guest User

GL bitmap

a guest
Nov 22nd, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <GL/glut.h>
  4.  
  5.  
  6. #include "stdlib.h"
  7. #include "windows.h"
  8. #include "math.h"
  9.  
  10. BITMAPFILEHEADER bitmapFileHeader;
  11. BITMAPINFOHEADER bitmapInfoHeader;
  12. unsigned char* bitmap_Image;
  13.  
  14.  
  15. void ReadBitmap(const char* FileName)
  16. {
  17.  
  18.     FILE *file=fopen(FileName,"rb");
  19.  
  20.  
  21.         if (bitmapInfoHeader.biSizeImage != 0)
  22.             bitmap_Image = (unsigned char*)calloc(bitmapInfoHeader.biSizeImage, sizeof(unsigned char));
  23.  
  24.     if (!bitmap_Image)
  25.     {
  26.         free(bitmap_Image);
  27.         fclose(file);
  28.         return;
  29.     }
  30.    
  31.     fread(bitmap_Image, bitmapInfoHeader.biSizeImage,1, file);
  32.     int pixCnt = 0;
  33.     int inc = (4 - (int)fmod((double)bitmapInfoHeader.biWidth*3, 4)) ; //every line is formed by 32bits parts
  34.     if (inc == 4) inc = 0;
  35.     int rowEndIndex = bitmapInfoHeader.biWidth*3; //first row
  36.     for (int i = 0; i < (bitmapInfoHeader.biHeight); i++)
  37.     {
  38.         printf("new line\n");
  39.         for (int cnt=pixCnt; cnt < rowEndIndex; cnt+=3,pixCnt+=3)
  40.         {
  41.                 printf("/b - %d",bitmap_Image[cnt]);
  42.                 printf("/g - %d",bitmap_Image[cnt + 1]);
  43.                 printf("/r - %d\n",bitmap_Image[cnt + 2]);             
  44.         }
  45.         pixCnt+=inc;
  46.         rowEndIndex+=bitmapInfoHeader.biWidth*3 + inc;
  47.  
  48.     }
  49. }
  50.  
  51.  
  52. void renderScene(void) {
  53.  
  54.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  55.  
  56.     ReadBitmap(/* file path */);
  57.     glBitmap(838,837,0,0,0,0,bitmap_Image);
  58.  
  59.  
  60.         glutSwapBuffers();
  61. }
  62.  
  63. int main(int argc, char **argv) {
  64.  
  65.     // init GLUT and create Window
  66.     glutInit(&argc, argv);
  67.     glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  68.     glutInitWindowPosition(100,100);
  69.     glutInitWindowSize(320,320);
  70.     glutCreateWindow("Test");
  71.  
  72.     // register callbacks
  73.     glutDisplayFunc(renderScene);
  74.  
  75.     // enter GLUT event processing cycle
  76.     glutMainLoop();
  77.  
  78.     return 1;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement