紋理-1維
綁定1維紋理
void LoadAllTextures(void)
{
static unsigned char roygbiv_image[8][3] =
{
{ 0x3f, 0x00, 0x3f }, /* Dark Violet (for 8 colors…) */
{ 0x7f, 0x00, 0x7f }, /* Violet */
{ 0xbf, 0x00, 0xbf }, /* Indigo */
{ 0x00, 0x00, 0xff }, /* Blue */
{ 0x00, 0xff, 0x00 }, /* Green */
{ 0xff, 0xff, 0x00 }, /* Yellow */
{ 0xff, 0x7f, 0x00 }, /* Orange */
{ 0xff, 0x00, 0x00 } /* Red */
};
glNewList(RainbowTexture = glGenLists(1), GL_COMPILE);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D, 0, 3, 8, 0, GL_RGB, GL_UNSIGNED_BYTE,roygbiv_image);
glEndList();
}
使能1維紋理
glEnable(GL_TEXTURE_1D);
glCallList(RainbowTexture);
繪圖指定頂點座標和紋理座標
glBegin(GL_QUAD_STRIP);
float th, x, y, z;
for (th = 0.0; th <= my