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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:46:34+00:00 2026-06-18T02:46:34+00:00

I’m working on my first steps with OpenGL (3.x) and I plan to use

  • 0

I’m working on my first steps with OpenGL (3.x) and I plan to use VAO & VBO’s to draw several figures (triangle, cube,…):

Now i got the following setup:

VAO –>
VBO [vertices, colors] + VBO [indices]

Where “vertices” has [3 * 3floats vertices of triangle, 8*3floats of cube],
“colors” has RGB per vertex (no alpha),
“indices” has [ triangle: 0,1,2, square: 0,1,2, 0,2,3, …]

Now if I draw using “glDrawElements”. i only see the first figure on the series drawn correctly (and getting the right color), the second one doesn’t works as it should.

So if i render the triangle data first, it goes like:

triangle then cube

And if i render the cube first, it goes like:

cube then triangle

Note: triangle is red, and cube is colourful, so the first figure is always shown as I expected

This worked ok drawing arrays with “glDrawArrays” (with offset + trianglecount) instead of drawElements but, of course, indexing makes the data arrays muuuuuch smaller. So i wanted to do the move.

How could i draw the same setup but with indexing? should i call another method?

This is the code I use to prepare the VBO’s data, in case of doubt.

// VBOS solid
    glBindBuffer(GL_ARRAY_BUFFER, vboSolid[0]);
    glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(GLfloat),&vertices[0], GL_STATIC_DRAW);
    glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, vboSolid[1]);
    glBufferData(GL_ARRAY_BUFFER, colors.size()*sizeof(GLfloat),&colors[0], GL_STATIC_DRAW);
    glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(1);

    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, vboIndex );
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(GLuint),&indices[0], GL_STATIC_DRAW);
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );

And this is the call I do when rendering.
In this loop, the triangle would have indicesCount=3 & offset=0, while cube would have 24 & 3 respectively.

glDrawElements(
   GL_TRIANGLES,      
   primitives[i]->indicesCount,    
   GL_UNSIGNED_INT,  
   (void*) (primitives[i]->offsetIndices*sizeof(GLuint))   
);
  • 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-18T02:46:35+00:00Added an answer on June 18, 2026 at 2:46 am

    Since i was still testing after posting, i finally made a working attempt, using:

    glDrawElementsBaseVertex(
       GL_TRIANGLES.
       __INDICES_TO_RENDER__,
       GL_UNSIGNED_INT,
       (void*) (__INDICES_RENDERED___*sizeof(GLuint)),
       _VERTICES_RENDERED_BEFORE_   
    );
    

    where “INDICES_TO_RENDER” and “INDICES_RENDERED_” are values counting 3f, so for a cube you use 24floats as value “TO_RENDER”, and 0 to “_RENDERED”.

    “_VERTICES_RENDERED_BEFORE_” worked being a human value of vertices rendered, so before cube is rendered, it is 0, after, it should be 8.

    Kinda weird (probably i did something wrong), but it worked in my tests:

    wooot

    It was said at Using an offset with VBOs in OpenGL, but i tried several times till i found what to put into the call.

    If an expert could verify this, i would be happier :P.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.