Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6160595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:19:53+00:00 2026-05-23T21:19:53+00:00

Im trying to render a non power of 2 texture using a model class

  • 0

Im trying to render a non power of 2 texture using a model class that creates a texture and stores it’s ID and size (thanks to ADC and another stackoverflow member), and additional code the create VBO’s and render it (The code for VBO’s and rendering is for testing purposes, it is properly divided in my models).

When I use this code, but remove the texture-specific code, it works fine. When adding the texture specific code however, it only renders what I believe to be the bottom-right pixel, from trying out multiple complex images and using DigitalColor Meter to check the images and output.

I don’t suppose that texture coordinates have to be specified explicitly when using this setup, and if they do, how would I?

Main OpenGL Code

    // 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: Method

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
I’ve tried using a texture pointer to define the area, and this results in the same problem. The colour/texture it draws will do so even without binding and using a pointer. I have also tried enabling and disabling GL_TEXTURE_COORD_ARRAY before and after it is used and rendered, and results in the same problem.

Unless i’ve done something wrong, the problem doesn’t seem related with texture pointers.

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
I’ve tried obtaining an error code from OpenGL to try and solve the problem, but no error codes have been printed.

UPDATE 3
I have tried using a different method to get raw image data, and the same result happens (albeit with some discolouration, as I must not be using the right colour settings). OpenGL’s interpretation of the data must be flawed here. I have experimented with glPixelStorei() but nothing has changed so far. As OpenGL isn’t reporting any error, it must be with the programs interpretation of the data, so either the parameters I have set for how data is stored, or vertex problems that is causing only 1 pixel to be displayed, although because of this precision, it is most likely to be parameters.

New process for raw image data (thanks to another stackoverflow user). Posted for reference.

 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

UPDATE 4
Changed to GL_TEXTURE_2D for efficiency. The bottom-left pixel is still only being rendered. Here is the full order of the code:

// 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
From glTexImage2D(), it will render the bottom-left pixel of the texture even if I don’t bind the texture and add coordinates for it, which seems strange, considering that it should be drawn using glTexCoordPointer().

UPDATE 6
Probably the last update, used the texture initialisation code with another more, ‘manual’ technique of drawing and it worked fine. I have removed the Apple specific elements. When removing the colour VBO and pointer from this code, a white box is still rendered for some odd reason. The problem is with the VBO’s, but I cant see why. GL_TEXTURE_RECTANGLE_ARB is just being used for my coloured texture right now, will be changed when this problem is solved.

// 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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:19:54+00:00Added an answer on May 23, 2026 at 9:19 pm

    I solved the problem (finally) by creating a Vertex Buffer Object (VBO) for the texture, instead of trying to supply vertex data directly to glTextureCoordPointer(). I guess the lesson here is that if you are going to use VBO’s, use them for everything! For reference, here is the complete code:

    Texture Creation

    // 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 Creation

    // 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);
    

    Rendering and Deleting VBO and Data

    // 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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a model in Direct3D using DrawIndexedPrimitives . However, I
I'm trying to write a C++ windows service that can render to a texture.
I have a UIView that I am trying to render into a UIImage using
Currently I am trying to render a .obj model that I loaded into vectors.
I'm trying to render a bit of text using Core Graphics APIs and I'm
I'm trying to render a colored cube after rendering other cubes that have textures.
I have a chart (in bitmap format) that I'm trying to render to a
I'm trying to build a grid the size of the browser window that has
I'm trying to render a simple textured quad on Android 2.2 using GLSurfaceView .
I'm trying to render a textured quad in d3d, and its not using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.