OpenGL的 - 动画/循环/旋转调色板 [英] OpenGL - Animate/cycle/rotate palette

查看:227
本文介绍了OpenGL的 - 动画/循环/旋转调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建在DOS下的老血浆的8bit效果动画的OpenGL的版本,但我坚持。因为几乎每一个OpenGL的计划包括的东西产生的调色板为Win32我认为这不会是很难在我的旧应用程序调色板动画。

我的目的是产生具有色指数纹理不会改变,并且被旋转一个调色板。挖掘到网络这个周末之后,我仍无法修复它。所以在这个阶段什么是错的我甚至无法显示一个颜色索引纹理(如果它会工作,我可以创建一个调色板循环机制)。

我可以用PFD_TYPE_COLORINDEX强行进入调色板模式,并借鉴使用glIndexi一些随机像素。我读了glDrawPixels和glReadPixels很慢,从帧缓冲区获取像素背时(由于定位不准确从舍入误差或某事的结果),后者是不准确的。

我试过GL_COLOR_INDEX关键字。我也尝试:
glPixelTransferi(GL_MAP_COLOR,真);
glPixelMapfv(GL_PIXEL_MAP_I_TO_R,...);
glTexImage2D ...有些code我试过到目前为止(最新变化):

初​​始化部分:

 无效* rawplasma;
GLuint plastexture;rawplasma =(无效*)malloc的(256 * 256);
 memset的(rawplasma,兰特()%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);

更新/抽奖:

 浮动RMAP [256];
浮GMAP [256];
浮BMAP [256];
浮阿马帕[256];glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
memset的(rawplasma,兰特()%256,256 * 256); //检查是否正常工作
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);

或者我应该结合使用glColorTableEXT与GL_COLOR_INDEX8_EXT?我读的地方,纹理调色板不支持?我发现其中提到调色板纹理扩展的链接: HTTP: //www.cs.rit.edu/~ncs/Courses/570/UserGuide/OpenGLonWin-20.html

这是我想要的(但在OpenGL):

HTTP://www.$c$cforge.com/read/ 174459 / PalAnimDemo.h__html

我不是在寻找ES /着色器实现(我只是一个初学者;))和DirectDraw可能更容易我想,但我想尝试的OpenGL


解决方案

  

因为几乎每一个OpenGL的计划包括的东西产生为Win32调色板


没有,绝对不是。如果你指的是PIXELFORMATDESCRIPTOR,的的不是一个调色板定义。颜色索引模式是一个重大的PITA与OpenGL中工作,并且当前没有实现实际上支持它。


  

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


不过,这正是你应该使用什么。此外着色器的强制的现代的OpenGL。一个简单的片段着色器,执行查找到一维纹理转弯索引到一个颜色正是你需要的。如果你的目标是为现代系统,你无论如何都要使用着色器。

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.

解决方案

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.

这篇关于OpenGL的 - 动画/循环/旋转调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆