Hello all! I am new to OpenGL and I’m having a small problem that I can’t seem to find the answer to. I can actually live with it if there is no fix but it would be nice to have it display correctly. I hope it it something simple that I’m doing wrong. I’m using SDL with OpenGL and am writing a 2d tile engine. My init code is:
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_WM_SetCaption("build1", NULL);
SDL_SetVideoMode(winwidth,winheight,32, SDL_OPENGL);
glViewport(0,0,winwidth,winheight);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_MODELVIEW);
glEnable (GL_BLEND); //enable blending
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
My sight area function is working correctly, but I can’t seem to get the shading worked out. Use the picture below for reference.
(unable to post an image “Post denied. New posts are limited by number of URLs it may contain and checked if it doesn’t contain forbidden words.”) image at: draksplace dot com/openglimage.png
The blue squares are actually textures, (I just made blue images instead of the actual image to make it easier to see). They would be considered a wall. The black areas are either the floor, (which I turned off for now) or areas that can not be seen. The green and red dots are the corners of each quad. Each dot is accessed by four different quads and carries the rgba value for that corner of the quad. The quads are drawn using this similar code:
1: glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mytexture);
glBegin(GL_QUADS);
2: glColor4ub(dot[loc].cr , dot[loc].cg , dot[loc].cb , dot[loc].ca);
glTexCoord2d(my atlas lookup equation x,y);
glVertex2f(clockwise position of the quad cords from dot[].x, dot[].y);
glColor4ub(dot[loc].cr , dot[loc].cg , dot[loc].cb , dot[loc].ca);
glTexCoord2d(my atlas lookup equation x,y);
glVertex2f(clockwise position of the quad cords from dot[].x+ts, dot[].y);
glColor4ub(dot[loc].cr , dot[loc].cg , dot[loc].cb , dot[loc].ca);
glTexCoord2d(my atlas lookup equation x,y);
glVertex2f(clockwise position of the quad cords from dot[].x+ts, dot[].y+ts);
glColor4ub(dot[loc].cr , dot[loc].cg , dot[loc].cb , dot[loc].ca);
glTexCoord2d(my atlas lookup equation x,y);
glVertex2f(clockwise position of the quad cords from dot[].x, dot[].y+ts);
3: glEnd();
do 1
then repeat 2 for all quads on the screen
then 3
The green dots have an rgba value of 255,255,255,255. The red dots have a rgba value of 0,0,0,255. My problem is what I have circled in yellow. The shading is different. It looks like everything is shading diagonally. I made the engine generate the dots to tell me the rgba value of the dots for debugging. I’ve checked my code over and over and I am at a loss. Does anyone have any ideas of what is going on? OpenGL is drawing the lighting correctly because at every green dot that corner of the tile is bright. Where as every red dot that corner of the tile is dark. But the shading looks weird.
I would appreciate any help, thanks in advance!