I was trying to create a OpenGL version of an old plasma 8bit effect animation in DOS but I am stuck. Since almost every OpenGL program has included something to generate a palette for Win32 I thought it would not be that hard to apply palette animation on my old program.
My purpose is to generate a texture with color indices that does not change and a palette that is rotating. After digging into the web this weekend I am still not able to fix it. I cannot even display a texture with one color index so in that stage something is wrong (if it would work I can create the palette cycling mechanism).
I can force into palette mode by using PFD_TYPE_COLORINDEX and draw some random pixels using glIndexi. I read that glDrawPixels and glReadPixels are slow and the latter is not that accurate when getting pixels back from the framebuffer (due to inaccurate positioning as a result from rounding errors or something).
I tried the GL_COLOR_INDEX keyword. I also tried: glPixelTransferi(GL_MAP_COLOR, true); glPixelMapfv( GL_PIXEL_MAP_I_TO_R, ...); glTexImage2D... Some of the code I tried so far (latest changes):
init part:
void* rawplasma;
GLuint plastexture;
rawplasma = (void*) malloc(256*256);
memset(rawplasma,rand()%256,256*156);
glEnable( GL_TEXTURE_2D );
glGenTextures(1, plastexture);
glBindTexture(GL_TEXTURE_2D, plastexture);
glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, rawplasma );
update/draw:
float Rmap[256];
float Gmap[256];
float Bmap[256];
float Amap[256];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
memset(rawplasma,rand()%256,256*256); //check if it works
glTexImage2D( GL_TEXTURE_2D, 0, GL_COLOR_INDEX, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, rawplasma );
glBindTexture(GL_TEXTURE_2D, plastexture );
/*
glPixelTransferi( GL_MAP_COLOR, GL_TRUE );
glPixelMapfv(GL_PIXEL_MAP_I_TO_R,mapSize,Rmap);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G,mapSize,Gmap);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B,mapSize,Bmap);
glPixelMapfv(GL_PIXEL_MAP_I_TO_A,mapSize,Amap);
glPixelTransferi(GL_MAP_COLOR,GL_TRUE);
*/
glBegin(GL_QUADS);
glTexCoord2f(1.0, 0.0); glVertex2f(-1.0, -1.0);
glTexCoord2f(0.0, 0.0); glVertex2f( 1.0, -1.0);
glTexCoord2f(0.0, 1.0); glVertex2f( 1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex2f(-1.0, 1.0);
glEnd();
glFlush();
SwapBuffers(hDC);
Or should I use glColorTableEXT in combination with GL_COLOR_INDEX8_EXT? I read somewhere that textured palettes are not supported? I found a link which mentions Paletted Texture Extension: http://www.cs.rit.edu/~ncs/Courses/570/UserGuide/OpenGLonWin-20.html
This is what I want (but then in OpenGL):
http://www.codeforge.com/read/174459/PalAnimDemo.h__html
I am not looking for ES/Shader implementations (I am just a beginner ;)) and DirectDraw might be easier I think but I want to try OpenGL.