+ // Let us create the texture information :
+ sdlemu_create_texture(src, dst, filter, src_bpp);
+ sdlemu_create_overlay(dst, src_bpp);
+}
+
+void sdlemu_draw_texture(SDL_Surface * dst, SDL_Surface * src, int texturetype)
+{
+/*
+ This is needed when we want to render OpenGL textures with the Alpha mask set.
+ Be warned! This only works with the bpp of texture en *src set to 32.
+*/
+#ifdef WANT_OPENGL_ALPHA
+ Uint32 saved_flags;
+ Uint8 saved_alpha;
+
+ /* Save the alpha blending attributes */
+ saved_flags = src->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+ saved_alpha = src->format->alpha;
+ if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+ SDL_SetAlpha(src, 0, 0);
+ }
+
+ // Blit the src display to the texture.
+ SDL_BlitSurface(src, NULL, texture, NULL);
+
+ /* Restore the alpha blending attributes */
+ if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+ SDL_SetAlpha(src, saved_flags, saved_alpha);
+ }
+#else
+ SDL_BlitSurface(src, NULL, texture, NULL);
+#endif
+// SDL_BlitSurface(src, NULL, overlay, NULL);
+/*Uint32 * pix = (Uint32 *)overlay->pixels;
+Uint32 y,x;
+for(y=10; y<200; y++)
+for(x=30; x<250; x++)
+pix[x+(y*1024)] = 0x800000FF;//*/
+
+glBlendFunc(GL_ONE, GL_ZERO);
+glBindTexture(GL_TEXTURE_2D, texid);
+ // Texturemap complete texture to surface so we have free scaling
+ // and antialiasing
+ switch (texturebpp)
+ {
+ case 16:
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->w, texture->h,
+ GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texture->pixels);
+ break;
+ case 24:
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->w, texture->h,
+ GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);
+ break;
+ case 32:
+ default:
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->w, texture->h,
+ GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels);
+ break;
+ }
+
+ // Render the texture to the screen using OpenGL!
+ switch (texturetype)
+ {
+ case 1:
+ glBegin(GL_QUADS);
+ glTexCoord2f(texcoord[0], texcoord[1]);
+ glVertex2f(0, 0);
+ glTexCoord2f(texcoord[2], texcoord[1]);
+ glVertex2f(dst->w, 0);
+ glTexCoord2f(texcoord[2], texcoord[3]);
+ glVertex2f(dst->w, dst->h);
+ glTexCoord2f(texcoord[0], texcoord[3]);
+ glVertex2f(0, dst->h);
+ glEnd();
+
+ default:
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2f(texcoord[0], texcoord[1]); glVertex3i(0, 0, 0);
+ glTexCoord2f(texcoord[2], texcoord[1]); glVertex3i(dst->w, 0, 0);
+ glTexCoord2f(texcoord[0], texcoord[3]); glVertex3i(0, dst->h, 0);
+ glTexCoord2f(texcoord[2], texcoord[3]); glVertex3i(dst->w, dst->h, 0);
+ glEnd();
+ }//*/
+
+ if (showOverlay)
+ {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBindTexture(GL_TEXTURE_2D, overlayID);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, overlay->w, overlay->h, GL_RGBA, GL_UNSIGNED_BYTE, overlay->pixels);
+ glBegin(GL_QUADS);
+ glTexCoord2f(overlayCoord[0], overlayCoord[1]);
+ glVertex2f(0, 0);
+ glTexCoord2f(overlayCoord[2], overlayCoord[1]);
+ glVertex2f(dst->w, 0);
+ glTexCoord2f(overlayCoord[2], overlayCoord[3]);
+ glVertex2f(dst->w, dst->h);
+ glTexCoord2f(overlayCoord[0], overlayCoord[3]);
+ glVertex2f(0, dst->h);
+ glEnd();
+ }
+
+//Do some OpenGL stuff here...
+//Doesn't work...
+/*unsigned long int map[25] = {
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
+};
+glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+glRasterPos2i(10, 10);
+glDrawPixels(5, 5, GL_RGBA, GL_UNSIGNED_INT, map);//*/
+
+// glFlush();
+ SDL_GL_SwapBuffers();
+// glFinish();
+}
+
+void sdlemu_close_opengl(void)
+{
+ if (texture)
+ SDL_FreeSurface(texture);
+
+ if (overlay)
+ SDL_FreeSurface(overlay);
+}
+
+void sdlemu_create_texture(SDL_Surface * src, SDL_Surface * dst, int filter, int src_bpp)
+{
+ // Local variables.
+ int w , h; // w and h contain the width and height of the OpenGL texture.
+ Uint32 rmask, gmask, bmask, amask; // Needed for creating RGBA masks.
+ int bpp;
+
+ // Delete old texture (if allocated). Useful when there is a screen resize.
+ if (texture)
+ SDL_FreeSurface(texture);
+
+ // Texture width/height should be power of 2 of the SDL_Surface *src when using OpenGL.