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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:15:35+00:00 2026-05-31T12:15:35+00:00

I’m trying to learn GLSL for Open GL ES 2.0. I’ve looked around at

  • 0

I’m trying to learn GLSL for Open GL ES 2.0. I’ve looked around at tutorials but there’s clearly something missing in the explanations because it makes absolutely no sense. Take the code below. This is ripped right from the official OpenGL ES 2.0 reference card.

This is supposed to be the vertex shader.

uniform mat4 mvp_matrix; // model-view-projection matrix
uniform mat3 normal_matrix; // normal matrix
uniform vec3 ec_light_dir; // light direction in eye coords
attribute vec4 a_vertex; // vertex position
attribute vec3 a_normal; // vertex normal
attribute vec2 a_texcoord; // texture coordinates
varying float v_diffuse;
varying vec2 v_texcoord;

void main(void)
{
   // put vertex normal into eye coords
   vec3 ec_normal = normalize(normal_matrix * a_normal);
   // emit diffuse scale factor, texcoord, and position
   v_diffuse = max(dot(ec_light_dir, ec_normal), 0.0);
   v_texcoord = a_texcoord;
   gl_Position = mvp_matrix * a_vertex;
}

Problem 1: Nothing is initialized. There’s 8 variables/objects listed at the start and not one is ever initialized. So we’ve got 8 null variables/objects.

Problem 2: The variables/objects that are initialized are initialized using the previous 8 null variables/objects. Great, so now everything is null…

Problem 3: Nothing is passed out of the function. How this can shade anything is beyond me, it takes nothing in and passes nothing out. The only thing it touches that could have an effect is gl_Position which is apparently some kind of special output variable. But it only depends on mvp_matrix and a_vertex so what’s all the other stuff for?

And it isn’t just this example, it’s all the one’s I’ve found so far. I don’t understand how declaring a bunch of variables, not using most of them, and then passing/assigning null objects all over the place can do anything.

  • 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-31T12:15:36+00:00Added an answer on May 31, 2026 at 12:15 pm

    you are assuming that a shader behaves the same as regular c code, but this is not the case. vertex shaders have two types of input: attributes and uniforms, and one type of output: varyings. that is what is being defined at the top of the shader code. attributes are per vertex data, they are different for every vertex. uniforms are the same across all the vertexes. initialising the attributes and uniforms is done elsewhere, in your main rendering method in the application. here, there will be lots of calls like:

    // set up the position attribute
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
    

    the outputs to the shader are the varyings v_diffuse and v_texcoord. the values for these outputs are interpolated across all the rendered fragment shaders, for use in lighting the fragments.

    the gl_Position variable is a special output that sets the position of the vertex.

    for this example to make sense, you also need to look at the main loop doing the rendering and the fragment shader, they are all tied together.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group

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.