OpenGL纹理压缩问题
VC6.0下 256*256图片纹理, glGetCompressedTexImageARB(GL_TEXTURE_2D, 0, img);错误,求解决方案?程序在附件中。// Texturetest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "gl/glew.h"
#include "gl/glaux.h"
#include "gl/glut.h"
#include "stdio.h"
GLuint decal_map = 0;
GLuint compressed_decal_map = 1;
GLuint already_compressed_decal_map = 2;
AUX_RGBImageRec *LoadBMP(char* Filename)
{
FILE *File=NULL;
if (!Filename)
{
return NULL;
}
File=fopen(Filename,"r");
if (File)
{
return auxDIBImageLoad(Filename);
}
return NULL;
}
void loadTextureAndCompress(void)
{
int status=FALSE;
AUX_RGBImageRec * image;
memset(&decal_map,0,sizeof(void*)*1);
int compressed;
int internalformat;
int compressed_size;
int num_compressed_format;
int * compressed_format = NULL;
unsigned char * img = NULL;
/* Assume tightly packed textures. */
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
/* 原始纹理 original*/
glBindTexture(GL_TEXTURE_2D, decal_map);
image = LoadBMP("world.bmp"); /* "world.bmp" */
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,image->sizeX, image->sizeY,GL_RGB, GL_UNSIGNED_BYTE, image->data);
/* GL压缩图像到指定压缩格式 */
glBindTexture(GL_TEXTURE_2D, compressed_decal_map);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_ARB, //压缩
image->sizeX, image->sizeY,0,GL_BGR_EXT, GL_UNSIGNED_BYTE, image->data);
/* 检查图像是否被GL成功压缩GL_TEXTURE_COMPRESSED_ARB*/
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &compressed);
/*if the compression has been successful 如果成功压缩*/
if (compressed==GL_TRUE)
{
/* 查询压缩图像的内部格式 */
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalformat);
/* 查询压缩数据纹理缓冲区大小 */
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &compressed_size);
//保存压缩文理的相关信息
glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &num_compressed_format);
compressed_format = (GLint*)malloc(num_compressed_format * sizeof(GLint));
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS_ARB, compressed_format);
img = (unsigned char *)malloc(compressed_size * sizeof(unsigned char));
/* 得到压缩纹理数据 */
glGetCompressedTexImageARB(GL_TEXTURE_2D, 0, img);
glBindTexture(GL_TEXTURE_2D, already_compressed_decal_map);
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, internalformat, image->sizeX, image->sizeY, 0, compressed_size, img);
}
free(image->data);
free(image);
free(compressed_format);
free(img);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//LoadGLTexture();
loadTextureAndCompress();
glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2D,Texture[0]);
// glBindTexture(GL_TEXTURE_2D,decal_map);
glBindTexture(GL_TEXTURE_2D,already_compressed_decal_map);
glBegin(GL_QUADS);
GLUquadric* quadricObj=gluNewQuadric();
gluQuadricTexture(quadricObj,GL_TRUE);
gluSphere(quadricObj,1,50,50);
gluDeleteQuadric(quadricObj);
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutCreateWindow("Boy");
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}
CompressTexture.rar
(1.15 MB)