Blending problems: Anything wrong with SDL/GL or with me?

Hi List!
Sorry for posting such a long code “fragment”, but I’m in real trouble with the SDL and OpenGL combination.
The demo below is ment to draw a multicolor background and blend a simple texture above it, but it doesn’t.
Event on OpenGL.org nobody seems to know an answer, so I try here, because it may be a misunderstanding
by me with the SDL/GL handling. The bug seems to concentrate around the texture creation, because blending
works by changing the alpha value of the quad’s color. Would be nice, if somebody could have a look at it.
Is there anything special with textures in the SDL framework? I’m working on that misbehavior for a week now,
without getting any further…

Thanks in advance,
Andreas Podgurski

#include <Windows.h>
#include <GL/gl.h>
#include <SDL.h>
#include <SDLToolkit.h>
#include “Sarakon.h”

SDL_Surface *g_srfcScreen;
GLuint glintTexture[1];

unsigned long Test[] = { 0x00000000,0xFF000000,0xFF000000,0xFF000000,0xFF000000,0xFFFF0000,0xFF00FF00,0xFF000000,
0x00000000,0xFF000022,0xFF000022,0xFF000022,0xFF000022,0xFFFF0022,0xFF00FF22,0xFF000022,
0x00000000,0xFF000022,0xFF000044,0xFF000044,0xFF000044,0xFFFF0044,0xFF00FF44,0xFF000044,
0x00000000,0xFF000022,0xFF000044,0xFF000066,0xFF000066,0xFFFF0066,0xFF00FF66,0xFF000066,
0x00000000,0xFF000022,0xFF000044,0xFF000066,0xFF000088,0xFFFF0088,0xFF00FF88,0xFF000088,
0x00000000,0xFF000022,0xFF000044,0xFF000066,0xFF000088,0xFFFF00AA,0xFF00FFAA,0xFF0000AA,
0x00000000,0xFF000022,0xFF000044,0xFF000066,0xFF000088,0xFFFF00AA,0xFF00FFCC,0xFF0000CC,
0x00000000,0xFF000022,0xFF000044,0xFF000066,0xFF000088,0xFFFF00AA,0xFF00FFCC,0xFF0000FF,
};

int main(int argc,char *argv[])
{
SDL_Event sdlEvent;
Uint32 nStart;

SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
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_DEPTH_SIZE,32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
g_srfcScreen=SDL_SetVideoMode(640,480,32,SDL_OPENGL/*|SDL_FULLSCREEN*/);

glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glShadeModel(GL_SMOOTH);
glClearColor(0,0,0,0);
glClearDepth(1.0f);
glViewport(0,0,640,480);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glGenTextures(1,&glintTexture[0]);
glBindTexture(GL_TEXTURE_2D,glintTexture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

glBindTexture(GL_TEXTURE_2D,glintTexture[0]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,8,8,0,GL_RGBA,GL_UNSIGNED_BYTE,Test);

glDisable(GL_BLEND);

nStart=SDL_GetTicks();
while((SDL_GetTicks()-nStart)<5000)
{
	SDL_PumpEvents();
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,1,1,0,-1,1);

	glMatrixMode(GL_MODELVIEW);

	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_QUADS);
		glColor4f(0,0,0,1);	glVertex3f(0,0,0.4);
		glColor4f(1,0,0,1);	glVertex3f(1,0,0.4);
		glColor4f(0,1,0,1);	glVertex3f(1,1,0.4);
		glColor4f(0,0,1,1);	glVertex3f(0,1,0.4);
	glEnd();

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D,glintTexture[0]);
	glColor4f(1,1,1,1);
	glBegin(GL_QUADS);
		glTexCoord2f(0,0);	glVertex3f(0.4,0.4,0.5);
		glTexCoord2f(1,0);	glVertex3f(0.6,0.4,0.5);
		glTexCoord2f(1,1);	glVertex3f(0.6,0.6,0.5);
		glTexCoord2f(0,1);	glVertex3f(0.4,0.6,0.5);
	glEnd();

	SDL_GL_SwapBuffers();
	SDL_Delay(1);
}

SDL_Quit();

return (0);

}

ok, i finally understand your problem.
your program behave correctly it is the blending function you should
misunderstood…

try to replace
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
by
glBlendFunc(GL_SRC_ALPHA,GL_ONE);

and this should behave better… (i mean more as you want, i guess)