2011-07-15 7 views
0

テクスチャを作成し、そのIDとサイズ(ADCと別のスタックオーバーフローメンバーのおかげで)を保存するモデルクラスを使用して2の非累乗をレンダリングしようとしています。それをレンダリングします(VBOのコードとレンダリングはテスト目的のため、私のモデルでは適切に分割されています)。OpenGLテクスチャの初期化/レンダリングの問題

このコードを使用しても、テクスチャ固有のコードを削除すると問題なく動作します。しかし、テクスチャ固有のコードを追加すると、複数の複雑な画像を試したり、DigitalColor Meterを使って画像や出力を確認したりして、右下のピクセルと思われるものだけがレンダリングされます。

この設定を使用するときにテクスチャ座標を明示的に指定する必要はないと思いますが、どうすればいいでしょうか?

主なOpenGLのコード

// Create vertex buffer 
    GLuint memoryPointer = 0; 
    GLuint colourMemoryPointer = 0; 

    GLfloat *vertices; 
    size_t vertex_size = 0; 

    int check = AllocateVertexBuffer(2, 4, &vertices, &vertex_size); 
    CDMeshVertexesCreateRectangle(200, 200, vertices); 


    // Create colour buffer 
    GLfloat *colors; 
    size_t color_size; 

    int check2 = AllocateVertexBuffer(4, 4, &colors, &color_size); 
    CDMeshColorsCreateGrey(1.0, 4, colors); 


    // Create texture buffer 
    CDTexture *texture = [CDTexture loadPngTexture:@"Rawr"]; 

    // Allocate the buffer 
    glGenBuffers(1, &memoryPointer); 
    // Bind the buffer object (tell OpenGL what to use) 
    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 

    // Allocate space for the VBO 
    glBufferData(GL_ARRAY_BUFFER, vertex_size, vertices, GL_STATIC_DRAW); 


    // Allocate the buffer 
    glGenBuffers(1, &colourMemoryPointer); 
    // Bind the buffer object (tell OpenGL what to use) 
    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 

    // Allocate space for the VBO 
    glBufferData(GL_ARRAY_BUFFER, color_size, colors, GL_STATIC_DRAW); 

    glEnableClientState(GL_VERTEX_ARRAY); // Activate vertex coordinates array 
    glEnableClientState(GL_COLOR_ARRAY); 

    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 
    glVertexPointer(2, GL_FLOAT, 0, 0); 

    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
    glColorPointer(4, GL_FLOAT, 0, 0); 

    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture.ID); 
    glTexCoordPointer(2, GL_FLOAT, 0, 0); 

    //[texture render]; 

    //render 
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

    glDisableClientState(GL_VERTEX_ARRAY); // Deactivate vertex coordinates array 
    glDisableClientState(GL_COLOR_ARRAY); 

    free(vertices); 
    free(colors); 

CDTexture loadPngTexture:メソッド

CFURLRef textureURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), 
               (CFStringRef)fileName, 
               CFSTR("png"), 
               NULL); 

NSAssert(textureURL, @"Texture name invalid"); 

// Get the image source using a file path 
CGImageSourceRef myImageSourceRef = CGImageSourceCreateWithURL(textureURL, NULL); 
NSAssert(myImageSourceRef, @"Invalid Image Path."); 
NSAssert((CGImageSourceGetCount(myImageSourceRef) > 0), @"No Image in Image Source."); 

// Get the image reference using the source reference, -_- 
CGImageRef myImageRef = CGImageSourceCreateImageAtIndex (myImageSourceRef, 0, NULL); 
NSAssert(myImageSourceRef, @"Image not created."); 

// Start gathering data from the image, before releasing it 
GLuint myTextureName; 
size_t width = CGImageGetWidth(myImageRef); 
size_t height = CGImageGetHeight(myImageRef); 
CGRect rect = {{0, 0}, {width, height}}; 
void * myData = calloc(width * 4, height); 
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); 
CGContextRef myBitmapContext = CGBitmapContextCreate (myData, 
                 width, height, 8, 
                 width*4, space, 
                 kCGBitmapByteOrder32Host | 
                 kCGImageAlphaPremultipliedFirst); 

CGColorSpaceRelease(space); 
// Flip so that it isn't upside-down 
CGContextTranslateCTM(myBitmapContext, 0, height); 
CGContextScaleCTM(myBitmapContext, 1.0f, -1.0f); 
CGContextSetBlendMode(myBitmapContext, kCGBlendModeCopy); 
CGContextDrawImage(myBitmapContext, rect, myImageRef); 
CGContextRelease(myBitmapContext); 

glEnable(GL_TEXTURE_RECTANGLE_ARB); 

// Generate texture buffer 
glGenTextures(1, &myTextureName); 

// Bind buffer for use 
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName); 

// Set storage methods 
glPixelStorei(GL_UNPACK_ROW_LENGTH, width); 
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 

// Set the parameter required for non power of two textures 
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, 
       GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

// Load the texture data into the buffer 
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, width, height, 
      0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, myData); 

// Free the data used, as it's now in the buffer 
free(myData); 

// Return information on texture object 
CDTexture *texture = [[CDTexture alloc] init]; 

texture.ID = myTextureName; 
texture.size = NSMakeSize(width, height); 

return texture; 

UPDATE
私はエリアを定義するためにテクスチャのポインタを使用してみましたが、これは同じ問題がありました。描画する色やテクスチャは、バインドやポインタを使用しなくても実行されます。 GL_TEXTURE_COORD_ARRAYを使用してレンダリングする前と後に有効化と無効化を試してみましたが、同じ問題が発生します。

私が何か間違っていない限り、問題はテクスチャポインタに関連していないようです。

GLfloat texCoords[8] = { 
0.0, 0.0, 
0.0, 1.0, 
1.0, 1.0, 
1.0, 0.0 
}; 

... 

glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
glColorPointer(4, GL_FLOAT, 0, 0); 

glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture.ID); 
glTexCoordPointer(2, GL_FLOAT, 0, texCoords); 

//[texture render]; 

//render 
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

UPDATEは2
私が試してみて、問題を解決するためのOpenGLからのエラーコードを取得しようとしましたが、エラーコードが印刷されていません。

UPDATE 3
Iは、生の画像データを取得するために異なる方法を使用してみました、と(私は右の色設定を使用してはならないように、いくつかの変色はあるものの)同様の結果が起こります。ここではOpenGLのデータの解釈に欠陥があるはずです。私はglPixelStorei()で実験しましたが、これまで何も変わっていません。 OpenGLはエラーを報告していないので、データのプログラム解釈が必要なので、データの格納方法に設定したパラメータ、または1ピクセルしか表示しない頂点問題精度は、パラメータである可能性が最も高いです。

生画像データの新しい処理(別のstackoverflowユーザーのおかげで)。参照のために掲示される。

NSBitmapImageRep *theImage; 
int bitsPPixel, bytesPRow; 
NSSize size; 
unsigned char *theImageData; 

NSData* imgData = [NSData dataWithContentsOfFile:fileName options:NSUncachedRead error:nil]; // use FileURL 

theImage = [NSBitmapImageRep imageRepWithData:imgData]; 


if(theImage != nil) 
{ 
    bitsPPixel = [theImage bitsPerPixel]; 
    bytesPRow = [theImage bytesPerRow]; 
    size.width = [theImage pixelsWide]; 
    size.height = [theImage pixelsHigh]; 
} 

enter code here 

効率をGL_TEXTURE_2Dに変更UPDATE 4
。左下のピクセルはまだレンダリングされています。ここでは、コードの完全な順序は次のとおりです。

// Create vertex buffer 
    GLuint memoryPointer = 0; 
    GLuint colourMemoryPointer = 0; 

    GLfloat *vertices; 
    size_t vertex_size = 0; 

    AllocateVertexBuffer(2, 4, &vertices, &vertex_size); 
    CDMeshVertexesCreateRectangle(200, 200, vertices); 


    // Create colour buffer 
    GLfloat *colors; 
    size_t color_size; 

    AllocateVertexBuffer(4, 4, &colors, &color_size); 
    CDMeshColorsCreateGrey(1.0, 4, colors); 

    // Create Texture UV Coordinates 
    GLfloat *texture; 
    size_t texture_size; 
    AllocateVertexBuffer(4, 2, &texture, &texture_size); 
    CDMeshVertexesCreateRectangle(1, 1, texture); 

    // Create texture buffer 
    NSString *fileName = @"Rawr3"; 

    CFURLRef textureURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), 
                (CFStringRef)fileName, 
                CFSTR("png"), 
                NULL); 

    NSAssert(textureURL, @"Texture name invalid"); 

    // Get the image source using a file path 
    CGImageSourceRef myImageSourceRef = CGImageSourceCreateWithURL(textureURL, NULL); 
    NSAssert(myImageSourceRef, @"Invalid Image Path."); 
    NSAssert((CGImageSourceGetCount(myImageSourceRef) > 0), @"No Image in Image Source."); 

    // Get the image reference using the source reference, -_- 
    CGImageRef myImageRef = CGImageSourceCreateImageAtIndex (myImageSourceRef, 0, NULL); 
    NSAssert(myImageSourceRef, @"Image not created."); 

    // Start gathering data from the image, before releasing it 
    GLuint myTextureName; 
    size_t width = CGImageGetWidth(myImageRef); 
    size_t height = CGImageGetHeight(myImageRef); 
    CGRect rect = {{0, 0}, {width, height}}; //Doesnt need fiddling 
    void * myData = calloc(width * 4, height); //Fiddled 
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef myBitmapContext = CGBitmapContextCreate (myData, 
                  width, height, 8, 
                  width*4, space, 
                  kCGBitmapByteOrder32Host | 
                  kCGImageAlphaPremultipliedFirst); 

    CGColorSpaceRelease(space); 
    // Flip so that it isn't upside-down 
    CGContextTranslateCTM(myBitmapContext, 0, height); 
    CGContextScaleCTM(myBitmapContext, 1.0f, -1.0f); 
    CGContextSetBlendMode(myBitmapContext, kCGBlendModeCopy); 
    CGContextDrawImage(myBitmapContext, rect, myImageRef); 
    CGContextRelease(myBitmapContext); 

    // Generate texture buffer 
    glGenTextures(1, &myTextureName); 

    // Bind buffer for use 
    glBindTexture(GL_TEXTURE_2D, myTextureName); 

    // Set storage methods 
    glTexParameteri(GL_TEXTURE_2D, 
        GL_TEXTURE_STORAGE_HINT_APPLE, 
        GL_STORAGE_CACHED_APPLE); 

    glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); 

    // Set clamping and rendering preferences 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
        GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
        GL_NEAREST); 

    // Load the texture data into the buffer 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 
       0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, myData); 

    glGetError(); 

    // Free the data used, as it's now in the buffer 
    free(myData); 

    // Return information on texture object 
    CDTexture *textureObj = [[CDTexture alloc] init]; 

    textureObj.ID = myTextureName; 
    textureObj.size = NSMakeSize(width, height); 

    // Allocate the buffer 
    glGenBuffers(1, &memoryPointer); 
    // Bind the buffer object (tell OpenGL what to use) 
    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 

    // Allocate space for the VBO 
    glBufferData(GL_ARRAY_BUFFER, vertex_size, vertices, GL_STATIC_DRAW); 


    // Allocate the buffer 
    glGenBuffers(1, &colourMemoryPointer); 
    // Bind the buffer object (tell OpenGL what to use) 
    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 

    // Allocate space for the VBO 
    glBufferData(GL_ARRAY_BUFFER, color_size, colors, GL_STATIC_DRAW); 

    glEnableClientState(GL_VERTEX_ARRAY); // Activate vertex coordinates array 
    glEnableClientState(GL_COLOR_ARRAY); 
    glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
    glEnable(GL_TEXTURE_2D); 

    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 
    glVertexPointer(2, GL_FLOAT, 0, 0); 

    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
    glColorPointer(4, GL_FLOAT, 0, 0); 

    glBindTexture(GL_TEXTURE_2D, textureObj.ID); 
    glTexCoordPointer(2, GL_FLOAT, 0, texture); 

    GetGLError(); 

    //render 
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

    glDisableClientState(GL_VERTEX_ARRAY); // Deactivate vertex coordinates array 
    glDisableClientState(GL_COLOR_ARRAY); 
    glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    glDisable(GL_TEXTURE_2D); 

    glDeleteBuffers(1, &memoryPointer); 
    glDeleteBuffers(1, &colourMemoryPointer); 
    GLuint texID = textureObj.ID; 
    glDeleteBuffers(1, &texID); 

    free(vertices); 
    free(colors); 
    free(texture); 


} 

UPDATE 5 glTexImage2Dから()、それは私がテクスチャをバインドしての座標を追加しない場合でも、テクスチャの左下のピクセルをレンダリングしますそれはglTexCoordPointer()を使って描かれるべきであると考えて、奇妙に思えます。

UPDATE 6 おそらく最後の更新は、図面の別のより、「手動」技術によるテクスチャー初期化コードを使用し、それがうまく働きました。私はApple固有の要素を削除しました。このコードから色のVBOとポインタを削除すると、何らかの理由で白いボックスがレンダリングされます。問題はVBOの問題ですが、その理由を見ることはできません。 GL_TEXTURE_RECTANGLE_ARBは色のテクスチャに使用されているだけで、この問題が解決されると変更されます。

// Create vertex buffer 
    GLuint memoryPointer = 0; 
    GLuint colourMemoryPointer = 0; 

    GLfloat *vertices; 
    size_t vertex_size = 0; 

    AllocateVertexBuffer(2, 4, &vertices, &vertex_size); 
    CDMeshVertexesCreateRectangle(200, 200, vertices); 

    GetGLError(); 

    // Create colour buffer 
    GLfloat *colors; 
    size_t color_size; 

    AllocateVertexBuffer(4, 4, &colors, &color_size); 
    CDMeshColorsCreateGrey(0.4, 4, colors); 

    // Allocate the buffer 
    glGenBuffers(1, &memoryPointer); 
    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 
    glBufferData(GL_ARRAY_BUFFER, vertex_size, vertices, GL_STATIC_DRAW); 

    // Allocate the buffer 
    glGenBuffers(1, &colourMemoryPointer); 
    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
    glBufferData(GL_ARRAY_BUFFER, color_size, colors, GL_STATIC_DRAW); 

    // Enable client states for drawing the various arrays 
    glEnableClientState(GL_VERTEX_ARRAY); 
    glEnableClientState(GL_COLOR_ARRAY); 
    glEnableClientState(GL_TEXTURE_COORD_ARRAY); 

    // Bind each buffer and use the VBO's to draw (apart from the texture buffer) 
    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 
    glVertexPointer(2, GL_FLOAT, 0, 0); 

    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
    glColorPointer(4, GL_FLOAT, 0, 0); 

    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName); // 
    glTexCoordPointer(2, GL_FLOAT, 0, texture); 

    //render 
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

    // Disale client states as were done with them. 
    glDisableClientState(GL_VERTEX_ARRAY); 
    glDisableClientState(GL_COLOR_ARRAY); 
    glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    glDisable(GL_TEXTURE_RECTANGLE_ARB); 

    GetGLError(); 

    // Delete buffers to avoid problems 
    glDeleteBuffers(1, &memoryPointer); 
    glDeleteBuffers(1, &colourMemoryPointer); 
    glDeleteBuffers(1, &myTextureName); 

    free(vertices); 
    free(colors); 
    free(texture); 
+1

ヒント:いけないGL_TEXTURE_RECTANGLE_ARBを使用し、それすべてのgfxカードとそれが動作する場所ではスーパースローで動作しませんし、ミップマップをサポートしませんどちらか。常にGL_TEXTURE_2Dを使用してください! – Rookie

+0

@ルーキー、ヒントをいただきありがとうございます。私は2枚の画像とUV座標のセットでこれを使用しようとしましたが、今は画像を出力しません。しかし、GL_TEXTURE_2Dで作業を続けます。 – Croc

答えて

0

glTextureCoordPointer()に直接頂点データを提供しようとするのではなく、テクスチャのVertex Buffer Object(VBO)を作成して問題を解決しました。 VBOを使うつもりなら、すべてのものを使ってください!参考のため、ここでは完全なコードです:

テクスチャの作成

// Create texture buffer, start with the name of the image. 
    NSString *fileName = @"Rawr"; 

    CFURLRef textureURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), 
                (CFStringRef)fileName, 
                CFSTR("png"), 
                NULL); 

    NSAssert(textureURL, @"Texture name invalid"); 

    // Get the image source using a file path 
    CGImageSourceRef myImageSourceRef = CGImageSourceCreateWithURL(textureURL, NULL); 
    NSAssert(myImageSourceRef, @"Invalid Image Path."); 
    NSAssert((CGImageSourceGetCount(myImageSourceRef) > 0), @"No Image in Image Source."); 

    // Get the image reference using the source reference, -_- 
    CGImageRef myImageRef = CGImageSourceCreateImageAtIndex (myImageSourceRef, 0, NULL); 
    NSAssert(myImageSourceRef, @"Image not created."); 

    // Start gathering data from the image, before releasing it 
    GLuint myTextureName; 
    size_t width = CGImageGetWidth(myImageRef); 
    size_t height = CGImageGetHeight(myImageRef); 
    CGRect rect = {{0, 0}, {width, height}}; //Doesnt need fiddling 
    void * myData = calloc(width * 4, height); //Fiddled 
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef myBitmapContext = CGBitmapContextCreate (myData, 
                  width, height, 8, 
                  width*4, space, 
                  kCGBitmapByteOrder32Host | 
                  kCGImageAlphaPremultipliedFirst); 

    CGColorSpaceRelease(space); 
    // Flip so that it isn't upside-down 
    CGContextTranslateCTM(myBitmapContext, 0, height); 
    CGContextScaleCTM(myBitmapContext, 1.0f, -1.0f); 
    CGContextSetBlendMode(myBitmapContext, kCGBlendModeCopy); 
    CGContextDrawImage(myBitmapContext, rect, myImageRef); 
    CGContextRelease(myBitmapContext); 

    GetGLError(); 

    // The extension GL_TEXTURE_RECTANGLE_ARB can be used for non-power of two textures, but it is slower than GL_TEXTURE_2D and not 
    // supported by all graphics cards. 
    glEnable(GL_TEXTURE_RECTANGLE_ARB); 
    glGenTextures(1, &myTextureName); 
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName); 
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,GL_NEAREST); 
    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 
    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, myData); 
    //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT ,GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB,myTextureName, 0); 
    free(myData); 

VBO作成

// Create vertex buffer 
    GLuint memoryPointer = 0; 
    GLuint colourMemoryPointer = 0; 
    GLuint texPointer = 0; 

    GLfloat *vertices; 
    size_t vertex_size = 0; 

    AllocateVertexBuffer(2, 4, &vertices, &vertex_size); 
    CDMeshVertexesCreateRectangle(200, 200, vertices); 

    GetGLError(); 

    // Create colour buffer 
    GLfloat *colors; 
    size_t color_size; 

    AllocateVertexBuffer(4, 4, &colors, &color_size); 
    CDMeshColorsCreateGrey(0.0, 4, colors); 

    // Create Texture UV Coordinates 
    GLfloat *texture; 
    size_t texture_size; 
    AllocateVertexBuffer(2, 4, &texture, &texture_size); 
    CDMeshVertexesCreateRectangle(200, 200, texture); 

    // Allocate the vertex VBO 
    glGenBuffers(1, &memoryPointer); 
    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 
    glBufferData(GL_ARRAY_BUFFER, vertex_size, vertices, GL_STATIC_DRAW); 

    // Allocate the colour VBO 
    glGenBuffers(1, &colourMemoryPointer); 
    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
    glBufferData(GL_ARRAY_BUFFER, color_size, colors, GL_STATIC_DRAW); 

    // Allocate the texture VBO 
    glGenBuffers(1, &texPointer); 
    glBindBuffer(GL_ARRAY_BUFFER, texPointer); 
    glBufferData(GL_ARRAY_BUFFER, texture_size, texture, GL_STATIC_DRAW); 

レンダリングと削除VBOとデータ

// Enable client states for drawing the various arrays 
    glEnableClientState(GL_VERTEX_ARRAY); 
    glEnableClientState(GL_COLOR_ARRAY); 
    glEnableClientState(GL_TEXTURE_COORD_ARRAY); 

    // Bind each buffer and use the VBO's to draw 
    glBindBuffer(GL_ARRAY_BUFFER, memoryPointer); 
    glVertexPointer(2, GL_FLOAT, 0, 0); 

    glBindBuffer(GL_ARRAY_BUFFER, colourMemoryPointer); 
    glColorPointer(4, GL_FLOAT, 0, 0); 

    glBindBuffer(GL_ARRAY_BUFFER, texPointer); 
    glTexCoordPointer(2, GL_FLOAT, 0, 0); 
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName); 

    // RENDER! 
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

    // Disale client states as were done with them. 
    glDisableClientState(GL_VERTEX_ARRAY); 
    glDisableClientState(GL_COLOR_ARRAY); 
    glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    glDisable(GL_TEXTURE_RECTANGLE_ARB); 

    GetGLError(); 

    // Delete buffers when they arent being used. 
    glDeleteBuffers(1, &memoryPointer); 
    glDeleteBuffers(1, &colourMemoryPointer); 
    glDeleteBuffers(1, &myTextureName); 
    glGenTextures(GL_TEXTURE_RECTANGLE_ARB, 0); 

    // Free vertexes when done using them 
    free(vertices); 
    free(colors); 
    free(texture); 
1

もちろん、テクスチャ座標を指定する必要があります。頂点属性ベクトルの一部として、またはそれらを生成することによって(シェーダ内で)。しかし、テクスチャ座標を何らかの形で供給する必要があります。これを回避することはできません。

+1

@Croc、私のヒントを読んでください。また、GL_TEXTURE_RECTANGLE_ARBは0-1の値ではなく、ピクセルでテクスチャを取ります。 GL_TEXTURE_RECTANGLE_ARBからGL_TEXTURE_2Dに変更するだけです – Rookie

関連する問題