Java - 使用顶点缓冲对象(vbo)LWJGL

时间:2013-10-14 16:45:27

标签: java opengl lwjgl vbo slick2d

好的,我有以下代码,我试图将此代码转换为顶点缓冲区对象渲染方式。
但它似乎不起作用。
所以这是代码:

package com.game.base;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;

import java.nio.FloatBuffer;
import java.util.Random;

import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;

import com.game.display.graphics.Entity;

public class Game {

float speed = 0.0f;
float speedChange = 0.000001f;
int stars = 20000;
int starsDistance = 4000;
float starSize = 2.0f;
int vertices = 3;
int vertex_size = 3; // X, Y, Z,
int color_size = 3; // R, G, B,
Entity[] points;
Random random = new Random();

public Game() {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective((float) 60, (float) (MainClass.WIDTH / MainClass.HEIGHT), 0.001f, 100);
    glMatrixMode(GL_MODELVIEW);

    glEnable(GL_DEPTH_TEST);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    points = new Entity[stars];
    for (int i = 0; i < points.length; i++) {
        points[i] = new Entity((random.nextFloat() - 0.5f) * 100f, (random.nextFloat() - 0.5f) * 100f, random.nextInt(starsDistance) - starsDistance);
    }
}

public void render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glTranslatef(0, 0, speed);

    glPointSize(2.0f);
    glBegin(GL_POINTS);
    for (Entity p : points) {
        glVertex3f(p.x, p.y, p.z);
    }
    glEnd();
}

public void update() {

}

public void dispose() {

}

public void input() {
    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        speed += speed < 0 ? speedChange * 5 : speedChange;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        speed -= speed > 0 ? speedChange * 5 : speedChange;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
        speed = 0f;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_C)) {
        speed = 0;
        glLoadIdentity();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        MainClass.stop();
    }
}
}

有关如何将其转换为VBO(顶点缓冲区对象)的想法吗? 有人可以将其转换为VBO并告诉我如何?

先谢谢,
我接受快速:))

0 个答案:

没有答案