Hi,
I’m trying to do a particles system with point sprites. But I’ve got an error in the windows emulator
when I use the gl_PointCoord variable. The output is:
"Fragment shaders uses varying gl_TexCoord but vertex shader does not write to it."
The source code of my shaders is the following:
[vertex shader]
attribute highp vec4 inVertex;
uniform mediump mat4 MVPMatrix;
void main()
{
gl_PointSize = 200.0;
gl_Position = MVPMatrix * inVertex;
}
[fragment shader]
uniform sampler2D sTexture;
void main()
{
gl_FragColor = texture2D(sTexture, gl_PointCoord);
}
As a first approach I was only trying to draw a textured point on the screen:
GLfloat vertex[] = {0.0f,0.0f,0.0f};
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer (VERTEX_ARRAY, 4, GL_FLOAT, GL_FALSE, 0, vertex);
glDrawArrays(GL_POINTS, 0, 1);
If I use a vec2 coordinate instead of the gl_PointCoord, it draws a point sprite with uniform color.
But with the gl_PointCoord it fails.
Am I missing something?
Thanks
Hi alvalea,
strange error. What is your hardware? Do you know which OpenGL version and which extensions your driver supports?
Could you try this fragment shader:
void main()
{
gl_FragColor = vec4(gl_PointCoord.x, gl_PointCoord.y, 0.0, 1.0);
}
I’m trying it with an Intel integrated chip Q45/Q43. The supported OpenGL version is 2.0.
The gl_PointCoord coordinates are always (0,0).
Strange.
Well, "gl_PointCoord" is a feature of GLSL 1.20; thus, you might have to add the line
#version 120
at the start of your fragment shader. (Of course, you should also check whether GLSL 1.20 is supported on your hardware/driver. OpenGL 2.0 only requires GLSL 1.10; thus, this might be an issue.)
If this doesn't work, I would suggest that you try to get the fragment
shader to work in (desktop) OpenGL. If it doesn't work in (desktop)
OpenGL on your hardware/driver, I would assume that it also doesn't work
in the OpenGL ES emulator. (In desktop OpenGL you probably have to
glEnable GL_POINT_SPRITE and GL_VERTEX_PROGRAM_POINT_SIZE but apart from
this, the code should be very similar.)
If the code works in (desktop) OpenGL but not in the OpenGL ES emulator, I would assume it's a bug in the emulator. :/
Martin Kraus2010-11-29 13:02:17
If I add the line ‘#version 120’ the function PVRTShaderLoadFromFile fails.
I guess that the problem is that the hardware doesn’t support GLSL 1.20.
I will try to test it in another hardware.
alvelea,
I just tested it and the OpenGL ES emulator seems to reject anything but version “#version 100”. Actually, GLSL version 1.00 for OpenGL ES appears to be based on GLSL version 1.20 for OpenGL.
Thus, I guess you have to make sure to run the emulator on hardware that supports GLSL 1.20.
Ok, thanks a lot