1

この画像を 2D テクスチャに読み込み、画面に描画します。主な問題は、画像をテクスチャ変数にロードすることです。次のコードは正しい幅と高さ、および rgba を出力しますが、データを 3D テクスチャに配置するにはどうすればよいですか。

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
/* more includes... */
#include "stb_image.h"

using namespace std;

int main(int argc, char** argv) {
    int x,y,n;
    unsigned char *data = stbi_load("png.png", &x, &y, &n, 0);
    if (data == NULL) {
        // error
        cout << "Error, data was null";
    } else {
        // process
        cout << data << endl << endl;
    }
    stbi_image_free(data);

    cout << x << endl << y << endl << n;
    return 0;
}
4

1 に答える 1

5

まずあなたが必要です

  • ドローアブル (window、PBuffer、framebuffer)
  • ドローアブルに関連付けられた OpenGL コンテキスト

それらを取得するには、GLFW、SDL、またはGLUTを使用できます(個人的には、単一のウィンドウのみが必要な場合はGLFWをお勧めします)。

でテクスチャ名を作成します

Gluint texture_name;

void somefunction(…)
{
glGenTextures(1, &texture_name);
glBindTexture(GL_TEXTURE_2D, texture_name);
glPixelStorei(…); /* multiple calls to glPixelStorei describing the layout of the data to come */
glTexImage2D(GL_TEXTURE_2D, miplevel, internal_format, width, height, border, format, type, data);
}

これは、ロード方法の簡単で汚い説明でした。絵を描くのは別の仕事です。OpenGL のチュートリアルを読むことをお勧めします。「NeHe」または「Lighthouse3D」、または「Arcsynthesis OpenGL チュートリアル」の Google。

于 2011-09-29T17:14:09.603 に答える