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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:00:58+00:00 2026-06-17T02:00:58+00:00

In my application, I’m having to draw multiple elements with OpenGL, some are Triangles

  • 0

In my application, I’m having to draw multiple elements with OpenGL, some are Triangles and others are Line Strips. I’m putting my vertices into multiple float[] and my indices into multiple short[] whenever I am to draw a new shape. I also have to create a new FloatBuffer, ShortBuffer and ByteBuffer for each new array in order to make it work.

How could I more efficiently draw the multiple elements? I was thinking of putting all of the vertices into a single float[] and creating a new short[] for each element to remove excess arrays, but is it possible to use one FloatBuffer, ShortBuffer and put all of the arrays into a single ByteBuffer such as this:

float[] vertices = { -3, -3, -3, 2, 3, 0, 2, -1, 0, 0, 5, 2, 3, 1 };
short[] indItemA = { 0, 1, 2, 0, 2, 3 };
short[] indItemB = { 4, 5, 6 };

FloatBuffer fBuff;
ShortBuffer sBuff;

ByteBuffer bBuff = ByteBuffer.allocateDirect(vertices.length * 4);
fbBuff.order(ByteOrder.nativeOrder());

fBuff = bBuff.asFloatBuffer();
fBuff.put(vertices);
fBuff.position(0);

sBuff = bBuff.asShortBuffer();
sBuff.put(indItemA);
sBuff.position(0);

sBuff.put(indItemB);
sBuff.position(0);
  • 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-17T02:00:59+00:00Added an answer on June 17, 2026 at 2:00 am

    glBufferData sends the data from the buffer to the graphics card’s memory. You can do whatever you want with the ByteBuffer after that call and it wont effect the data already sent.

    Therefore if your aim is to reduce the number of ByteBuffers you create, you could just create one large ByteBuffer that is used for everything. Just reset the pointer of the buffer, write the data, send it to the graphics card and repeat.

    // Do this once
    ByteBuffer bBuff = ByteBuffer.allocateDirect( someBigNumber );
    bBuff.order(ByteOrder.nativeOrder());
    FloatBuffer fBuff = bBuff.asFloatBuffer();
    ShortBuffer sBuff = bBuff.asFloatBuffer();
    
    // Do this for each shape
    fBuff.position(0);
    fBuff.put(vertices);
    fBuff.position(0);
    
    glBindBuffer( GL_ARRAY_BUFFER, vertexbuffer );
    glBufferData( GL_ARRAY_BUFFER, vertices.length * 4, fBuff, GL_STATIC_DRAW );
    
    sBuff.position( 0 );
    sBuff.put( indices );
    sBuff.position( 0 );
    
    glBindBuffer( GL_ARRAY_BUFFER, indexbuffer );
    glBufferData( GL_ARRAY_BUFFER, indices.length * 2, sBuff, GL_STATIC_DRAW );
    

    If your vertex and index data is static, you could just put the vertex data for every shape into one buffer object and all the index data into another then use the offset parameter of glVertexPointer and glIndexPointer to specify where in the buffer object the data begins.

    It sounds like you generate custom shapes at runtime though, so you could just re-use the ByteBuffer and store each shape in a separate buffer object like the sample above.

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

Sidebar

Related Questions

Application-Stack: Rails3, CanCan, Devise, Shoulda I've got some nested Resources and want to test
Application I am developing does some kind of server-side authorization. Communication is done via
My application is written in delphi. For some reason the main menu does not
Application c:\pinkPanther.exe is running and it is application i wrote in c#. Some other
Application flow An input file consists of multiple logical documents. Extract one input logical
Application.Run(new Main()); This line gives TypeInitializationException was unhandled after I switched from 3.5 to
Application crashed at line .... [AppDel.engine getFollowedTimelineSinceID:1 startingAtPage:1 count:100]; [AppDel.engine sendUpdate:textView.text]; Please help me
application uses codeigniter and tank_auth with it. I need to add some more data
Application, have a TextBlock and two Buttons, the text is displayed TextBlock by clicking
Application: WPF Application consisting of a textbox on top and a listbox below Users

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.