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

  • Home
  • SEARCH
  • 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 7553813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:09:48+00:00 2026-05-30T11:09:48+00:00

Ive been using Open GL ES 2.0 Programming guide and am following chapter 9

  • 0

Ive been using Open GL ES 2.0 Programming guide and am following chapter 9 about textures but ive set up the same pixel array (2×2- Red Green Blue Yellow) and it only shows red for the whole triangle. Cant seem to find the problem, i think my shaders are fine too please help my code follows.

- (void)setupGL
   {
    [EAGLContext setCurrentContext:self.context];

    [self loadShaders];

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_SRC_COLOR);

    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);

    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(gRectVertexData), gRectVertexData, GL_STATIC_DRAW);

// 2 x 2 Image, 3 bytes per pixel(R, G, B) 
GLubyte pixels[12] =
{
    255,0,0, // Red 
    0,255,0, // Green
    0,0,255, // Blue
    0,255,255 // Yellow 
};
    // Use tightly packed data
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    // Generate a texture object 
glGenTextures(1, &texture[0]);
    // Bind the texture object 
glBindTexture(GL_TEXTURE_2D, texture[0]);
    // Load the texture
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, 2,2, 0, GL_RGB,
                 GL_UNSIGNED_BYTE, pixels);
// Set the filtering mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    GLint SamplerLoc = glGetUniformLocation(_program, "Texture");
glUniform1i(SamplerLoc, 0);

glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(12));
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 32, BUFFER_OFFSET(24));

glBindVertexArrayOES(0);

}

I have this in my load shaders part

glBindAttribLocation(_program, ATTRIB_VERTEX, "position");
glBindAttribLocation(_program, ATTRIB_NORMAL, "normal");
glBindAttribLocation(_program, ATTRIB_TEX, "TexCoordIn");

then my vertex shader and fragment shader are as follows

attribute vec4 position;
attribute vec3 normal;
attribute vec2 TexCoordIn;

varying lowp vec4 colorVarying;
varying vec2 TexCoordOut;

uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;

void main()
{
  vec3 eyeNormal = normalize(normalMatrix * normal);
  vec3 lightPosition = vec3(0.0, 0.0, 1.0);
  vec4 diffuseColor = vec4(0.8, 0.4, 1.0, 1.0);

  float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));

  colorVarying = diffuseColor*nDotVP;

  gl_Position = modelViewProjectionMatrix * position;
  TexCoordOut = TexCoordIn;
}

The Fragment Shader

varying lowp vec4 colorVarying;
varying lowp vec2 TexCoordOut;
uniform sampler2D Texture;

void main()
{
lowp vec4 col = texture2D(Texture, TexCoordOut);
col.x *= colorVarying.x;
col.y *= colorVarying.x;
col.z *= colorVarying.x;
col.a = 1.0;
    gl_FragColor =  col;
}
  • 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-30T11:09:49+00:00Added an answer on May 30, 2026 at 11:09 am

    Change your call

    glBindAttribLocation(_program, ATTRIB_TEX, "TexCoordIn");
    

    to use the GLKVertexAttribTexCoord0 instead of your ATTRIB_TEX enum.

    This is an annoying gotcha in the OpenGL Game project. The enum members they use in their glBindAttribLocation calls for positions and normals happen to have the same values as the GLKVertexAttribPosition and GLKVertexAttribNormal enums, but this is just a coincidence.

    Check out the post at headnoodles for step by step instructions. The example uses GLKit but everything else should be the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using File.ReadAllText() to open a CSV file, but every time I forget
I've been using the following code to open Office Documents, PDF, etc. on my
I've been reading on how to search LDAP servers using Python, but Ive been
I'm from a Windows programming background when writing tools, but have been programming using
Ive been using the following code to convert aac / mp3 files into pcm.
The question is a fairly open one. I've been using Stored Procs with MS
I've been using PHP & MySQL for ages and am about to start using
I have been programming procedural PHP for about 8 years, and am finally starting
Sorry about all these silly questions, I've been thrust into Perl programming and I'm
Some open source I've been using has the below line as a function declaration:

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.