Hello Guest

Recent Posts

Pages: 1 ... 8 9 [10]
OpenGL / Per mesh model matrices
« Last post by Mihai_Ionut_Floares on December 01, 2020, 10:20:43 »
I figured out the movementof the camera trough scene and the perspective/view/model matrices that I created from scratch sine I didn't want to use JOML. It is working: https://streamable.com/1exa27

But now I want to add another mesh, but the meshes share the same model matrix. The projection and view matrices should be the same, but the model should be different because when I translate one object, all meshes are translated. The matrices are sent to vertex shader, but I can't figure out how to make per mesh model matrices. I guess I need per mesh shaders???
OpenGL / Re: glDrawArrays causes coredump with SIGSEGV
« Last post by mikem on November 28, 2020, 15:14:07 »
OMG. That's embarrasing  :-[ Probably just choosen a wrong auto-complete item and it costed me hours of wondering.

Thank you! I see the triangle now. Also noted the glEnableVertexAttribArray remark. Thanks!
OpenGL / Re: glDrawArrays causes coredump with SIGSEGV
« Last post by KaiHH on November 28, 2020, 14:49:57 »
The error is with the call:
Code: [Select]
glVertexAttribPointer(0, 3, GL_FLAT, false, 0, 0);
This call is generating an OpenGL error (and its effect is therefore ignored), because you pass the invalid constant `GL_FLAT`. It should be `GL_FLOAT`.
This causes glDrawArrays() to access undefined memory (because the vertex buffer has not been specified as the vertex attribute source).

Besides that:
Code: [Select]
can be executed within the VAO binding just once in start(). Vertex array enable state is part of the VAO and you don't have to enable/disable constantly.
OpenGL / glDrawArrays causes coredump with SIGSEGV
« Last post by mikem on November 28, 2020, 14:29:45 »
I'm loosely following this tutorial https://lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content/chapter04/chapter4.html to get familiar with lwjgl and OpenGL. The goal is to just get this simple triangle on screen but my code keeps on crushing on glDrawArrays call with coredump and SIGSEGV. Looks like OpenGL can't get access to the vbo data created but I can't see what and where could go wrong with that.

Code: [Select]
import org.lwjgl.glfw.GLFWErrorCallback;

import org.lwjgl.opengl.GL;

import java.nio.FloatBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.*;

public class Main {
    private long window;
    private ShaderProgram shaderProgram;
    private int vaoId;

    public void start() {

        if (!glfwInit())
            throw new IllegalStateException("Error");


        glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
        glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

        window = glfwCreateWindow(1920, 1080, "OpenGL", NULL, NULL);

        if (window == NULL)
            throw new RuntimeException("Couldn't create a window");

        glfwSetKeyCallback(window, (window, key, scancode, action, mode) -> {
            // TODO





        shaderProgram = new ShaderProgram();
        shaderProgram.attachShader(new Shader(Res.string("fragment.frag"), GL_FRAGMENT_SHADER));
        shaderProgram.attachShader(new Shader(Res.string("vertex.vert"), GL_VERTEX_SHADER));

        float[] verts = new float[]{
                0.0f, 0.5f, 0.0f,
                -0.5f, -0.5f, 0.0f,
                0.5f, -0.5f, 0.0f

        FloatBuffer vertBuffer = memAllocFloat(verts.length);

        vaoId = glGenVertexArrays();

        int vboId = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vertBuffer, GL_STATIC_DRAW);

        glVertexAttribPointer(0, 3, GL_FLAT, false, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        glViewport(0, 0, 1920, 1080);
        glClearColor(1.f, 0.f, 1.f, 1.f);


    void loop() {
        while (!glfwWindowShouldClose(window)) {



            glDrawArrays(GL_TRIANGLES, 0, 3);




    public static void main(String[] args) {
        new Main().start();

All the shader stuff seem to be working fine. But in case it can be relevant here's the gist with the rest of the code including shaders: https://gist.github.com/miriti/c578f4f4c000a4a84f1af260fa4ba28e
Lightweight Java Gaming Library / Eclipse Import Suggestions (Issue)
« Last post by ZackTactical34 on November 26, 2020, 02:19:15 »
I'm facing a weird issue with import suggestions not showing on Eclipse. I followed this tutorial and seem to have everything set up correctly: https://www.youtube.com/watch?v=oHyzjnhqjpc&start=314s

The code will work, but it's a pain to have to type out each import statement. Please let me know if there is a fix (I'm guessing there is and I'm just not seeing it).
Lightweight Java Gaming Library / Re: Project panama
« Last post by tlf30 on November 20, 2020, 03:31:24 »
I see that Panama will be included as a preview in JDK 16. Exciting to see it finally making it into a JDK!
OpenGL / Re: I'm unable to properly blend z-ordered textures
« Last post by KaiHH on November 19, 2020, 08:04:00 »
You could always use texture atlases (pack multiple images into the same texture and assign texture coordinates accordingly) or use array textures, where each layer is a different image and index into the corresponding layer in the fragment shader.
OpenGL / Re: I'm unable to properly blend z-ordered textures
« Last post by noncompetitive_antagonist on November 19, 2020, 02:08:28 »
 :) Thank you. I suppose I'll have to render by z-index; hopefully, switching between 2d sprite textures won't be too performance intensive.
OpenGL / Re: I'm unable to properly blend z-ordered textures
« Last post by KaiHH on November 16, 2020, 10:41:49 »
Depth testing happens before alpha blending, so all fragments of the later drawn object behind the front object are discarded.
When you want to draw transparent objects, you must sort/draw them from back/furthest to front/nearest.
OpenGL / I'm unable to properly blend z-ordered textures
« Last post by noncompetitive_antagonist on November 16, 2020, 00:02:59 »
Hi there,

I am not able to implement transparency blending properly when I have one object being drawn *after* another object, and *beneath* that other object. See here:
In this picture, the upper-left image is being rendered first, and the lower-right image is being rendered second. The upper-left image has a lower z index, so it is higher than the lower-right image; this is correct. However, its transparency "overwrites" the non-transparency of the lower-right image beneath it. I am currently using the following code for my blending function and equation:

Code: [Select]

Am I missing something obvious? (I've double-checked that I'm not setting a different blend function elsewhere, for instance.)

Pages: 1 ... 8 9 [10]