Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LWJGL vertex shader gl_PointSize not working

I'm trying to change the size of a point in a vertex shader in LWJGL and can't get it to work. The point size is always 1px if I try to change it from the shader.

Vertex shader:

void main(){
   gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
   gl_PointSize = 10.0;
}

Fragment shader:

void main(){
   gl_FrontColor = gl_Color;
}

Draw code:

glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, p_vbo);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, c_vbo);
glColorPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, particles_num);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

My aim is to dynamically change the point size, but I can't change the point size from the shader. If I call this code:

glPointSize(10.0f);

from java, the size gets changed, but I want to be able to do that for each point. I've enabled my shader to change point sizes with:

glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);

Just to clarify: I can render all my points and everything is working great, but the point size is always 1px. I'm also not using smooth points.

EDIT: glGetFloat(GL_POINT_SIZE_RANGE) returns 1.0, which should indicate that my hardware does not support other pointsizes than 1.0. But if i modify my draw code from:

glDrawArrays(GL_POINTS, 0, particles_num);

to:

for (int i = 0; i < particles_num; i++) {
   glPointSize(massBuff.get(i));
   glDrawArrays(GL_POINTS, i, 1);
}

Where massBuff contains random floats with values 1f - 10f, I get the exactly desired result but with lesser performance. So, it's apparently supported by my hardware, and I still want to be able to do this from the shader.

EDIT: I also tried:

glEnable(GL_PROGRAM_POINT_SIZE);

Which does not work either. The program is behaving like i never enabled GL_PROGRAM_POINT_SIZE, as it uses glPointSize() if it exists it in the java code. As I understand, all calls to glPointSize() will be ignored if GL_PROGRAM_POINT_SIZE is enabled, and the program expects the shader to set the value, but even so, glPointSize() is used if it exists in the code.

like image 822
Mattias F Avatar asked Nov 23 '22 14:11

Mattias F


1 Answers

From what I can tell, the state you're supposed to glEnable is called GL_PROGRAM_POINT_SIZE, not GL_VERTEX_PROGRAM_POINT_SIZE. Does this make a difference for you?

like image 137
Dolda2000 Avatar answered Nov 26 '22 02:11

Dolda2000