I am using openGL and C to load a sprite as a ppm file, I use Gimp to turn a png into a ppm and then I turn it into an array and add commas it to make it readable in C. In the ppm file format there is the red green and blue values of each pixel separated by a comma and the array name is at the start. The only problem is when I load the file and try to see it in openGL it does not work and just leaves me with a blanc screen.
.ppm file format:
int Wall[]={
184,
184,
184,
etc
};
Code:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#ifdef __unix__
# include <unistd.h>
#elif defined _WIN32
# include <windows.h>
#define sleep(x) Sleep(1000 * (x))
#endif
#define or ||
#define and &&
#define pCharacter "%c \n"
#define pInteger "%d \n"
#define pFloat "%f \n"
#define pDouble "%lf \n"
#define pUnsighned "%u \n"
#define pString "%s \n"
#include <C:/Users/cuerv/Downloads/C/First/Sprites/wall.ppm>
int width=1000; //Screen width
int height=500; //Screen height
void drawSprites(){
int x;
int y;
for(y=0;y<33;y++){//The image is 33*33
for(x=0;y<33;x++){//The image is 33*33
int pixel=(y*33+x)*3;//Use the *3 because there are three RGB vals per pixel
int red=Wall[pixel+0];
int green=Wall[pixel+1];
int blue=Wall[pixel+2];
glPointSize(8);
glBegin(GL_POINTS);
glColor3ub(red, green, blue);
glVertex2i(x+8,y+8);
glEnd();
}
}
}
void init(){
glClearColor(0.3,0.3,0.3,0);
gluOrtho2D(0,width,height,0);
}
void userDisplay(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//-----------------------Draw----------------------
drawSprites();
glutSwapBuffers();
glutPostRedisplay();
}
void main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(width,height);
glutCreateWindow("OpenGL");
init();
glutDisplayFunc(userDisplay);
glutMainLoop();
}