#Generating textures using ByteBuffer resulting in white texture (LWJGL)

1 messages ยท Page 1 of 1 (latest)

spring flaxBOT
#

<@&987246399047479336> please have a look, thanks.

spring flaxBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

textures using ByteBuffer. However, when I render the textures, they appear as white textures instead of the expected colors. Here is my code:

#
// Loading the lightmap texture
ByteBuffer lightmapData = ByteBuffer.allocateDirect(width * height * 3);
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        int index = (y * width + x) * 3;
        byte r = ... // red component from BSP file
        byte g = ... // green component from BSP file
        byte b = ... // blue component from BSP file

        lightmapData.put(index, r);
        lightmapData.put(index + 1, g);
        lightmapData.put(index + 2, b);
    }
}

// Creating the lightmap texture
int textureId = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB,
             GL_UNSIGNED_BYTE, lightmapData);

// Rendering the textured quad
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3d(-1.0d ,1 .00d ,0 .00d);
glEnd();
#

I have verified that the byte values for the red, green, and blue components are correct. I have also tried using different internal formats like GL_RGB16F and GL_RGB32F, but the result is still a white texture. What could be causing this issue?

One possible issue could be the texture parameters. By default, OpenGL assumes that textures have their origin at the bottom-left corner. However, in some cases (like loading images from files), the origin may be at the top-left corner. To fix this, you can set the texture parameter GL_TEXTURE_WRAP_T to GL_CLAMP_TO_EDGE:

#
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#

Additionally, make sure to enable texture mapping before rendering:

#
glEnable(GL_TEXTURE_2D);
#

If these suggestions don't solve your issue, there might be a problem with how you're generating or reading the lightmap data from the BSP file. Double-check that you're correctly extracting the red, green, and blue components from the file.

You can also try printing out some debug information to verify that your lightmapData ByteBuffer contains the expected values before creating the texture.

If none of these suggestions work, please provide more details about how you're generating or loading lightmap data from your BSP file so we can further assist you.

south arch
rich schooner
#

@south arch Im gonna get back to this later, but just for my curiosity what libraries (other than lwjgl) are you using?

#

also how do you pass the bytebuffer to opengl?

south arch
#

to answer your first question:

  • Dear ImGui
  • Joml
  • Assimp
  • Fmod
  • GLFW
  • OpenAL
  • Tinylog
  • stb

to answer your second question: I have 2 constructors for the Texture class, one for loading a texture from a file, and one from loading it from a ByteBuffer

#

both constructors use the generateTexture function but the filepath one uses stbi to load it to a buffer

rich schooner
#

i guess what i'd be interested in is if the bytebuffer maybe got copied or something

#

because if the only difference is that if buf is ByteBuffer and not byte[]...

south arch
#

i'm not really sure what you mean by that

i create a new bytebuffer for every lightmap

rich schooner
#

i mean

#

on a bytebuffer some operations copy the underlying bytes

#

so i thought that might be a culprit - opengl doing its work and it not getting back to you

#

but if the only difference between the working code and the byte buffer code is that byte[] is used instead, that will be confusing

#

(but definitely give directions to look)

south arch
#

well there isn't really a way to pass a byte[] into the glTexImage2D function

#

if that's what you mean

rich schooner
#

ohhh

#

are you expecting the byte[] to get the changes?

south arch
#

no the byte[] is just for easy pixel editing

it then gets turned into a bytebuffer and passed to opengl

spring flaxBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐Ÿ‘