0

I'm working on a simple particle system in OpenGL; so far I've written two fragment shaders to update velocities and positions in response to my mouse, and they seem to work! I've looked at those two textures and they both seem to respond properly (going from random noise to an orderly structure in response to my mouse).

However, I'm having issues with how to draw the particles. I'm rather new to vertex shaders (having previously only used fragment shaders); it's my understanding that the usual way is a vertex shader like this:

uniform sampler2DRect tex;
varying vec4 cur;

void main() {
    gl_FrontColor = gl_Color;
    cur = texture2DRect(tex, gl_Vertex.xy);
    vec2 pos = cur.xy;
    gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 0., 1.);
}

Would transform the coordinates to the proper place according to the values in the position buffer. However, I'm getting gl errors when I run this that it can't be compiled -- after some research, it seems that gl_ModelViewProjectionMatrix is deprecated.

What would be the proper way to do this now that the model view matrix is deprecated? I'm not trying to do anything fancy with perspective, I just need a plain orthogonal view of the texture.

thanks!

nathan lachenmyer
  • 5,298
  • 8
  • 36
  • 57

1 Answers1

2

What version of GLSL are you using (don't see any #version directive)? Yes, i think gl_ModelViewProjectionMatrix is really deprecated. However if you want to use it maybe this could help. By the way varying qualifier is quite old too. I would rather use in and out qualifiers it makes your shader code more 'readable'.

'Proper' way of doing that is that you create your own matrices - model and view (use glm library for example) and multiply them and then pass them as uniform to your shader. Tutorial with an example can be found here.

Here is my vs shader i used for displaying texture (fullscreen quad):

#version 430

layout(location = 0) in vec2 vPosition;
layout(location = 1) in vec2 vUV;

out vec2 uv;

void main()
{
    gl_Position = vec4(vPosition,1.0,1.0);
    uv = vUV;
}

fragment shader:

#version 430

in vec2 uv;
out vec4 final_color;
uniform sampler2D tex;

void main()
{
    final_color = texture(tex, uv).rgba;
}

and here are my coordinates (mine are static, but you can change it and update buffer - shader can be the same):

//Quad verticles - omitted z coord, because it will always be 1
float pos[] = {
    -1.0, 1.0,
    1.0, 1.0,
    -1.0, -1.0,
    1.0, -1.0
};

float uv[] = {
    0.0, 1.0,
    1.0, 1.0,
    0.0, 0.0,
    1.0, 0.0
};

Maybe you could try to turn off depth comparison before executing this shader glDisable(GL_DEPTH_TEST);

Community
  • 1
  • 1
mafian89
  • 81
  • 9