| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1096 人关注过本帖
标题:OpenGL纹理压缩问题
只看楼主 加入收藏
whucv
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-30
收藏
 问题点数:0 回复次数:0 
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)
搜索更多相关主题的帖子: 附件 图片 解决方案 include 
2012-03-30 18:06
快速回复:OpenGL纹理压缩问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016977 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved