glsl

From RGB to HSV in OpenGL GLSL

心已入冬 提交于 2019-11-27 09:35:58
问题 I need to pass from RGB color space to HSV .. I searched in internet and found two different implementations, but those give me different results: A: precision mediump float; vec3 rgb2hsv(float r, float g, float b) { float h = 0.0; float s = 0.0; float v = 0.0; float min = min( min(r, g), b ); float max = max( max(r, g), b ); v = max; // v float delta = max - min; if( max != 0.0 ) s = delta / max; // s else { // r = g = b = 0 // s = 0, v is undefined s = 0.0; h = -1.0; return vec3(h, s, v); }

GLUT on OS X with OpenGL 3.2 Core Profile

点点圈 提交于 2019-11-27 08:57:37
Is it possible to use GLUT on OS X Lion or OS X Mountain Lion using core profile (so I can use GLSL 1.50)? Can I use the built in GLUT or do I need to use a third-part library such as FreeGLUT? And is there any simple 'Hello world' applications available for OS X with either an XCode project or a make-file? You need at least Mac OS X Lion (OS X 10.7 or higher) for the basic support of OpenGL 3.2. To use the OpenGL 3.2 Core Profile, just add glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | ... | ...); in your main -function. You can check it by std::printf("%s\n%s\n", glGetString(GL_RENDERER), // e

Why does GL divide `gl_Position` by W for you rather than letting you do it yourself?

二次信任 提交于 2019-11-27 07:52:39
Note: I understand the basic math. I understand that the typical perspective function in various math libraries produces a matrix that converts z values from -zNear to -zFar back into -1 to +1 but only if the result is divided by w The specific question is what is gained by the GPU doing this for you rather than you having to do it yourself? In other words, lets say the GPU did not magically divide gl_Position by gl_Position.w and that instead you had to do it manually as in attribute vec4 position; uniform mat4 worldViewProjection; void main() { gl_Position = worldViewProjection * position; /

What is the purpose of `glEnableVertexAttribArray(GLuint index)` in OpenGL?

点点圈 提交于 2019-11-27 07:23:28
问题 After calling glVertexAttribPointer(GLuint index, ...) the vertex attribute is disabled by default as the docs say By default, all client-side capabilities are disabled, including all generic vertex attribute arrays. Why must we enable it using an extra function? Can someone name a case, where this is useful? When researching I learned the following: By using the layout(location = x) qualifier in GLSL or glBindAttribLocation we can set the location explicitly rather then letting OpenGL

GLSL - Weird syntax error “<”

我怕爱的太早我们不能终老 提交于 2019-11-27 07:11:16
问题 I'm trying to use a shader but it keeps telling me this error on both fragment and vertex shader: error(#132) Syntax error: "<" parse error vertex shader varying vec4 diffuse; varying vec4 ambient; varying vec3 normal; varying vec3 halfVector; void main() { normal = normalize(gl_NormalMatrix * gl_Normal); halfVector = gl_LightSource[0].halfVector.xyz; diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; ambient += gl

OpenGL font rendering using Freetype2

旧城冷巷雨未停 提交于 2019-11-27 06:54:37
问题 I'm trying to render a freetype font using OpenGL, following the example posted at http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_02. I've been able to generate a texture atlas from the font, creating shaders and creating quads. What I seem to get stuck at is passing the texture to the shader and/or getting the correct UVs for my quads. Been struggling for a good while now and really need the help. The following is the struct I use to create my texture

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

核能气质少年 提交于 2019-11-27 06:43:54
Does the variable that you're stuffing values into dictate what precision you're working with, to the right of the equals sign? For example, is there any difference, of meaning, to the precision specifier here: gl_FragColor = lowp vec4(1); Here's another example: lowp float floaty = 1. * 2.; floaty = lowp 1. * lowp 2.; And if you take some floats, and create a vector or matrix from them, will that vector or matrix take on the precision of the values you stuff it with, or will those values transform into another precision level? I think optimizing this would best answer the question: dot(gl

Qt5 OpenGL GLSL version error

痞子三分冷 提交于 2019-11-27 06:24:42
问题 I'm starting out on using OpenGL with Qt, and with Shaders (I have OpenGL experience, but not with shaders yet) I'm following this tutorial: http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf (the official Qt5 OpenGL tutorial). The problem is, that when I try to run my program, I get a black screen and the following error messages: QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported QGLShader::compile(Fragment): ERROR: 0:1: '' :

Can someone please explain this Fragment Shader? It is a Chroma Key Filter (Green screen effect)

徘徊边缘 提交于 2019-11-27 06:09:07
问题 I'm trying to understand how this chroma key filter works. Chroma Key, if you don't know, is a green screen effect. Would someone be able to explain how some of these functions work and what they are doing exactly? float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b; float maskCr = 0.7132 * (colorToReplace.r - maskY); float maskCb = 0.5647 * (colorToReplace.b - maskY); float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 *

Does If-statements slow down my shader?

妖精的绣舞 提交于 2019-11-27 06:08:43
I want to know if "If-statements" inside shaders (vertex / fragment / pixel...) are realy slowing down the shader performance. For example: Is it better to use this: vec3 output; output = input*enable + input2*(1-enable); instead of using this: vec3 output; if(enable == 1) { output = input; } else { output = input2; } in another forum there was a talk about that (2013): http://answers.unity3d.com/questions/442688/shader-if-else-performance.html Here the guys are saying, that the If-statements are realy bad for the performance of the shader. Also here they are talking about how much is inside