0

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.

Mat90
  • 169
  • 1
  • 9
  • 2
    "*Since almost every OpenGL program has included something to generate a palette for Win32*" It has? Since when? And being a beginner is no excuse for not using shaders. – Nicol Bolas Nov 04 '12 at 19:56

1 Answers1

2

Since almost every OpenGL program has included something to generate a palette for Win32

No, definitely not. If you mean the PIXELFORMATDESCRIPTOR, that is not a palette definition. Color index mode was a major PITA to work with in OpenGL, and no current implementation actually support it.

I am not looking for ES/Shader implementations (I am just a beginner ;))

But that's exactly what you should use. Also shaders are mandatory in modern OpenGL. A simple fragment shader, that performs a lookup into a 1D texture turning an index into a color is exactly what you need. And if you aim for modern systems, you'll have to use a shader anyway.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • [Here](http://python-opengl-examples.blogspot.co.uk/2009/07/fire-preview-stage.html) is an example of a shader implementation. – StuGrey Nov 04 '12 at 20:42
  • I meant the PFD_NEED_PALETTE and PFD_TYPE_COLORINDEX in the PIXELFORMATDESCRIPTOR structure for the palette definition (the latter for setting/forcing it, the former when it requires a palette). – Mat90 Nov 26 '12 at 20:52
  • @Mat90: Indexed color mode has not been supported by any OpenGL implementation since 1998 or so. You'll only get a software rasterizer fallback OpenGL-1.1 context, if any at all with that. *Just. Don't. Use. It!* – datenwolf Nov 26 '12 at 21:41