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 8863853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:05:30+00:00 2026-06-14T16:05:30+00:00

Whenever I attempt to render a textured quad, I end up with a triangular

  • 0

Whenever I attempt to render a textured quad, I end up with a triangular section of the texture distorted: see this image
.

The texture is a PNG created in GIMP, and I’ve tried two seperate methods of loading the texture (both from Apple’s own sample code). Each method of loading the texture produced different results (I don’t know if it is different default settings, or if there is a problem with the texture), but I couldn’t get either to render proper.

I’ve tried setting up my indices/verticles/texices in multiple different ways, from suggestions posted in Fastest way to draw quads in OpenGL ES? yet still no luck.

What could I be missing?

Code to Load Texture

- (GLuint)setupTexture:(NSString *)fileName {    
    CGImageRef spriteImage = [UIImage imageNamed:fileName].CGImage;
    if (!spriteImage) {
        NSLog(@"Failed to load image %@", fileName);
        exit(1);
    }
    size_t width = CGImageGetWidth(spriteImage);
    size_t height = CGImageGetHeight(spriteImage);
    GLubyte * spriteData = (GLubyte *) calloc(width*height*4, sizeof(GLubyte));
    CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4, 
    CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);    
    CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage);
    CGContextRelease(spriteContext);
    GLuint texName;
    glGenTextures(1, &texName);
    glBindTexture(GL_TEXTURE_2D, texName);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
    free(spriteData);        
    return texName;    
}

Texture Coordinates and Verticles

const GLfloat texices[] =
    { 0,1,
      1,1,
      0,0,
      1,0 };

glActiveTexture(GL_TEXTURE0);
glUniform1i(_texturedTextureUniformSlot, 0);
glVertexAttribPointer(_texturedTextureSlot, 2, GL_FLOAT, GL_FALSE, 0, texices);

GLfloat vertices[] = {-1, -1, 0, //bottom left corner
                  -1,  1, 0, //top left corner
                   1,  1, 0, //top right corner
                   1, -1, 0}; // bottom right rocner

GLubyte indices[] = {0,1,2, // first triangle (bottom left - top left - top right)
                 0,2,3}; // second triangle (bottom left - top right - bottom right)

glVertexAttribPointer(3, GL_FLOAT, 0, vertices);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
  • 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-06-14T16:05:31+00:00Added an answer on June 14, 2026 at 4:05 pm

    It looks like your texture coordinates may be wrong (notice the texture appears to be wrapping around the left side).

    Here is a snippet of code that I’ve used in the past:

    const float quadPositions[] = {  1.0,  1.0, 0.0, 
                                    -1.0,  1.0, 0.0, 
                                    -1.0, -1.0, 0.0, 
                                    -1.0, -1.0, 0.0, 
                                     1.0, -1.0, 0.0, 
                                     1.0,  1.0, 0.0 };
    const float quadTexcoords[] = { 1.0, 1.0, 
                                    0.0, 1.0, 
                                    0.0, 0.0, 
                                    0.0, 0.0, 
                                    1.0, 0.0, 
                                    1.0, 1.0 };
    
    // stop using VBO
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    // setup buffer offsets
    glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), quadPositions);
    glVertexAttribPointer(ATTRIB_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), quadTexcoords);
    
    // ensure the proper arrays are enabled
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glEnableVertexAttribArray(ATTRIB_TEXCOORD0);
    
    // draw
    glDrawArrays(GL_TRIANGLES, 0, 2*3);
    

    That should draw a two triangles at z=0. You’ll want to setup your projection from -1 to 1 in width and height.

    Edit:

    Here’s a working version of your code:

    const GLfloat texices[] = { 0, 0,
                                0, 1,
                                1, 1,
                                1, 0 };
    
    
    const GLfloat vertices[] = { -1, -1, 0,  // bottom left corner
                                 -1,  1, 0,  // top left corner
                                  1,  1, 0,  // top right corner
                                  1, -1, 0}; // bottom right corner
    
    const GLubyte indices[] = { 0, 2, 1,     // first triangle (bottom left - top left - top right)
                                0, 3, 2 };
    
    
    // ensure no VBOs or IBOs are bound
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);    
    
    glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), vertices);
    glVertexAttribPointer(ATTRIB_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), texices);
    
    // ensure the proper arrays are enabled
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glEnableVertexAttribArray(ATTRIB_TEXCOORD0);
    
    glDisable(GL_CULL_FACE);
    
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this error whenever I attempt to declare a class: Parse error: syntax
Whenever a model is created in my application, an email is sent out to
Whenever I attempt to create a wallpost that doesn't have the caption set it
Whenever I attempt to set the default value of an optional parameter to something
I have an OpenGL-related issue. Whenever I attempt to draw a simple polygon using
I'm attempting to use the jQuery UI Tabs module, but whenever I attempt to
A user recently notified me that whenever they attempt to dial into a conference
Alright, I'm doing this for a project and whenever I attempt to have it
Whenever I attempt to run my unit tests (written with buster and executed user
I ask the question because whenever I attempt to call an extension method from

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.