Hello Guest

Recent Posts

Pages: [1] 2 3 ... 10
1
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!
2
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).

EDIT:
Besides that:
Code: [Select]
glEnableVertexAttribArray(0);
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.
3
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() {
        GLFWErrorCallback.createPrint(System.err).set();

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

        glfwDefaultWindowHints();

        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
        });

        glfwMakeContextCurrent(window);

        glfwSwapInterval(1);

        glfwShowWindow(window);

        GL.createCapabilities();

        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));
        shaderProgram.link();

        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);
        vertBuffer.put(verts).flip();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

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

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

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);

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

        loop();
    }

    void loop() {
        while (!glfwWindowShouldClose(window)) {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            shaderProgram.bind();

            glBindVertexArray(vaoId);
            glEnableVertexAttribArray(0);

            glDrawArrays(GL_TRIANGLES, 0, 3);

            glDisableVertexAttribArray(0);
            glBindVertexArray(0);

            shaderProgram.unbind();

            glfwSwapBuffers(window);
            glfwPollEvents();
        }
    }

    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
4
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).
5
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!
6
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.
7
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.
8
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.
9
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:
https://imgur.com/ccmg0IT
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]
        glEnable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glBlendEquation(GL_FUNC_ADD);

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

Thanks!
10
I figured out the problem--I was disabling depth testing elsewhere in my code.  :-[
Pages: [1] 2 3 ... 10