开发者

Gradients and memory

I'm creating a drawing application with OpenGL. I'v created an algorithm that generates gradient textures. I then map these to my polygons and this works quite well. What I realized is how much memory this requires. Creating 1000 gradients takes about 800MB and that's way t开发者_StackOverflowoo much. Is there an alternative to textures, or a way to compress them, or another way to map gradients to polygons that doesn't use up as much memory?

Thanks

My polygons are concave, I use GLUTesselator, and they are multicolored and point to point


Yes... gradients are super easy to do in OpenGL; you don't need textures at all. Working from memory here... you'd just do something like this:

glBegin(GL_POLYGON);
glColor3ub(255,0,0); // red
glVertex2f(-1,-1);
glVertex2f(1,-1);
glColor3ub(0,0,255); // blue
glVertex2f(1,1);
glVertex2f(-1,1);
glEnd();
// draws a square that fades from red to blue

If you change the color of a vertex, it just creates a gradient between those two points.


You can also try generating gradients procedurally inside a fragment shader.

If you go via the texture compression path, you can use glCompressedTexImage2D, compressed texture formats are provided via GL extensions, a common one is S3TC/DXT1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜