Please login or register.

Login with username, password and session length
Pages: [1] 2 3 ... 10
 on: March 15, 2018, 15:47:02 
Started by Misterpin - Last post by Misterpin
Hello everyone!
Can you ever add a bindings to the PhysX SDK in your spare time? (If it's not difficult and if it hasn't C++ api).
Thanks a lot!

Or if it's C ++ api, then can I add the ability to do C ++ bindings in a LWJGL generator?

 on: March 13, 2018, 07:20:47 
Started by TLHPoE - Last post by Andrew Alfazy
I'm new too but may be the problem in fragment shader
Code: [Select]
out_Color = pass_Color;
out_Color = texture(texture_diffuse, pass_UV);
first you set the out color to be  pass_Color than set it again to be texture(texture_diffuse, pass_UV).
You must add values.
Code: [Select]
out_Color = pass_Color + texture(texture_diffuse, pass_UV);the final code
Code: [Select]
#version 150 core
uniform sampler2D texture_diffuse;
in vec4 pass_Color;
in vec2 pass_UV;
out vec4 out_Color;
out vec2 out_UV;
void main() {
    out_Color = pass_Color + texture(texture_diffuse, pass_UV);

 on: March 12, 2018, 18:42:42 
Started by TLHPoE - Last post by TLHPoE
My current goal is to render a quad with colors, but currently my quad is drawn as completely white. I am using the "modern method," with each vertex's position and color being interleaved into one VBO. The quad is being drawn correctly, but the entire quad is white. I have tried enabling blending and alpha.

My code is based around the tutorials found on the LWJGL wiki, with a few minor adjustments:
  • My loop is found in my main class; the majority of my rendering code has been isolated to my QuadRendering class
  • I load the element buffer in the very beginning and reuse it for every draw
  • My vertex class is condensed with the order x, y, z, r, g, b, a
  • Removed the magic numbers that the tutorial used to identify attributes; I defined them at the top of my QuadRendering class

I am relatively new to OpenGL, so any comments on how I structure things or my interpretation of the functions are appreciated.

Here is my code,

Main Render Method:
Code: [Select]
private void render(double dT) {
try(MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1);
IntBuffer pHeight = stack.mallocInt(1);

glfwGetWindowSize(window, pWidth, pHeight);

glViewport(0, 0, pWidth.get(0), pHeight.get(0));




Code: [Select]
package com.kain.gp1;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;

import java.nio.*;

import org.lwjgl.*;
import org.lwjgl.opengl.*;

import com.kain.gp1.render.*;

public class QuadRendering {
public static final int POSITION = 0, COLOR = 1;

public static int quadIndicesVBOID, quadIndexCount;

public static void preloadData() {
byte[] indices = {
0, 1, 2,
2, 3, 0

quadIndexCount = indices.length;

ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(quadIndexCount);

quadIndicesVBOID = glGenBuffers();

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadIndicesVBOID);


public static void render(double dT) {
int vaoID = GL30.glGenVertexArrays();
int vboID = GL15.glGenBuffers();

FloatBuffer verticesBuffer = Vertex.combineVertices(
new Vertex(-0.5F, 0.5F, 0F, 1F, 0F, 0F, 1F),
new Vertex(-0.5F, -0.5F, 0F, 0F, 1F, 0F, 1F),
new Vertex(0.5F, -0.5F, 0F, 0F, 0F, 1F, 1F),
new Vertex(0.5F, 0.5F, 0F, 1F, 1F, 1F, 1F));

//Data variables created
//Now to send the data to the GPU


glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STATIC_DRAW);

glVertexAttribPointer(POSITION, Vertex.XYZ_SIZE, GL_FLOAT, false, Vertex.TOTAL_BYTE_SIZE, 0);
glVertexAttribPointer(COLOR, Vertex.COLOR_SIZE, GL_FLOAT, false, Vertex.TOTAL_BYTE_SIZE, Vertex.XYZ_BYTE_SIZE);

glBindBuffer(GL_ARRAY_BUFFER, 0);

//Data sent to the GPU
//Now to draw

glEnable(GL_BLEND); //These 2 methods are my attempts to get any color to appear



glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadIndicesVBOID);

glDrawElements(GL_TRIANGLES, quadIndexCount, GL_UNSIGNED_BYTE, 0);




//After drawing, we have to dispose of the variables


public static void dispose() {

Code: [Select]
package com.kain.gp1.render;

import java.nio.*;

import org.lwjgl.system.*;

public class Vertex {
public static int XYZ_SIZE = 3, COLOR_SIZE = 4, TOTAL_SIZE = XYZ_SIZE + COLOR_SIZE;
public static int FLOAT_BYTE_SIZE = 4;

public float[] xyz, color, uv;

public Vertex(float x, float y, float z, float r, float g, float b, float a) {
setXYZ(x, y, z);
setColor(r, g, b, a);

public Vertex setXYZ(float x, float y, float z) {
xyz = new float[] { x, y, z };

return this;

public Vertex setColor(float r, float g, float b, float a) {
color = new float[] { r, g, b, a };

return this;

public FloatBuffer toFloatBuffer() {
FloatBuffer buf = MemoryUtil.memCallocFloat(TOTAL_SIZE);


return buf;

public static FloatBuffer combineVertices(Vertex... vertices) {
FloatBuffer verticesBuf = MemoryUtil.memAllocFloat(TOTAL_SIZE * vertices.length);

for(Vertex vertex : vertices) {


return verticesBuf;

Code: [Select]
package com.kain.gp1.shader;

import static org.lwjgl.opengl.GL20.*;

import java.io.*;
import java.nio.charset.*;
import java.nio.file.*;

import com.kain.gp1.*;

public class ShaderProgram {
public final int programID, vsID, fsID;

public ShaderProgram() throws Exception {
programID = glCreateProgram();

if(programID == 0) {
throw new Exception("Could not create Shader");

vsID = createShader(getFileText("./res/vertex.vs"), GL_VERTEX_SHADER);
fsID = createShader(getFileText("./res/fragment.fs"), GL_FRAGMENT_SHADER);

public void link() throws Exception {

if(glGetProgrami(programID, GL_LINK_STATUS) == 0) {
throw new Exception("Error linking shader program: " + glGetProgramInfoLog(programID, 1024));

if(vsID != 0) {
glDetachShader(programID, vsID);

if(fsID != 0) {
glDetachShader(programID, fsID);


if(glGetProgrami(programID, GL_VALIDATE_STATUS) == 0) {
System.err.println("Warning validating shader code: " + glGetProgramInfoLog(programID, 1024));

public void bind() {

public void unbind() {

public void dispose() {

if(programID != 0) {

private int createShader(String shaderCode, int shaderType) throws Exception {
int shaderID = glCreateShader(shaderType);

if(shaderID == 0) {
throw new Exception("Error creating shader. Type: " + shaderType);

glShaderSource(shaderID, shaderCode);

if(glGetShaderi(shaderID, GL_COMPILE_STATUS) == 0) {
throw new Exception("Error compiling shader code: " + glGetShaderInfoLog(shaderID, 1024));

glBindAttribLocation(programID, QuadRendering.POSITION, "in_Position");
glBindAttribLocation(programID, QuadRendering.COLOR, "in_Color");

glAttachShader(programID, shaderID);

return shaderID;

private String getFileText(String file) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(file));

return new String(encoded, StandardCharsets.UTF_8);

Vertex Shader:
Code: [Select]
#version 150 core

in vec4 in_Position;
in vec4 in_Color;
in vec2 in_UV;

out vec4 pass_Color;
out vec2 pass_UV;

void main() {
gl_Position = in_Position;

pass_Color = in_Color;

pass_UV = in_UV;

Fragment Shader:
Code: [Select]
#version 150 core

uniform sampler2D texture_diffuse;

in vec4 pass_Color;
in vec2 pass_UV;

out vec4 out_Color;
out vec2 out_UV;

void main() {
out_Color = pass_Color;

out_Color = texture(texture_diffuse, pass_UV);

 on: March 10, 2018, 17:06:11 
Started by Misterpin - Last post by Misterpin
I found the Oculus SDK example!

 on: March 10, 2018, 16:35:48 
Started by Misterpin - Last post by spasi
The example doesn't do anything exciting, except verify that there's no serious problem with the binding implementation. I do not own an Oculus Rift, so there's no way I could write an interesting demo. An LWJGL user could contribute one, but that hasn't happened so far.

 on: March 10, 2018, 15:53:40 
Started by Misterpin - Last post by Misterpin
Excuse me!
In the LWJGL examples, what does the LibOVR example do? How can I make a simple application that is completely ready for rendering without a great deal of time?

 on: March 08, 2018, 15:33:51 
Started by Misterpin - Last post by spasi
First of all, read Memory management in LWJGL 3.

The methods that struct classes support for creating new instances (using GLFWImage as an example):

Code: [Select]
// Constructor, struct backed by whatever memory is backing the specified container
GLFWImage(ByteBuffer container)

// Uses memAlloc to allocate an uninitialized struct. The struct must be freed explicitly.
GLFWImage GLFWImage.malloc()
// Uses memCalloc to allocate a zero-filled struct. The struct must be freed explicitly.
GLFWImage GLFWImage.calloc()
// Uses ByteBuffer.allocateDirect to allocate a zero-filled struct
GLFWImage GLFWImage.create()
// Returns a struct that wraps the specified pointer address (unsafe)
GLFWImage GLFWImage.create(long address)

// Same as above, but an array of structs is returned
GLFWImage.Buffer GLFWImage.malloc(int capacity)
GLFWImage.Buffer GLFWImage.calloc(int capacity)
GLFWImage.Buffer GLFWImage.create(int capacity)
GLFWImage.Buffer GLFWImage.create(long address, int capacity)

// Same as above, but the struct is backed by "stack" memory. If the current stack frame goes away, the struct goes away automatically.
GLFWImage GLFWImage.mallocStack(MemoryStack stack)
GLFWImage GLFWImage.callocStack(MemoryStack stack)
GLFWImage.Buffer GLFWImage.mallocStack(int capacity, MemoryStack stack)
GLFWImage.Buffer GLFWImage.callocStack(int capacity, MemoryStack stack)

You may use any of the above, depending on the use-case. It helps to have a good mental model of the methods that allocate memory. In terms of performance, from fastest to slowest:

- mallocStack
- callocStack
- malloc
- calloc
- create

And in terms of convenience, from more easiest to hardest:

- create (GCed automatically)
- malloc/callocStack (use the MemoryStack API to manage "stack frames", usually with try-with-resources blocks)
- malloc/calloc (must call .free() explicitly when the memory is no longer used)

 on: March 08, 2018, 15:23:00 
Started by Andrew Alfazy - Last post by Andrew Alfazy
thanks for your replay I've found the problems. stupid mistakes from me.sorry  :-[

 on: March 08, 2018, 15:16:23 
Started by Misterpin - Last post by Misterpin
Good afternoon!
I notice that each class has a constructor called Testclass(ByteBuffer container). And how can I create NkImage, STBImage, GLFWImage?
And how can I create NkContext instance?

 on: March 08, 2018, 15:06:42 
Started by Andrew Alfazy - Last post by spasi
Please make sure you aren't getting any OpenGL errors before the crash. Use:

Code: [Select]
// before creating the window/context

// after the call to GL.createCapabilities();

If that doesn't help, try LWJGLX/debug.

Pages: [1] 2 3 ... 10