好的,我有以下代码,我正在尝试将此代码转换为顶点缓冲区对象渲染方式。
但它似乎不起作用..
所以这里是代码:
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 并告诉我怎么做吗?
在此先感谢,
我很快接受:)