Hello Guest

Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Oh yeah! I actually found that on accident! Works really well for me
12
There is actually a binding

I have used it successfully and can confirm it works flawless (done a couple of graphic samples + compute)
13
Vulkan / Re: Vulkan gui ?
« Last post by elect on July 11, 2018, 16:00:07 »
Hi,

I'm working on the vk backend for imgui

Actually I was almost ready when Omar (the author of the original) did a huge examples refractoring..

This slowed me down a bit because I was already working on that and at the end I preferred to start again from scratch

Still a couple of days I guess..  but would you maybe be available to help?
14
Vulkan / Vulkan gui ?
« Last post by ealrann on July 11, 2018, 13:44:13 »
Hello,

I played with vulkan (LWJGL binding of course  ;D) for a while, but not really with GUI.

So I'm trying to use ImGui right now, but still curious ; what is your opinion ? what are the best APIs for GUI theses days for vulkan/LWJGL ?
15
OpenGL / Re: LWJGL 2 - glReadPixel and Pbo Asynchronous read
« Last post by Thiird on July 10, 2018, 08:37:22 »
Thanks it works!
16
OpenGL / Re: LWJGL 2 - glReadPixel and Pbo Asynchronous read
« Last post by spasi on July 09, 2018, 15:54:17 »
OpenGL rendering is double-buffered. Afaict, with your current setup you end up reading the color pass of the previous frame. Try changing glReadBuffer(GL_FRONT) to glReadBuffer(GL_BACK), it should let you read the ID pass of the current frame.
17
OpenGL / Re: LWJGL 2 - glReadPixel and Pbo Asynchronous read
« Last post by Thiird on July 08, 2018, 20:21:40 »
Quote
[edit] never mind, misread

Is my post unclear?
18
OpenGL / Shader compiles but vertices not drawn to window
« Last post by smithy545 on July 08, 2018, 20:04:26 »
I'm new to OpenGL programming so right now I'm just trying to get a simple shader to display a 2-dimensional red triangle. Using various tutorials I've pieced together a program that I think should work but there seems to be a problem with the shader. When I comment out the glUseProgram line I see a white triangle where it's supposed to be according to the obj file vertices. However, when I put the glUseProgram line back in the code compiles successfully but all I get is a black screen. I've attached the shader files. Below is the render method and methods I use to separately load the shaders and compile them into a program.

Code: [Select]
private int loadShader(String shaderFile, int type) {
// read the shader file
ByteBuffer source;
try {
FileInputStream fis = new FileInputStream(shaderFile);
FileChannel fc = fis.getChannel();
source = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
fc.close();
fis.close();
} catch(FileNotFoundException ex) {
throw new AssertionError("Could not find file \"" + shaderFile + "\"");
} catch(IOException ex) {
throw new AssertionError("Error reading file \"" + shaderFile + "\"");
}

// compile the shader
int shader = glCreateShader(type);
PointerBuffer strings = BufferUtils.createPointerBuffer(1);
IntBuffer lengths = BufferUtils.createIntBuffer(1);
strings.put(0, source);
lengths.put(0, source.remaining());

// check the shader
glShaderSource(shader, strings, lengths);
glCompileShader(shader);
int compiled = glGetShaderi(shader, GL_COMPILE_STATUS);
String shaderLog = glGetShaderInfoLog(shader);
if (shaderLog != null && shaderLog.trim().length() > 0) {
System.err.println(shaderLog);
}
if (compiled == 0) {
throw new AssertionError("Could not compile shader");
}
return shader;
}

public void init() {
// normal glfw init and vertices loaded here but that's cut out because I know that works

// creating the program
String vertexShaderFile = "res/spaceship.vs";
int vertexShader = loadShader(vertexShaderFile, GL_VERTEX_SHADER);
String fragmentShaderFile = "res/spaceship.fs";
int fragmentShader = loadShader(fragmentShaderFile, GL_FRAGMENT_SHADER);

// compile the program
int program = glCreateProgram();
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glLinkProgram(program);

// check the program
int linked = glGetProgrami(program, GL_LINK_STATUS);
String programLog = glGetProgramInfoLog(program);
if(programLog != null && programLog.trim().length() > 0) {
System.err.println(programLog);
}
if(linked == 0) {
throw new AssertionError("Could not link program");
}

// this is a member variable
programId = program;

        // Set the clear color
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

}

public void render() {
glfwPollEvents();

glViewport(0, 0, fbWidth, fbHeight);

glClear(GL_COLOR_BUFFER_BIT);

// trying to display in 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);

// "programId" member variable
int program = programId;

// use shader
glUseProgram(program);

// vertex pos attribute buffer
glEnableVertexAttribArray(0);
// "vertices" is a member variable that I know works when glUseProgram(program) is commented out
glBindBuffer(GL_ARRAY_BUFFER, vertices);
glVertexAttribPointer(
0,          // index
2,           // size
GL_FLOAT,         // type
false,  // normalized?
0,          // stride
0          // offset
);

// This DOESN'T work and displays nothing on the screen unless the program is cleared
glDrawArrays(GL_TRIANGLES, 0, numVertices);

// free attrib arrays and clear program
glDisableVertexAttribArray(0);
glUseProgram(0);

// Since the program is cleared this DOES WORK and displays a white triangle at the specified coordinates
glBegin(GL_TRIANGLES);
glVertex2f(10, 10);
glVertex2f(10, 100);
glVertex2f(100, 10);
glEnd();

// swap screen buffers
glfwSwapBuffers(window);
}

And here are the simple shader files.

vertex shader:
spaceship.vs
Code: [Select]
#version 330

layout(location = 0) in vec2 vertexPosition_modelspace;

void main() {
  gl_Position = vec4(vertexPosition_modelspace, 0.0, 1.0);
}

fragment shader:
spaceship.fs
Code: [Select]
#version 330

out vec3 color;

void main() {
  color = vec3(1,0,0);
}
19
OpenGL / Re: LWJGL 2 - glReadPixel and Pbo Asynchronous read
« Last post by CoDi on July 08, 2018, 16:48:20 »
[edit] never mind, misread
20
OpenGL / LWJGL 2 - glReadPixel and Pbo Asynchronous read
« Last post by Thiird on July 08, 2018, 13:45:45 »
So I've been trying to implement the Pbo asynchronous read in order to pick objects in 3d space by first rendering an Id pass and then the normal color pass, to do that I used the last section of this article http://www.songho.ca/opengl/gl_pbo.html#pack
I implement the code as follows:

Main class:
Code: [Select]
PBOManager PBOManager = new PBOManager();

// Main game loop
while (!Display.isCloseRequested())
{
// Capturing inputs to move the camera
viewMat = camera.move();

//Render with id shader
MasterRenderer.renderIdView = true;
renderer.renderScene(light, viewMat, camera.getPosition());
PBOManager.readPixelData();

MasterRenderer.renderIdView = false;

//Render with normal shader
renderer.renderScene(light, viewMat, camera.getPosition());
PBOManager.readPixelData();

        //Display the normal shader
display.update();
}

PBOManager.cleanUp();


And the PBOManager class looks like this:

Code: [Select]
package Render_engine;

import java.nio.ByteBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL21;

public class PBOManager
{
private static final int BYTES_PER_PIXEL = 4;
private int pbos[];
private int index = 0;
private int nextIndex = 1;

public static ByteBuffer buffer;

public PBOManager()
{
buffer = BufferUtils.createByteBuffer(BYTES_PER_PIXEL);

initPbos(2);
}

private void initPbos(int count)
{
this.pbos = new int[count];

for (int i = 0; i < pbos.length; i++)
{
this.pbos[i] = createPbo();
}
}

private int createPbo()
{
int pbo = GL15.glGenBuffers();

GL15.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, pbo);

GL15.glBufferData(GL21.GL_PIXEL_PACK_BUFFER, BYTES_PER_PIXEL, GL15.GL_STREAM_READ);

GL15.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, 0);

return pbo;
}

public void readPixelData()
{
// "index" is used to read pixels from framebuffer to a PBO
// "nextIndex" is used to update pixels in the other PBO

// set the target framebuffer to read
GL11.glReadBuffer(GL11.GL_FRONT);

// read pixels from framebuffer to PBO
// glReadPixels() should return immediately.
GL15.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, this.pbos[this.index]);

GL11.glReadPixels(Mouse.getX(), Mouse.getY(), 1, 1, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, 0);

// map the PBO to process its data by CPU
GL15.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, this.pbos[this.nextIndex]);
buffer = GL15.glMapBuffer(GL21.GL_PIXEL_PACK_BUFFER, GL15.GL_READ_ONLY, buffer);

//If buffer not empty (will be empty only on first frame)
if (buffer != null && buffer.hasRemaining())
{
this.printCurrentPixelColor();

GL15.glUnmapBuffer(GL21.GL_PIXEL_PACK_BUFFER);
}

// back to conventional pixel operation
GL15.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, 0);

this.index = (this.index + 1) % 2;
this.nextIndex = (this.index + 1) % 2;
}

private void printCurrentPixelColor()
{
while (buffer.hasRemaining())
{
System.out.print(((int) buffer.get() & 0xFF) + ":");
}

System.out.println();
}

public void cleanUp()
{
GL15.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, 0);

for (int pbo : this.pbos)
{
GL15.glDeleteBuffers(pbo);
}
}
}

As you can see the readPixelData() method is the same snippet of code at the bottom of the article, just translated to java.

With this setup I see the normal colors, which is what I want, but the colors detected are not from the id pass but from the normal color pass:
http://prntscr.com/k3x9wm

And if comment out the second render call in the main method I see the Id pass (of course) and the color detected is correct: http://prntscr.com/k3x9cm

So from what I can see I did some error in the code for which instead of, render the id, read the color and render the normal color, and process the previosuly read color, Im only able to read and process the pixel color of the last render call.

Is my diagnosis right?

Pages: 1 [2] 3 4 ... 10