Can't get OpenGL to work correctly

I am very new to OpenGL, GLSL and WebGL. I'm trying to get this sample code to work in a tool like http://shdr.bkcore.com/ but I can't seem to get it to work.

Vertex Shader:

void main()
{ 
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;
}

      

Fragment shader:

precision highp float;
uniform float time;
uniform vec2 resolution;
varying vec3 fPosition;
varying vec3 fNormal;

uniform sampler2D tex0;

void main()
{
  float border = 0.01;
  float circle_radius = 0.5;
  vec4 circle_color = vec4(1.0, 1.0, 1.0, 1.0);
  vec2 circle_center = vec2(0.5, 0.5);

  vec2 uv = gl_TexCoord[0].xy;
  vec4 bkg_color = texture2D(tex0,uv * vec2(1.0, -1.0));

  // Offset uv with the center of the circle.
  uv -= circle_center;
  float dist = sqrt(dot(uv, uv));

  if ( (dist > (circle_radius+border)) || (dist < (circle_radius-border)) )
gl_FragColor = bkg_color;
else
gl_FragColor = circle_color;
}

      

I realized that this code must be from an outdated version of the language, so I changed the vertex shader to:

precision highp float;
attribute vec2 position;
attribute vec3 normal;

varying vec2 TextCoord;
attribute vec2 textCoord;

uniform mat3 normalMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
varying vec3 fNormal;
varying vec3 fPosition;

void main()
{

  gl_Position = vec4(position, 0.0, 1.0);
  TextCoord = vec2(textCoord);
}

      

It seemed to fix error messages about undeclared ids and not being able to "convert from" float "to highp 4-piece something or other", but I have no idea if functionally this would do the same as the original.

Also, when I convert to this version of Vertex Shader, I have no idea what I should be doing with this line in the Fragment Shader:

vec2 uv = gl_TexCoord[0].xy;

      

How do I convert this string to match the converted vertex shader and how can I be sure that the vertex shader is even converted correctly?

+3


source to share


1 answer


gl_TexCoord is the OpenGL desktop and not part of OpenGL ES. You will need to create a new custom vec2 that changes to store the coordinate value.



0


source







All Articles