Schnigges
Schnigges

Reputation: 1326

Render textured point sprites using GLFW

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?

Upvotes: 2

Views: 1709

Answers (1)

genpfault
genpfault

Reputation: 52083

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

Upvotes: 1

Related Questions