2

I'm currently rendering a bunch of points to which I'd like to apply a texture using point sprites. To load my texture, I'm using GLFW. I followed the instructions in the OpenGL Super Bible chapter on this, but when I try to apply the texture in my fragment shader, it doesn't work.

Here are some of my code snippets on this:

//Variables
GLuint starTBO;
GLuint location_texture = 0;

// Set location (in main function)
glUseProgram(shader_program2);
location_texture = glGetUniformLocation(shader_program2, "sprite_texture");
glUseProgram(0);

// Set Texture (in main function)
glGenTextures(1, &starTBO);
glBindTexture(GL_TEXTURE_2D, starTBO);
if(glfwLoadTexture2D("stone.tga", GLFW_BUILD_MIPMAPS_BIT))
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
glEnable(GL_TEXTURE_2D);

// in display method
glUseProgram(shader_program2);
glActiveTexture(GL_TEXTURE0 + 0);
glUniform1i(location_texture, 0);
...

// Fragment shader
const GLchar *fragment_shader2 =
"#version 330\n"
"out vec4 out_color;"
""
"uniform sampler2D sprite_texture;"
""
"void main()"
"{" 
"   out_color = texture(sprite_texture, gl_PointCoord) + vec4(1.0, 0.0, 0.0, 1.0);"
"}"

Point Sprite mode is enabled in my initGL method. What could be the reason why texture isn't applied to the points?

EDIT: I inserted an if-statement to see whether the call to glfwLoadTexture2D isworking properly, and indeed it is not. What could cause this to fail? I tried using the relative and the real path as a parameter, but still no change. I also tried using different .tga images. Anyone, still haven't figured out why it won't work?

EDIT 2: Could it be that freeglut and glfw don't work together?

Schnigges
  • 1,284
  • 2
  • 24
  • 48

1 Answers1

1

Try tossing in a glActiveTexture(GL_TEXTURE0 + 0) before your glUniform1i() call.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Until now, I completely avoided using textures. Now I wanted to start with an easy use case of them but it's not working...so I don't really know what could be wrong. – Schnigges Jan 30 '13 at 15:07
  • Is there a way to check if my texture is loaded correctly in this case? – Schnigges Jan 30 '13 at 16:03
  • Use [gDEBugger](http://www.gremedy.com/). Break on a relevant GL call (like glGenTextures(...)) and then step while monitoring the status of your texture. – Jelly Feb 01 '13 at 23:56
  • so, gDEBuffer tells me this: The used internal pixel format is different from the requested internal format. This is probably caused by requesting a pixel format that is not supported by the graphic system. I have copied different .tga files from examples which work alright, so I don't understand what the damn problem is – Schnigges Feb 02 '13 at 16:56
  • 1
    You can get this sometimes with compressed/uncompressed tga files (depending on which your code is using) make sure that the file is being saved in the exact format the code accepts (Yep, this seems obvious but not all TGAs are born equal... and they have given me the same problems in the past): particular attention on image bit depth and dimensions, compression being enabled/disabled to suit the loader and that should hopefully fix your problem:) – GMasucci Feb 06 '13 at 12:44