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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:57:55+00:00 2026-05-15T09:57:55+00:00

Hello I’m trying to convert the following functions to a VBO based function for

  • 0

Hello I’m trying to convert the following functions to a VBO based function for learning purposes, it displays a static texture on screen. I’m using OpenGL ES 2.0 with shaders on the iPhone (should be almost the same than regular OpenGL in this case), this is what I got working:

//Works!
- (void) drawAtPoint:(CGPoint)point depth:(CGFloat)depth
{
    GLfloat             coordinates[] = {
                            0,          1,
                            1,          1,
                            0,          0,
                            1,          0
                        };

    GLfloat             width = (GLfloat)_width * _maxS,
                        height = (GLfloat)_height * _maxT;

    GLfloat             vertices[] = {
                            -width / 2 + point.x,       -height / 2 + point.y,
                            width / 2 + point.x,        -height / 2 + point.y,
                            -width / 2 + point.x,       height / 2 + point.y,
                            width / 2 + point.x,        height / 2 + point.y,   
                        };


    glBindTexture(GL_TEXTURE_2D, _name);
    //Attrib position and attrib_tex coord are handles for the shader attributes
    glVertexAttribPointer(ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glEnableVertexAttribArray(ATTRIB_POSITION);
    glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, coordinates);
    glEnableVertexAttribArray(ATTRIB_TEXCOORD);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

I tried to do this to convert to a VBO however I don’t see anything displaying on-screen with this version:

//Doesn't display anything
- (void) drawAtPoint:(CGPoint)point depth:(CGFloat)depth
{
    GLfloat             width = (GLfloat)_width * _maxS,
                        height = (GLfloat)_height * _maxT;

    GLfloat             position[] = {
                            -width / 2 + point.x,       -height / 2 + point.y,
                            width / 2 + point.x,        -height / 2 + point.y,
                            -width / 2 + point.x,       height / 2 + point.y,
                            width / 2 + point.x,        height / 2 + point.y,   
                        }; //Texture on-screen position ( each vertex is x,y in on-screen coords )

    GLfloat             coordinates[] = {
        0,          1,
        1,          1,
        0,          0,
        1,          0
    }; // Texture coords from 0 to 1

    glBindVertexArrayOES(vao);
    glGenVertexArraysOES(1, &vao);
    glGenBuffers(2, vbo);

    //Buffer 1
    glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
    glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), position, GL_STATIC_DRAW);
    glEnableVertexAttribArray(ATTRIB_POSITION);
    glVertexAttribPointer(ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, position);

    //Buffer 2
    glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
    glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), coordinates, GL_DYNAMIC_DRAW);    
    glEnableVertexAttribArray(ATTRIB_TEXCOORD);
    glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, coordinates);

    //Draw
    glBindVertexArrayOES(vao);
    glBindTexture(GL_TEXTURE_2D, _name);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

In both cases I’m using this simple Vertex Shader

//Vertex Shader
attribute vec2 position;//Bound to ATTRIB_POSITION
attribute vec4 color; 
attribute vec2 texcoord;//Bound to ATTRIB_TEXCOORD

varying vec2 texcoordVarying;

uniform mat4 mvp;

void main()
{
    //You CAN'T use transpose before in glUniformMatrix4fv so... here it goes.
    gl_Position = mvp * vec4(position.x, position.y, 0.0, 1.0);
    texcoordVarying = texcoord;
}

The gl_Position is equal to product of mvp * vec4 because I’m simulating glOrthof in 2D with that mvp

And this Fragment Shader

//Fragment Shader
uniform sampler2D sampler;

varying mediump vec2 texcoordVarying;

void main()
{
    gl_FragColor = texture2D(sampler, texcoordVarying);
}

I really need help with this, maybe my shaders are wrong for the second case ?

thanks in advance.

  • 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-15T09:57:56+00:00Added an answer on May 15, 2026 at 9:57 am

    Everything is right, except the glVertexAttribPointer call.

    When you have a VBO bound, the last parameter o glVertexAttribPointer is used as an offset into the VBO, as a pointer (the pointer value is the offset). So, your data is at the start of the VBO, so the last parameter should be 0 (NULL) for both calls.

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

Sidebar

Related Questions

Hello I am trying to create a stacked barplot using the following code: test
Hello everyone i am trying to format the input number range with php number_format
hello friends i am trying to get a list of user id and want
Hello Guys I am trying to figure out why i am gettings this error
Hello All I am trying to flatten a list in Ocaml. I am a
Hello There, I am new to phonegap.I am trying to record a audio clip
. Hello, I am trying to add a UIButton and other items to my
. Hello, I am trying to make a Custom Segue for my storyboard. Now
Hello everyone i am developing an quiz based app in android and i have
Hello i am trying to check to see if there is a row in

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.