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.

4

1 回答 1

2

因为几乎每个 OpenGL 程序都包含一些东西来为 Win32 生成调色板

不,绝对不是。如果您指的是 PIXELFORMATDESCRIPTOR,不是调色板定义。颜色索引模式是在 OpenGL 中使用的主要 PITA,目前没有任何实现真正支持它。

我不是在寻找 ES/Shader 实现(我只是一个初学者;))

但这正是您应该使用的。在现代 OpenGL 中,着色器也是强制性的。一个简单的片段着色器,它执行对一维纹理的查找,将索引转换为颜色,这正是您所需要的。如果你的目标是现代系统,那么无论如何你都必须使用着色器。

于 2012-11-04T20:29:21.127 回答