Hi guys,
I am having trouble showing anything on the screen. Can someone try to copy this and try to run in and see what you can get. I am using Dev-C Bloodsheed and trying simply to read tif image and then show it on the screen. I have image in same directory as my program.
Even when i delete the image from directory i cant even get error message to the screen (printf(“Error”);
Can anyone help me with this
#include <stdlib.h>
#include <GL/gl.h>
#include <stdio.h>
#include <GL/glut.h>
#include <malloc.h>
#include <FreeImage.h>
typedef struct {
GLubyte r, g, b;
} pixel;
//the global structure
typedef struct {
pixel *data;
int w, h;
} glob;
glob global;
pixel *read_img(char *name, int *width, int *height) {
FIBITMAP *image;
int i,j,pnum;
RGBQUAD aPixel;
pixel *data;
if((image = FreeImage_Load(FIF_TIFF, name, 0)) == NULL) {
return NULL;
}
*width = FreeImage_GetWidth(image);
*height = FreeImage_GetHeight(image);
data = (pixel *)malloc((*height)*(*width)*sizeof(pixel *));
pnum=0;
for(i = 0 ; i < (*height) ; i++) {
for(j = 0 ; j < (*width) ; j++) {
FreeImage_GetPixelColor(image, j, i, &aPixel);
data[pnum].r = (aPixel.rgbRed);
data[pnum].g = (aPixel.rgbGreen);
data[pnum++].b = (aPixel.rgbBlue);
}
}
FreeImage_Unload(image);
return data;
}//read_img
int main(int argc,char** argv){
global.data = read_img("img.tif", &global.w, &global.h);
if (global.data == NULL){
printf("Error");
return 1;
}
glutInit(&argc,argv);
glutCreateWindow("Simple Display");
glutMainLoop();
}