use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.
the class PhotonMappingDemo method createSceneVao.
/**
* Creates a VAO for the scene.
*/
private void createSceneVao() {
int vao = glGenVertexArrays();
/* Create vertex data */
int vbo = glGenBuffers();
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
ByteBuffer bb = BufferUtils.createByteBuffer(4 * (3 + 3) * 6 * 6);
FloatBuffer fv = bb.asFloatBuffer();
DemoUtils.triangulateUnitBox(fv);
glBufferData(GL_ARRAY_BUFFER, bb, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 4 * (3 + 3), 0L);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, false, 4 * (3 + 3), 4 * 3);
glBindBuffer(GL_ARRAY_BUFFER, 0);
/* Create per instance data (position and size of box) */
int ivbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, ivbo);
bb = BufferUtils.createByteBuffer(4 * (3 + 3) * boxes.length);
fv = bb.asFloatBuffer();
for (int i = 0; i < boxes.length; i += 2) {
Vector3f min = boxes[i];
Vector3f max = boxes[i + 1];
fv.put((max.x + min.x) / 2.0f).put((max.y + min.y) / 2.0f).put((max.z + min.z) / 2.0f);
fv.put((max.x - min.x) / 2.0f).put((max.y - min.y) / 2.0f).put((max.z - min.z) / 2.0f);
}
glBufferData(GL_ARRAY_BUFFER, bb, GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, false, 4 * (3 + 3), 0L);
glVertexAttribDivisor(2, 1);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, false, 4 * (3 + 3), 4 * 3);
glVertexAttribDivisor(3, 1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
this.vaoScene = vao;
}
use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.
the class PhotonMappingDemo method createSceneSSBO.
/**
* Create a Shader Storage Buffer Object which will hold our boxes to be
* read by our Compute Shader.
*/
private void createSceneSSBO() {
this.ssbo = glGenBuffers();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4) * boxes.length / 2);
FloatBuffer fv = ssboData.asFloatBuffer();
for (int i = 0; i < boxes.length; i += 2) {
Vector3f min = boxes[i];
Vector3f max = boxes[i + 1];
/*
* NOTE: We need to write vec4 here, because SSBOs have specific
* alignment requirements for struct members (vec3 is always treated
* as vec4 in memory!)
*
* See:
* "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
*/
fv.put(min.x).put(min.y).put(min.z).put(0.0f);
fv.put(max.x).put(max.y).put(max.z).put(0.0f);
}
glBufferData(GL_SHADER_STORAGE_BUFFER, ssboData, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.
the class DemoSsbo method createSceneSSBO.
/**
* Create a Shader Storage Buffer Object which will hold our boxes to be
* read by our Compute Shader.
*/
private void createSceneSSBO() {
this.ssbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, ssbo);
ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4) * boxes.length / 2);
FloatBuffer fv = ssboData.asFloatBuffer();
for (int i = 0; i < boxes.length; i += 2) {
Vector3f min = boxes[i];
Vector3f max = boxes[i + 1];
/*
* NOTE: We need to write vec4 here, because SSBOs have specific
* alignment requirements for struct members (vec3 is always treated
* as vec4 in memory!)
*
* See:
* "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
*/
fv.put(min.x).put(min.y).put(min.z).put(0.0f);
fv.put(max.x).put(max.y).put(max.z).put(0.0f);
}
glBufferData(GL_ARRAY_BUFFER, ssboData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.
the class SpaceGame method drawHudShip.
private void drawHudShip() {
glUseProgram(0);
Ship enemyShip = ships[shootingShip];
if (enemyShip == null)
return;
Vector3f targetOrigin = tmp2;
targetOrigin.set((float) (enemyShip.x - cam.position.x), (float) (enemyShip.y - cam.position.y), (float) (enemyShip.z - cam.position.z));
tmp3.set(tmp2);
viewMatrix.transformPosition(targetOrigin);
boolean backward = targetOrigin.z > 0.0f;
if (backward)
return;
projMatrix.transformProject(targetOrigin);
if (targetOrigin.x < -1.0f)
targetOrigin.x = -1.0f;
if (targetOrigin.x > 1.0f)
targetOrigin.x = 1.0f;
if (targetOrigin.y < -1.0f)
targetOrigin.y = -1.0f;
if (targetOrigin.y > 1.0f)
targetOrigin.y = 1.0f;
float crosshairSize = 0.03f;
float xs = crosshairSize * height / width;
float ys = crosshairSize;
crosshairVertices.clear();
crosshairVertices.put(targetOrigin.x - xs).put(targetOrigin.y - ys);
crosshairVertices.put(targetOrigin.x + xs).put(targetOrigin.y - ys);
crosshairVertices.put(targetOrigin.x + xs).put(targetOrigin.y + ys);
crosshairVertices.put(targetOrigin.x - xs).put(targetOrigin.y + ys);
crosshairVertices.flip();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glVertexPointer(2, GL_FLOAT, 0, crosshairVertices);
glDrawArrays(GL_QUADS, 0, 4);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Draw distance text of enemy
int quads = stb_easy_font_print(0, 0, Integer.toString((int) (tmp3.length())), null, charBuffer);
glVertexPointer(2, GL_FLOAT, 16, charBuffer);
glPushMatrix();
// Scroll
glTranslatef(targetOrigin.x, targetOrigin.y - crosshairSize * 1.1f, 0f);
float aspect = (float) width / height;
glScalef(1.0f / 500.0f, -1.0f / 500.0f * aspect, 0.0f);
glDrawArrays(GL_QUADS, 0, quads * 4);
glPopMatrix();
}
use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.
the class Cubes method frame.
@Override
protected void frame(float time, float frameTime) {
bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/01-cubes");
bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Rendering simple static mesh.");
bgfx_dbg_text_printf(0, 3, 0x0f, String.format("Frame: %7.3f[ms]", frameTime));
BGFXDemoUtil.lookAt(new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.0f, 0.0f, -35.0f), view);
BGFXDemoUtil.perspective(60.0f, getWindowWidth(), getWindowHeight(), 0.1f, 100.0f, proj);
view.get(viewBuf);
proj.get(projBuf);
bgfx_set_view_transform(0, viewBuf, projBuf);
long encoder = bgfx_begin();
for (int yy = 0; yy < 11; ++yy) {
for (int xx = 0; xx < 11; ++xx) {
model.identity().translate(-15.0f + xx * 3.0f, -15.0f + yy * 3.0f, 0.0f).rotateAffineXYZ(time + xx * 0.21f, time + yy * 0.37f, 0.0f);
model.get(modelBuf);
bgfx_encoder_set_transform(encoder, modelBuf);
bgfx_encoder_set_vertex_buffer(encoder, 0, vbh, 0, 8);
bgfx_encoder_set_index_buffer(encoder, ibh, 0, 36);
bgfx_encoder_set_state(encoder, BGFX_STATE_DEFAULT, 0);
bgfx_encoder_submit(encoder, 0, program, 0, false);
}
}
bgfx_end(encoder);
}
Aggregations