1. <tfoot id='G6aqv'></tfoot>

          <bdo id='G6aqv'></bdo><ul id='G6aqv'></ul>
        <i id='G6aqv'><tr id='G6aqv'><dt id='G6aqv'><q id='G6aqv'><span id='G6aqv'><b id='G6aqv'><form id='G6aqv'><ins id='G6aqv'></ins><ul id='G6aqv'></ul><sub id='G6aqv'></sub></form><legend id='G6aqv'></legend><bdo id='G6aqv'><pre id='G6aqv'><center id='G6aqv'></center></pre></bdo></b><th id='G6aqv'></th></span></q></dt></tr></i><div id='G6aqv'><tfoot id='G6aqv'></tfoot><dl id='G6aqv'><fieldset id='G6aqv'></fieldset></dl></div>

      1. <legend id='G6aqv'><style id='G6aqv'><dir id='G6aqv'><q id='G6aqv'></q></dir></style></legend>

        <small id='G6aqv'></small><noframes id='G6aqv'>

        如何在 GLUT 上加载 bmp 以将其用作纹理?

        时间:2023-09-18
          • <bdo id='FqMah'></bdo><ul id='FqMah'></ul>

            1. <small id='FqMah'></small><noframes id='FqMah'>

              <legend id='FqMah'><style id='FqMah'><dir id='FqMah'><q id='FqMah'></q></dir></style></legend>
              • <tfoot id='FqMah'></tfoot>
                <i id='FqMah'><tr id='FqMah'><dt id='FqMah'><q id='FqMah'><span id='FqMah'><b id='FqMah'><form id='FqMah'><ins id='FqMah'></ins><ul id='FqMah'></ul><sub id='FqMah'></sub></form><legend id='FqMah'></legend><bdo id='FqMah'><pre id='FqMah'><center id='FqMah'></center></pre></bdo></b><th id='FqMah'></th></span></q></dt></tr></i><div id='FqMah'><tfoot id='FqMah'></tfoot><dl id='FqMah'><fieldset id='FqMah'></fieldset></dl></div>

                    <tbody id='FqMah'></tbody>
                1. 本文介绍了如何在 GLUT 上加载 bmp 以将其用作纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我一直在四处寻找一个简单的解决方案,以在 C++ 中为我的 OpenGl GLUT 简单月球着陆器游戏添加精灵,看来我必须使用 bmp,因为它们最容易加载并用作矩形上的纹理.

                  I've been searching all around for a simple solution to add sprites to my OpenGl GLUT simple moon lander game in c++ and it appears I must use bmp's since they're easiest to load and use them as textures on a rectangle.

                  我究竟如何将 bmp 加载为纹理?

                  How exactly can I load the bmp's as textures though?

                  推荐答案

                  看我简单的c实现函数加载纹理.

                  Look my simple c implementation function to load texture.

                  GLuint LoadTexture( const char * filename )
                  {
                    GLuint texture;
                    int width, height;
                    unsigned char * data;
                  
                    FILE * file;
                    file = fopen( filename, "rb" );
                  
                    if ( file == NULL ) return 0;
                    width = 1024;
                    height = 512;
                    data = (unsigned char *)malloc( width * height * 3 );
                    //int size = fseek(file,);
                    fread( data, width * height * 3, 1, file );
                    fclose( file );
                  
                    for(int i = 0; i < width * height ; ++i)
                    {
                      int index = i*3;
                      unsigned char B,R;
                      B = data[index];
                      R = data[index+2];
                  
                      data[index] = R;
                      data[index+2] = B;
                    }
                  
                    glGenTextures( 1, &texture );
                    glBindTexture( GL_TEXTURE_2D, texture );
                    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE );
                    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST );
                  
                    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );
                    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT );
                    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT );
                    gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,GL_RGB, GL_UNSIGNED_BYTE, data );
                    free( data );
                  
                    return texture;
                  }
                  

                  以上函数返回纹理数据.将纹理数据存储在变量中

                  Above function returns the texture data. Store the texture data in variable

                  GLuint texture;
                  texture= LoadTexture( "your_image_name.bmp" );
                  

                  现在您可以使用 glBindTexture 绑定纹理

                  Now you can bind the texture using glBindTexture

                  glBindTexture (GL_TEXTURE_2D, texture);
                  

                  这篇关于如何在 GLUT 上加载 bmp 以将其用作纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 glut 和 std::string 时 main() 之前的分段错误? 下一篇:CMake 找不到源文件 (add_executable)

                  相关文章

                  最新文章

                    <bdo id='ehtyN'></bdo><ul id='ehtyN'></ul>

                  <small id='ehtyN'></small><noframes id='ehtyN'>

                  1. <tfoot id='ehtyN'></tfoot>
                      <i id='ehtyN'><tr id='ehtyN'><dt id='ehtyN'><q id='ehtyN'><span id='ehtyN'><b id='ehtyN'><form id='ehtyN'><ins id='ehtyN'></ins><ul id='ehtyN'></ul><sub id='ehtyN'></sub></form><legend id='ehtyN'></legend><bdo id='ehtyN'><pre id='ehtyN'><center id='ehtyN'></center></pre></bdo></b><th id='ehtyN'></th></span></q></dt></tr></i><div id='ehtyN'><tfoot id='ehtyN'></tfoot><dl id='ehtyN'><fieldset id='ehtyN'></fieldset></dl></div>
                      <legend id='ehtyN'><style id='ehtyN'><dir id='ehtyN'><q id='ehtyN'></q></dir></style></legend>