游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2561|回复: 3

关于opengl里面bmp装载怎么做,谢谢,大师指点!!!急用

[复制链接]

2

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2003-11-1 11:04:00 | 显示全部楼层 |阅读模式
我现在做好了40*40的九个高的bitmap,现在怎样把它装载到mush上,谢谢,用glBegin(TRIANGLE_STRIP)之前应该怎么载入bitmaip,帮帮忙吧!!!

[em24]

6

主题

100

帖子

105

积分

注册会员

Rank: 2

积分
105
发表于 2003-11-1 12:59:00 | 显示全部楼层

Re: 关于opengl里面bmp装载怎么做,谢谢,大师指点!!!

bool CTexture:oadBMP(char *Filename)                                                                        // Load Bitmaps And Convert To Textures
{
        AUX_RGBImageRec *pImage = NULL;
        FILE *pFile = NULL;

        if(!Filename)
                return false;

        // Open a file pointer to the BMP file and check if it was found and opened
        if((pFile = fopen(Filename, "rb")) == NULL)
        {
                // Display an error message saying the file was not found, then return NULL
                char buf[255];
                sprintf(buf,"Unable to load BMP File:%s",Filename);
                MessageBox(NULL, buf, "Error", MB_OK);
                ExitProcess(0);
                return false;
        }
        // Load the bitmap using the aux function stored in glaux.lib
        pImage = auxDIBImageLoad(Filename);                               

        // Make sure valid image data was given to pImage, otherwise return false
        if(pImage == NULL)                                                               
                return false;

        // Generate a texture with the associative texture ID stored in the array
        glGenTextures(1, &m_nTxt);

        // This sets the alignment requirements for the start of each pixel row in memory.
//        glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

        // Bind the texture to the texture arrays index and init the texture
        glBindTexture(GL_TEXTURE_2D, m_nTxt);
       
        // Build Mipmaps (builds different versions of the picture for distances - looks better)
        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX,
                                          pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);

        //Assign the mip map levels and texture info
//        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        // Now we need to free the image data that we loaded since openGL stored it as a texture

        if (pImage)                                                                                // If we loaded the image
        {
                if (pImage->data)                                                        // If there is texture data
                {
                        free(pImage->data);                                                // Free the texture data, we don't need it anymore
                //        delete []pImage->data;
                }
        //        delete pImage;
                free(pImage);                                                                // Free the image structure
        }
        return true;
}

6

主题

100

帖子

105

积分

注册会员

Rank: 2

积分
105
发表于 2003-11-1 13:02:00 | 显示全部楼层

Re: 关于opengl里面bmp装载怎么做,谢谢,大师指点!!!

sample:
glEnable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255);
glBindTexture(GL_TEXTURE_2D,TextureID );
glBegin(GL_TRIANGLES);
.....
.....

2

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2003-11-3 04:27:00 | 显示全部楼层

Re:关于opengl里面bmp装载怎么做,谢谢,大师指点!!!急

谢谢,但不是这样做的,我说得bmp是,r,g,b高转过来的,用GetPixel()
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-2-23 23:28

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表