In OpenGL ES 2.0 / GLSL, where do you need precision specifiers?

You don’t need precision specifiers on constants/literals since those get compile time evaluated to whatever they are being assigned to. In vertex shaders, the following precisions are declared by default: ( 4.5.3 Default Precision Qualifiers) precision highp float; precision highp int; precision lowp sampler2D; precision lowp samplerCube; And in fragment shaders you get: precision mediump … Read more

GLSL, semaphores?

Basically, you’re just implementing a spinlock. Only instead of one lock variable, you have an entire texture’s worth of locks. Logically, what you’re doing makes sense. But as far as OpenGL is concerned, this won’t actually work. See, the OpenGL shader execution model states that invocations execute in an order which is largely undefined relative … Read more

Multiple textures in GLSL – only one works

Here’s a basic GLUT example (written on OS X, adapt as needed) that generates two checkerboard textures, loads a shader with two samplers and combines them by tinting each (one red, one blue) and blending. See if this works for you: #include <stdio.h> #include <stdlib.h> #include <GLUT/glut.h> #include <OpenGL/gl.h> #include <OpenGL/glu.h> #define kTextureDim 64 GLuint … Read more

How do you get the modelview and projection matrices in OpenGL?

Hey, let’s slow down a bit here 🙂 Yes, that’s true that you receive the matrix by glGetFloatv(GL_MODELVIEW_MATRIX, ptr)… But that’s definitely not the thing you should do here! Let me explain: In GLSL, built-in variables like gl_ModelViewProjectionMatrix or functions like ftransform() are deprecated – that’s right, but that’s only because the whole matrix stack … Read more

From RGB to HSV in OpenGL GLSL

I am the author of the second implementation. It has always behaved correctly for me, but you wrote 2.9 / 6.9 instead of 2.0 / 6.0. Since you target GLSL, you should use conversion routines that are written with the GPU in mind: // All components are in the range [0…1], including hue. vec3 rgb2hsv(vec3 … Read more