Hello Guest

Recent Posts

Pages: [1] 2 3 ... 10
1
OpenGL / Re: VBO - Strange black quad appears sometimes
« Last post by TheBoneJarmer on August 31, 2022, 07:45:35 »
It is has been 7 years since I used LWJGL and just learned I still have an account here. How times flies. Reading back my comments feels embarrassing. God I was a naive young idiot. Now I am just a naive idiot. lol In the meantime I have learned much, much more about OpenGL so I ought it was nice to share an update on the matter for those who like me back in the day experiences this issue. Kinda feels weird solving an issue for my past self but here goes! It was not the shader nor the driver and none of all the wild goose chasing ideas I threw up.

A couple of years ago I experienced the same issue with c++ and I learned it was actually my buffer data. My example worked with triangles and I was likely screwing up my buffers by not passing the right amount of vertices, texcoords and normals. Or with the wrong parameters for that matter. With what I know now, Kay was absolute correct to state it could not be the shaders. I know its a bit late but sorry for confusion the whack out of you! What I experienced back then was a case of what they call undefined behavior in c++. Same happens when you try to fetch an element from a const float* array that goes out of bounds. You won't get an error, just memory corruption. Which is why I saw those fragments. It was really that simple.
2
OpenGL / Generating an indexed voxel chunk mesh
« Last post by moderator_man on August 27, 2022, 19:27:29 »
My goal is to generate a Minecraft-like voxel chunk mesh & render it. The geometry is incorrect, but I'm not quite sure why.

Here is my mesh generation code:

Code: [Select]
private void generateMeshData(Vector3f pos)
{
    Block block = Block.getBlock(getBlockAt(pos));
    int vertexIndex = 0;
    LinkedHashMap<Vertex, Integer> vertex2index = new LinkedHashMap<>();
    ArrayList<Integer> indices = new ArrayList<>();

    for (int side = 0; side < 6; side++)
    {
        if (!shouldRenderVoxel(pos.add(VoxelData.faceChecks[side]), block.isFluid()))
        {
            int x0 = Math.round(pos.x);
            int x1 = Math.round(pos.x);
            int z0 = Math.round(pos.z);
            int z1 = Math.round(pos.z);
            int xx = x1 - x0 + 1, zz = z1 - z0 + 1, yy = 1;
            int red = 25, green = 25, blue = 25;

            float[] vertices = AABB.SIDE.values[side].translate_and_expand(pos.x + x_offset, pos.y + y_offset, pos.z + z_offset, xx, yy, zz);
            float[] textures = Texture.calcAtlasCoords(block.getTextureIndex(side), 16);

            Integer index;

            Vertex vertex0 = new Vertex(vertices[0], vertices[1], vertices[2], textures[0], textures[1], textures[2], textures[3], red, green, blue);
            index = vertex2index.get(vertex0);
            if (index == null)
            {
                index = vertexIndex++;
                vertex2index.put(vertex0, index);
            }
            indices.add(index);
            indices.add(vertex2index.get(vertex0));

            Vertex vertex1 = new Vertex(vertices[3], vertices[4], vertices[5], textures[0], textures[1], textures[2], textures[3], red, green, blue);
            index = vertex2index.get(vertex1);
            if (index == null)
            {
                index = vertexIndex++;
                vertex2index.put(vertex1, index);
            }
            indices.add(index);
            indices.add(vertex2index.get(vertex1));

            Vertex vertex2 = new Vertex(vertices[6], vertices[7], vertices[8], textures[0], textures[1], textures[2], textures[3], red, green, blue);
            index = vertex2index.get(vertex2);
            if (index == null)
            {
                index = vertexIndex++;
                vertex2index.put(vertex2, index);
            }
            indices.add(index);
            indices.add(vertex2index.get(vertex2));

            Vertex vertex3 = new Vertex(vertices[9], vertices[10], vertices[11], textures[0], textures[1], textures[2], textures[3], red, green, blue);
            index = vertex2index.get(vertex3);
            if (index == null)
            {
                index = vertexIndex++;
                vertex2index.put(vertex3, index);
            }
            indices.add(index);
            indices.add(vertex2index.get(vertex3));
        }
    }

    mesh.update_gl_data(vertex2index.keySet(), indices);
}

And here is how I'm updating it:

Code: [Select]
public void update_gl_data(Set<Vertex> vertices, List<Integer> indices) {
this.indices_counter = indices.size();
this.ibo_data = BufferUtils.createByteBuffer(indices_counter * 4);
this.vbo_data = BufferUtils.createByteBuffer(vertices.size() * 40);
for (int index : indices) {
ibo_data.putInt(index);
}
ibo_data.flip();

for (Vertex vertex : vertices) {
vbo_data.putFloat(vertex.pos_x).putFloat(vertex.pos_y).putFloat(vertex.pos_z);
vbo_data.putFloat(vertex.tex_coord_x).putFloat(vertex.tex_coord_y);
vbo_data.putFloat(vertex.tex_coord_offset_x).putFloat(vertex.tex_coord_offset_y);
vbo_data.putFloat(vertex.color_r).putFloat(vertex.color_g).putFloat(vertex.color_b);
}
vbo_data.flip();
}
3
OpenGL / OpenGL-ES 2.0 glCopyBufferSubData alternative
« Last post by Aisaaax on August 18, 2022, 11:14:46 »
I used glCopyBufferSubData() quite a lot. My vertex array buffers need to grow from time to time, and it was a great way to increase the size of the buffer without involving CPU as a middleman to copy the data.

Is there any alternative? How would you even go about copying buffer data? do you actually need to read it from Vram into some buffer array and then write it into another VBO?
4
OpenGL / Re: OpenGL-ES 3.2 -> OpenGL-ES 2.0
« Last post by Aisaaax on August 18, 2022, 11:08:40 »
It was something like that.
For mesh constructor, I indeed need to just take out everything to do with VAO and just save my VBO's into array.

For rendering, it goes something like this:
Code: [Select]

            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbi);           

            glBindBuffer(GL_ARRAY_BUFFER, vboIDList.get(0));         //These 3 lines for each VBO
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, size, type, normalized, stride, offset);

            glDrawElements(GL_TRIANGLES, getIndexCount(), GL_UNSIGNED_INT, 0);

            glDisableVertexAttribArray(0);
            glDisableVertexAttribArray(1);

            glBindBuffer(GL_ARRAY_BUFFER, 0);
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
5
OpenGL / OpenGL-ES 3.2 -> OpenGL-ES 2.0
« Last post by Aisaaax on August 18, 2022, 04:41:04 »
Hello.
Since our hardware on my project got downgraded, I need to adapt my previous program writtem with GLES 3.2 to an older GLES 2.0 version.
Thankfully, I'm not using a lot of 3.0+ features, so the transition should be rather smooth.
AFAIK I will only need to modify my shaders and also get rid of VAO mechanics, and here's the point that is confusing to me.

My mesh creation was done something like this:
Code: [Select]
public Mesh(float[] vertexes, int[] indexes, int lengthStep, int vertexSize, int vertexLayoutSlot)
            throws Exception
    {
            int vboID;
 
            vaoID = glGenVertexArrays();
            vboIDList = new ArrayList<>();
            glBindVertexArray(vaoID);
 
            // Vertices VBO generation
            vboID = glGenBuffers();
            vboIDList.add(vboID);
 
            vertexCount = vertexes.length;
            this.vertexSize = vertexSize;
            vertexBufferLength = calculateBufferLength(vertexCount, vertexSize);
 
            FloatBuffer vertexesBuffer = getFloatBuffer(vertexes, vertexBufferLength);
 
            glBindBuffer(GL_ARRAY_BUFFER, vboID);
            glBufferData(GL_ARRAY_BUFFER, vertexesBuffer, GL_STATIC_DRAW);
            glVertexAttribPointer(vertexLayoutSlot, vertexSize, GL_FLOAT, false, 0, 0);
            vertexAttrArrCount++;
 
            // Indices VBO generation
            vboID = glGenBuffers();
            vboIDList.add(vboID);
            indexCount = indexes.length;
            indexBufferLength = calculateBufferLength(indexCount, 3);       // every one vertex adds 3 indexes, so 3 indexes per node is standard
                                                                                    // may not be applicable to meshes with complex geometry
 
            IntBuffer indexesBuffer = getIntBuffer(indexes, indexBufferLength);
 
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
            glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexesBuffer, GL_STATIC_DRAW);
 
            // unbinding
            glBindBuffer(GL_ARRAY_BUFFER, 0);
            glBindVertexArray(0);
    }

And then for rendering, something like this:
Code: [Select]
public void render(ShaderProgram sp)
    {
            // draw the mesh
            glBindVertexArray(getVAO());
            for (int i = 0; i < vertexAttrArrCount; i++)
            {
                // enable the right number of vertex attribute arrays
                glEnableVertexAttribArray(i);
            }
 
            glDrawElements(GL_TRIANGLES, getIndexCount(), GL_UNSIGNED_INT, 0);
 
            // restore state
            glDisableVertexAttribArray(0);
            glDisableVertexAttribArray(1);
            glDisableVertexAttribArray(2);
            glBindVertexArray(0);
    }

As far as I understand, I need to get rid of VAO entirely, and then manually bind the VBO's each time I want to render something. So my constructor should be somehting like this, basically just remove any mention of VAO but when it comes to VBO's I still generate them in the same manner and store them in the array of VBO ID's:

Code: [Select]
public Mesh(float[] vertexes, int[] indexes, int lengthStep, int vertexSize, int vertexLayoutSlot)
            throws Exception
    {
            int vboID;
            vboIDList = new ArrayList<>();
 
            // Vertices VBO generation
            vboID = glGenBuffers();
            vboIDList.add(vboID);
 
            vertexCount = vertexes.length;
            this.vertexSize = vertexSize;
            vertexBufferLength = calculateBufferLength(vertexCount, vertexSize);
 
            FloatBuffer vertexesBuffer = getFloatBuffer(vertexes, vertexBufferLength);
 
            glBindBuffer(GL_ARRAY_BUFFER, vboID);
            glBufferData(GL_ARRAY_BUFFER, vertexesBuffer, GL_STATIC_DRAW);
            glVertexAttribPointer(vertexLayoutSlot, vertexSize, GL_FLOAT, false, 0, 0);
            vertexAttrArrCount++;
 
            // Indices VBO generation
            vboID = glGenBuffers();
            vboIDList.add(vboID);
            indexCount = indexes.length;
            indexBufferLength = calculateBufferLength(indexCount, 3);       // every one vertex adds 3 indexes, so 3 indexes per node is standard
                                                                                    // may not be applicable to meshes with complex geometry
 
            IntBuffer indexesBuffer = getIntBuffer(indexes, indexBufferLength);
 
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
            glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexesBuffer, GL_STATIC_DRAW);
 
            // unbinding
            glBindBuffer(GL_ARRAY_BUFFER, 0);
    }

And then to render I need to just bind all my VBO's associated with this mesh and then unbind them after. So again, basically what I was already doing, just take out the VAO mentions from the code.
Code: [Select]
public void render(ShaderProgram sp)
    {
            // draw the mesh
            for (int i = 0; i < vertexAttrArrCount; i++)
            {
                // enable the right number of vertex attribute arrays
                glEnableVertexAttribArray(i);
            }

            glDrawElements(GL_TRIANGLES, getIndexCount(), GL_UNSIGNED_INT, 0);

            // restore state
            glDisableVertexAttribArray(0);
            glDisableVertexAttribArray(1);
            glDisableVertexAttribArray(2);
    }

Is this correct? Or am I missing something?
6
Vulkan / Re: Access violation from nstbi_load_from_memory
« Last post by cpope9141 on August 15, 2022, 01:38:12 »
I can use stbi_load_from_memory from a single thread, but my load times are 2-3 times longer.  Alternatively, stbi_load can be called from multiple threads without issue.
7
Vulkan / Re: Access violation from nstbi_load_from_memory
« Last post by cpope9141 on August 07, 2022, 03:00:25 »
My usage looks something like this:

   public void run() {
      switch(resourceType) {
         case RESOURCE_TYPE_IMAGE_RGBA:
            readImageRGBA();
            break;
         case RESOURCE_TYPE_AUDIO_STREAM:
            readAudioStream();
         default:
            break;
      }
   }

   private void readImageRGBA() {
      RGBAResource[] resources = new RGBAResource[resourcePaths.length];
      
      for(int i = 0; i < resourcePaths.length; i++) {         
         try(MemoryStack stack = MemoryStack.stackPush()) {
               IntBuffer pWidth = stack.mallocInt(1);
               IntBuffer pHeight = stack.mallocInt(1);
               IntBuffer pChannels = stack.mallocInt(1);
               ByteBuffer imageRGBA = stbi_load_from_memory(ioResourceToByteBuffer(resourcePaths, RESOURCE_TO_BYTE_BUFFER_DEFAULT_SIZE),
                     pWidth,
                     pHeight,
                     pChannels,
                     STBI_rgb_alpha);
              
            resources = new RGBAResource(pHeight.get(0), pWidth.get(0), imageRGBA);
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      
      requester.requestedImageRGBACallback(resourceId, resources);
   }

Where these methods' class extends Thread.
8
Vulkan / Re: Access violation from nstbi_load_from_memory
« Last post by cpope9141 on August 07, 2022, 02:54:21 »
I was not able to attach the crash report (maybe because of size). Here is the first portion:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffb47a560cc, pid=7056, tid=10020
#
# JRE version: Java(TM) SE Runtime Environment (16.0.1+9) (build 16.0.1+9-24)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (16.0.1+9-24, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# C  [lwjgl_stb.dll+0x60cc]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  S U M M A R Y ------------

Command Line: -Dfile.encoding=Cp1252 -XX:+ShowCodeDetailsInExceptionMessages game.Game

Host: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz, 12 cores, 31G,  Windows 10 , 64 bit Build 19041 (10.0.19041.1806)
Time: Sat Aug  6 21:29:38 2022 Central Daylight Time elapsed time: 321.448003 seconds (0d 0h 5m 21s)

---------------  T H R E A D  ---------------

Current thread (0x000001ee1e5f7900):  JavaThread "Thread-3280" [_thread_in_native, id=10020, stack(0x000000a711c00000,0x000000a711d00000)]

Stack: [0x000000a711c00000,0x000000a711d00000],  sp=0x000000a711cfdc20,  free space=1015k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [lwjgl_stb.dll+0x60cc]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 1673  org.lwjgl.stb.STBImage.nstbi_load_from_memory(JIJJJI)J (0 bytes) @ 0x000001eda4ede58b [0x000001eda4ede520+0x000000000000006b]
J 2976 c2 org.lwjgl.stb.STBImage.stbi_load_from_memory(Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;I)Ljava/nio/ByteBuffer; (90 bytes) @ 0x000001eda503523c [0x000001eda5035160+0x00000000000000dc]
J 2222 c1 utilities.ResourceReader.readImageRGBA()V (199 bytes) @ 0x000001ed9dc99354 [0x000001ed9dc98b60+0x00000000000007f4]
J 1714 c1 utilities.ResourceReader.run()V (40 bytes) @ 0x000001ed9dbc67ec [0x000001ed9dbc66e0+0x000000000000010c]
v  ~StubRoutines::call_stub

siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), reading address 0x000001ee100385c9
9
Vulkan / Access violation from nstbi_load_from_memory
« Last post by cpope9141 on August 07, 2022, 02:52:59 »
Hello.

I am encountering an exception access violation when loading image resources with org.lwjgl.stb.STBImage.stbi_load_from_memory.  I have copied ioResourceToByteBuffer from lwjgl3-demos/src/org/lwjgl/demo/util/IOUtils.java into my project and am using it as the ByteBuffer input for stbi_load_from_memory. I have attached the crash report.

As far as I can tell, I am using ioResourceToByteBuffer in the same way as demonstrated in the lwjgl3 demos, but I am calling it from multiple threads. There does not seem to be a pattern to when the crash occurs. Are there any synchronization issues or limitations for ioResourceToByteBuffer or stbi_load_from_memory?
10
Lightweight Java Gaming Library / LWJGL Being Slow
« Last post by Rolpon on August 03, 2022, 00:17:50 »
Why is LWJGL being so slow? On one of my games/demos I made using LWJGL, the GPU and CPU usages are very high! This issue isn't with my demo though, as when I tried the same demo on a another computer it worked fine. Can anyone help me?
Pages: [1] 2 3 ... 10