After having used display lists for my programs since I started learning OpenGL, I've finally decided to switch to VBOs after experiencing a considerable amount of lag when I started work on a new game. I've nearly finished with my transition, but I'm still having a bit of trouble with rendering the textures to the screen. The way I'm working it is this: I have several sprites of the same dimensions for each type of "block" in the game (it's a Terraria port) which are loaded into the game via a convenience method, then after they're all loaded, they're compiled into a virtual texture atlas via Graphics2D, converted to a Slick texture, and their relative coordinates are saved to a HashMap. However, when it comes time to grab the textures out of the HashMap and render them, the game simply doesn't. Here's part of my code for adding a block to the VBO (this is executed 4 times per block, once for each corner):

// top left
// vertex
// light
values.add(Float.valueOf((float)b.getLightLevel() / 15));
values.add(Float.valueOf((float)b.getLightLevel() / 15));
values.add(Float.valueOf((float)b.getLightLevel() / 15));
// texture

(Note: values is a list which is later converted to an array.) Then comes my code for rendering the VBO:

public static void render(){
    glTranslatef(MineFlat.xOffset, MineFlat.yOffset, 0);
    glBindTexture(GL_TEXTURE_2D, BlockUtil.atlas.getTextureID());
    glVertexPointer(2, GL_FLOAT, 28, 0);
    glColorPointer(3, GL_FLOAT, 28, 8);
    glTexCoordPointer(2, GL_FLOAT, 28, 20);
    glDrawArrays(GL_QUADS, 0, vertexArray.length / 7);
    glBindTexture(GL_TEXTURE_2D, 0);

The blocks are properly rendered with the correct lighting, but they lack any sort of texture. Any suggestions as to how to get the code working? I apologize if the answer is obvious, but I still consider myself a bit of an OpenGL noob, especially in the area of VBOs.

One last thing; I should mention that I'm not using any shaders in my current game.

EDIT: I seem to be a bit mistaken. Upon experimenting with the code by manually setting all texture coords, I discovered that the game simply converts the texture to a uniform color by averaging the RGB value of all pixels. I didn't recognize this before because the color of most blocks is grey. I recall having this problem before with display lists, but that was quite a while ago, and so I don't remember how I resolved it.

SECOND EDIT: Screenshots of the expected and actual result, respectively: https://i.stack.imgur.com/3t4r4.png https://i.stack.imgur.com/edv8v.png

  • \$\begingroup\$ It shouldn't be necessary but did you try to call glEnable(GL_TEXTURE_2D); and glActiveTexture(GL_TEXTURE0); \$\endgroup\$
    – PeterT
    Jul 27, 2013 at 18:31
  • \$\begingroup\$ @mrproncace your edit sounds like a problem with glTexParameteri, the MIN / MAG filters or the mipmap level if you use mipmaps. \$\endgroup\$
    – PeterT
    Jul 27, 2013 at 18:35
  • \$\begingroup\$ @PeterT No luck. While I didn't have GL_TEXTURE0 active, activating it didn't solve the problem. While I did have the lines glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); and glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); in my code in order to remove interpolation while scaling, commenting them out didn't seem to affect anything either. \$\endgroup\$
    – caseif
    Jul 27, 2013 at 18:43
  • \$\begingroup\$ yeah, GL_NEAREST should give you the least problems. If it's really the average color that sounds kind of weird. Got no clue, if that wouldn't be what happened I'd check if the relevant glEnableClientState() calls have been made. You might also try to call glClientActiveTexture(GL_TEXTURE0) but just like glActiveTexture it should be default anyway. \$\endgroup\$
    – PeterT
    Jul 27, 2013 at 18:55
  • \$\begingroup\$ I've made calls to GL_VERTEX_ARRAY, GL_COLOR_ARRAY, and GL_TEXTURE_COORD_ARRAY. As for the textures being rendered as the average color, I'm not entirely positive that's the case; I was really just eyeballing it. I'll add two screenshots to the main post showing the expected result and the actual result. \$\endgroup\$
    – caseif
    Jul 27, 2013 at 18:56

1 Answer 1


I figured out my problem myself, and found it was due to a very simple mistake: I added a red pixel to the top left corner of one texture, and discovered it was the only one being rendered. I got the idea from this thread. It's because I forgot to cast the image width to a float, so when divided by 16, it would yield zero.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .