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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:39:53+00:00 2026-05-22T18:39:53+00:00

I am using the LWJGL and drawing cubes with glBegin/glEnd , but I heard

  • 0

I am using the LWJGL and drawing cubes with glBegin/glEnd, but I heard this method is very inefficient and I should start using VBOs. I have no idea how that works.

I want to draw cubes of different sizes and positions (no rotation), and I think I should use VBOs for this.

Can anyone could give me some example code or insight on how to use VBOs with Java or even if VBOs are the best choice?

  • 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-22T18:39:54+00:00Added an answer on May 22, 2026 at 6:39 pm

    This is the code I wrote to test VBOs with Java. It uses JOGL instead of LWJGL, but that’s a minor thing.

    In addition to glVertexPointer you can also use glTexCoordPointer and glNormalPointer to specify data for texture coordinates and normals and enable them with glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) and glEnableClientState(GL.GL_NORMAL_ARRAY).

    import com.sun.opengl.util.*;
    
    import javax.media.opengl.*;
    import javax.swing.*;
    import java.nio.*;
    
    
    public class VBOTest implements GLEventListener {
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            GLCanvas canvas = new GLCanvas();
            canvas.addGLEventListener(new VBOTest());
            frame.add(canvas);
            frame.setSize(640, 480);
            frame.setVisible(true);
        }
    
        private FloatBuffer vertices;
        private ShortBuffer indices;
        private int VBOVertices;
        private int VBOIndices;
    
        public void init(GLAutoDrawable drawable) {
            float[] vertexArray = {-0.5f,  0.5f, 0,
                                    0.5f,  0.5f, 0,
                                    0.5f, -0.5f, 0,
                                   -0.5f, -0.5f, 0};
            vertices = BufferUtil.newFloatBuffer(vertexArray.length);
            vertices.put(vertexArray);
            vertices.flip();
    
            short[] indexArray = {0, 1, 2, 0, 2, 3};
            indices = BufferUtil.newShortBuffer(indexArray.length);
            indices.put(indexArray);
            indices.flip();
    
            GL gl = drawable.getGL();
            int[] temp = new int[2];
            gl.glGenBuffers(2, temp, 0);
    
            VBOVertices = temp[0];
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.capacity() * BufferUtil.SIZEOF_FLOAT,
                                vertices, GL.GL_STATIC_DRAW);
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
    
            VBOIndices = temp[1];
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, indices.capacity() * BufferUtil.SIZEOF_SHORT,
                                indices, GL.GL_STATIC_DRAW);
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
        }
    
        public void display(GLAutoDrawable drawable) {
            GL gl = drawable.getGL();
    
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
    
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBOVertices);
            gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, VBOIndices);
            gl.glDrawElements(GL.GL_TRIANGLES, indices.capacity(), GL.GL_UNSIGNED_SHORT, 0);
    
            gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
        }
    
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use LWJGL in an Eclipse RCP application, but either using the
I'm trying to start using LWJGL to display some 2D graphics. I've written using
I'm using Slick Util's Texture class to load textures for lwjgl, but apparently that
I am using this code to draw different cubes with different colors using the
Good day! I created jar file (using Netbeans) and i can't start it. This
I'm using LWJGL and Slick framework to load Textures to my OpenGL-application. I'm using
I have a SWT app that opens a OpenGL window (using the LWJGL library)
I'm using OpenAL via the LWJGL bindings http://www.lwjgl.org/javadoc/ . I need to know the
I'm trying to get a simple triangle drawn in Java using LWJGL. I'm trying
I'm using LWJGL. I'm trying to create a simple 3D map using GL_TRIANGLE_STRIP and

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.