Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Dynamic palette

This topic is 4256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to find a way to render a full screen quad with a large texture and have the pixels go through a simple transformation. The variables used for the transformation are changed dynamically, so we need to reapply the transformation everytime they are changed. I know of a few ways to do it: 1) Apply the transformation to the texture. This is what we do right now, but the texture is pretty big. It takes about 50ms and after that we still have to delete the old texture and send the new one to the graphics card. 2) Use a pixel shader. Can't do it... It has to run on graphics cards that are pretty old. No extensions can be used. 3) Use a pixel map. The idea is the same as what we would use with the pixel shader. Instead of updating the large texture, we change the palette (color look up table) and then render using this palette. http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/pixelmap.html Setting a pixel map only affects a few functions (glCopyPixels, glCopyTexImage1D, glCopyTexImage2D,glCopyTexSubImage1D, glCopyTexSubImage2D, glDrawPixels,glReadPixels, glTexImage1D, glTexImage2D, glTexSubImage1D,and glTexSubImage2D). Regular rendering (glBegin, glVertex, glEnd) is not affected. We tried this, but it is very slow (the slow down is caused by enabling glPixelTransfer).

// palette is updated dynamically

// set the color map
glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 256, palette);
glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 256, palette);
glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 256, palette);

// disable it for the first pass (drawing to BACK_LEFT)
glPixelTransferi(GL_MAP_COLOR, GL_FALSE);

// draw a full screen quad with our texture

glTexCoord2f(tx1, ty1);
glVertex3f(-1.0f, -1.0f, 0.0f);

glTexCoord2f(tx2, ty1);
glVertex3f(1.0f, -1.0f, 0.0f);

glTexCoord2f(tx2, ty2);
glVertex3f(1.0f, 1.0f, 0.0f);

glTexCoord2f(tx1, ty2);
glVertex3f(-1.0f, 1.0f, 0.0f);


// copy from BACK_LEFT to BACK using the pixel map
// (if you comment this line, it runs pretty fast... doesn't do what we want though :P)
glPixelTransferi(GL_MAP_COLOR, GL_TRUE);

glCopyPixels(0,0,getWidth(), getHeight(), GL_COLOR);

glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
We also tried glDrawPixels() instead of two passes but it is even slower. Does anyone know why this is so slow or different ways to do it (can't be slower than looping through the whole texture, no extensions)?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!