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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:08:35+00:00 2026-05-13T11:08:35+00:00

I tried to implement Open GLs Vertex Buffer Objects the first time, and all

  • 0

I tried to implement Open GLs Vertex Buffer Objects the first time, and all i get is a black screen.

I tried it with glOrtho instead of glPerspective, but it didnt work as well.

thanks for helping

Heres my code:

public class VBufferTest {

 public static final int WIN_WIDTH = 640;
 public static final int WIN_HEIGHT = 480;
 public int vBufferId;

 public static void main(String args[]){
  VBufferTest foo = new VBufferTest();
  foo.initLWJGLFrame();
  foo.initBuffer();
  while (!Display.isCloseRequested()){
   foo.render();
  }
 }

 public void initLWJGLFrame(){
  try {
        DisplayMode[] possible = Display.getAvailableDisplayModes();
        DisplayMode chosen = null;
        for (int i = 0; i < possible.length; i += 1){
          if (possible[i].getWidth() == WIN_WIDTH && possible[i].getHeight() == WIN_HEIGHT){
            chosen = possible[i];          
            break;
          }
        }
        if (chosen != null){
          Display.setDisplayMode(chosen);
          Display.setTitle("TestFrame1");
          Display.create();

        }
        else {
          throw new LWJGLException("Couldn't find the appropriate display mode.");
        }
      }
      catch (LWJGLException e){

      }
 }

 public void initGL(){
  GL11.glEnable(GL11.GL_DEPTH_TEST);
     GL11.glEnable(GL11.GL_TEXTURE_2D);
     GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
     GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
     GL11.glClearColor(104.f/255.0f, 136.0f/255.0f, 252.0f/255.0f, 1.0f);
     GL11.glMatrixMode(GL11.GL_PROJECTION);
     GL11.glLoadIdentity();
     GLU.gluPerspective(50.0f, Display.getDisplayMode().getWidth()/Display.getDisplayMode().getHeight(), 0.5f, 1000.0f);

     GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
     GL11.glMatrixMode(GL11.GL_MODELVIEW);
     GL11.glLoadIdentity();
 }
  public void initBuffer(){
   FloatBuffer vertices = BufferUtils.createFloatBuffer(4*3);
   vBufferId = genNewId();
   vertices.put(new float[]{-1.0f, -1.0f, 0.0f});
   vertices.put(new float[]{1.0f, -1.0f, 0.0f});
   vertices.put(new float[]{1.0f, 1.0f, 0.0f});
   vertices.put(new float[]{-1.0f, 1.0f, 0.0f});
   vertices.flip();
   bufferData(vBufferId, vertices);
  }

  public void render(){
   GL11.glColor3f(1.0f, 0.0f, 1.0f);
   ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, this.vBufferId);
   GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
   GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
   Display.update();
  }

  public static int genNewId(){
      IntBuffer buffer = BufferUtils.createIntBuffer(1);
      ARBVertexBufferObject.glGenBuffersARB(buffer);
      return buffer.get(0);
    }


    public static void bufferData(int id, FloatBuffer buffer){
      ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
      ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
    }
}
  • 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-13T11:08:35+00:00Added an answer on May 13, 2026 at 11:08 am

    You have depth-testing enabled, but you don’t clear the z-buffer once per frame using glClear (at the beginning of your render method). Same for clearing the color buffer.

    EDIT: Also, initGl() seems to be never called?

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I used this hack to fix error: ... Uri hacked_uri… May 16, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer What you are doing is not actually getting a new… May 16, 2026 at 4:25 pm
  • Editorial Team
    Editorial Team added an answer In .Net, type resolution is based on the assembly name,… May 16, 2026 at 4:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Today i tried to implement the owner drawn menu item support in Cocoa and
I have tried to implement Stack Overflow question C++ Data Member Alignment and Array Packing
I have tried to implement a program using sockets in Ubuntu 10.04. Here is
I'm trying to experiment with software defined radio concepts. From this article I've tried
I want to implement the same behaviour of the notification view in the official
I have just received a requirement to implement spell checking on a web application
I'm trying to find a way to implement file manager functionality in an mvc
Here is the code below I tried this call but it didnt work... even
I would like to make a list-detail view with richfaces. There will be a
I'm trying to embed a PDF file into a Word document using the OLE

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.