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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:04:48+00:00 2026-05-27T18:04:48+00:00

In the OpenGL ES 2.0 introduction, found here: http://www.webreference.com/programming/opengl_es/2.html a vertex shader is defined:

  • 0

In the OpenGL ES 2.0 introduction, found here: http://www.webreference.com/programming/opengl_es/2.html
a vertex shader is defined:

GLbyte vShaderStr[] =
   "attribute vec4 vPosition;   \n"
   "void main()                 \n"
   "{                           \n"
   "   gl_Position = vPosition; \n"
   "};                          \n";

The vPosition attribute is a four component vector.

Later in the text the application will compile the vertex shader, together with the fragment shader.
With the glBindAttribLocation a handle to pass the applications vertex data to the shader is established:

// Bind vPosition to attribute 0
glBindAttribLocation(programObject, 0, "vPosition");

The 2 shaders are now linked and the program is ready to use.

The use case is this:

GLfloat vVertices[] = {0.0f, 0.5f, 0.0f,
                        -0.5f, -0.5f, 0.0f,
                        0.5f, -0.5f, 0.0f};
...
// Load the vertex data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);

Which means:

  • glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices) :
    pass the vertex data to the program, use location 0, each vertex has 3 components, type is float, no normalisation shall be used.

  • glEnableVertexAttribArray(0) :
    The shader will use the passed data.

  • glDrawArrays(GL_TRIANGLES, 0, 3); :
    The shader will execute the code to draw a single triangle, using the first (and only) three vertices found in the specified array.

My Questions are:

  • The vertex shader is expecting a four component vertex position (x,y,z,w), the program passes only three components (x,y,z) data
    Why is this working?

  • The shader needs a vec4, the w-component must be 1 to work as expected.
    Which step is responsible for adding the w-component correctly?

  • 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-27T18:04:49+00:00Added an answer on May 27, 2026 at 6:04 pm

    See this answer: Can you use glVertexAttribPointer to assign a smaller vector to a larger one?

    As mentioned in that post it appears in the gles specifications: http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.24.pdf
    In section 2.8 of this document it says:

    When an array element i is transferred to the GL by the DrawArrays or
    DrawElements commands, each generic attribute is expanded to four
    components. If size is one then the x component of the attribute is
    specified by the array; the y, z, and w components are implicitly set
    to zero, zero, and one, respectively. If size is two then the x and y
    components of the attribute are specified by the array; the z, and w
    components are implicitly set to zero, and one, respectively. If size
    is three then x, y, and z are specified, and w is implicitly set to
    one. If size is four then all components are specified.

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

Sidebar

Related Questions

Does OpenGL/OpenGLES VBO hold only same size vertex? I'm asking because i found that
In OpenGL ES 2.0, is it possible to use a compiled vertex/fragment shader in
In OpenGL 2.1, I'm passing a position and normal vector to my vertex shader.
I want to translate text to audio on osx similar as done here: http://developer.apple.com/library/mac/#samplecode/CocoaSpeechSynthesisExample/Introduction/Intro.html
In OpenGL, is there a way to use framebuffer data as vertex data without
I am using openGL and am currently passing it a vertex array. The problem
Running openGL 3.1, the question is simple. From GLSL site, here is how one
What OpenGL / GLUT reference is good for day to day programming as you
The OpenGL Es 2.0 Programming Guide (Munshi et al., 2008) says the dimensions must
/* OpenGL animation code goes here */ glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClear (GL_COLOR_BUFFER_BIT);

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.