進出口試圖創建使用此訥河Loadraw加載圖像的多邊形和繪製使用紋理大小
GLuint LoadTextureRAW(const char * filename, int wrap)
{
GLuint texture;
int width, height;
Byte * data;
FILE * file;
// open texture data
file = fopen("Data/raw.raw", "rb");
if (file == NULL) return 0;
// allocate buffer
width = 256;
height = 256;
data = malloc(width * height * 3);
// read texture data
fread(data, width * height * 3, 1, file);
fclose(file);
// allocate a texture name
glGenTextures(1, &texture);
// select our current texture
glBindTexture(GL_TEXTURE_2D, texture);
// select modulate to mix texture with color for shading
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// when texture area is small, bilinear filter the closest MIP map
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST);
// when texture area is large, bilinear filter the first MIP map
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// if wrap is true, the texture wraps over at the edges (repeat)
// ... false, the texture ends at the edges (clamp)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
wrap ? GL_REPEAT : GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
wrap ? GL_REPEAT : GL_CLAMP);
// build our texture MIP maps
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width,
height, GL_RGB, GL_UNSIGNED_BYTE, data);
// free buffer
free(data);
return texture;
}
在OpenGL紋理的多邊形,然後創建多邊形 紋理= LoadTextureRAW(「 texture.raw「,TRUE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBegin(GL_POLYGON);
glVertex3f(-42.0f, -42.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f( 42.0f, -42.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 42.0f, 42.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-42.0f, 42.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glEnd();
我能怎樣改變圖像的任何規模大小加載不僅2的冪和創建使用紋理的一側,而不是
哇,非常感謝你,這幫助我很多我在錯誤的方式爲我需要什麼 – 2012-04-15 01:40:12