Reputation: 71
I'm trying to render pointsprites in Opengl along a certain path. I define a sprite as a 2D texture and set it to use GL_NEAREST as the mag/min filter. I also define a 1D texture containing a few 2D coordinates (so that I only need 1 float per sprite to determine their screenspace location) which I set to GL_LINEAR.
However, when I run my program on my laptop it always uses the mag filter method of the sprite-texture and ignores the setting on the path-texture. My laptop runs Linux+mesa 9.2.1+Opengl 3.0 on an intel Iris Pro 5200. Everything works as expected on my desktop which runs Linux and uses the proprietary Nvidia driver with opengl 4.2.
The relevant code is
//A path "t -> (x,y)" along which we will place our sprites
v2f path[] = {{-0.5,0.5},
{-0.5,-0.5},
{0.5,-0.5},
{0.5,0.5}};
glActiveTexture(GL_TEXTURE0);
if(glGetError() != GL_NO_ERROR)
report(FAIL, "Couldn't activate texture!");
GLuint pathTex;
glGenTextures(1, &pathTex); //create a new texture
glBindTexture(GL_TEXTURE_1D, pathTex); //start using it as a 1D texture
//store the coordinates of path in the texture so that we can interpolate our path in the shader.
glTexImage1D(GL_TEXTURE_1D,0,GL_RG32F, sizeof(path)/sizeof(v2f),0,GL_RG,GL_FLOAT,path);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_BASE_LEVEL, 0);//We need these two lines
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 0);//because we don't have mipmaps.
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//We want the path to be linearly filtered
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//Set the min filter just to be safe.
if(glGetError() != GL_NO_ERROR)
report(FAIL, "Something went wrong setting up pathTex");
GLint uniformLoc = glGetUniformLocation(shaderProgram, "pathTexture"); //locate the uniform
uniformLoc >= 0?glUniform1i(uniformLoc, 0):report(FAIL, "found uniform spriteTexture at %d", uniformLoc); //and set it to "0" because we're using GL_TEXTURE0
if(glGetError() != GL_NO_ERROR)
report(FAIL, "Couldn't set uniform!");
report(PASS, "Setup texture for path");
//create and set second texture
rgba sprite[] = {{1.0,0,0,1},{0,1.0,0,1},{0,0,1.0,1},{1,1,0,1}}; //our sprite, a simple "red,green,blue,yellow" square.
glActiveTexture(GL_TEXTURE0+1); //use texUnit 1 now.
if(glGetError() != GL_NO_ERROR)
report(FAIL, "Couldn't activate texture!");
GLuint spriteTex;
glGenTextures(1, &spriteTex); //create a new texture
glBindTexture(GL_TEXTURE_2D, spriteTex); //start using it as a 2D texture
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, 2,2,0,GL_RGBA,GL_FLOAT,sprite); //load the data again. 2x2 sprite.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);//We need these two lines
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);//because we don't have mipmaps.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);//We want our sprites to be filtered to
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);//the nearest pixel, not interpolated.
if(glGetError() != GL_NO_ERROR)
report(FAIL, "Something went wrong setting up pathTex");
uniformLoc = glGetUniformLocation(shaderProgram, "spriteTexture"); //locates and set the second sampler.
uniformLoc >= 0?glUniform1i(uniformLoc, 1):report(FAIL, "found uniform spriteTexture at %d", uniformLoc);
if(glGetError() != GL_NO_ERROR)
report(FAIL, "Couldn't set uniform!");
report(PASS, "Setup texture for sprite");
And my vertex shader is
#version 130
uniform sampler1D pathTexture;
in float t;
void main(){
gl_Position = texture(pathTexture, t);
}
and my fragment shader is
#version 130
uniform sampler2D spriteTexture;
out vec4 outputColor;
void main()
{
outputColor = texture(spriteTexture, gl_PointCoord);
}
The whole code (single filed) I have pasted here, and here are screenshots of what I see on Nvidia and Intel respectively.
edit: I get the same results on Nvidia with a 3.0 context.
What can cause this?
Upvotes: 0
Views: 779
Reputation: 52084
Make sure you call glfwInit()
before any other GLFW functions
Same with glewInit()
.
Upvotes: 1