OpenGL default shaders?

Hi, if I want to start out with a vertex shader and a fragment shader that I know work, just to see if my code for loading the shaders works, does there exist any shaders which I can get that will definitely work for my program? For example, before any shaders are loaded at all, I guess OpenGL has some shaders of it’s own that it is using and they would definitely work. Is it possible to find them somewhere?

Unless otherwise, it would be interesting just to take a look at them and see how hey are coded.

There is no such thing as default shaders.

If you need the simplest possible shaders, then you can try these:

vertex shader


void main() { gl_Position = gl_Vertex; }

fragment shader


void main() { gl_FragColor = vec4(1,1,0,1); }

There is no such thing as default shaders.

Not quite right!
How do you think fixed pipeline is implemented nowadays?

But:

  1. That is a proprietary code of GL drivers vendors.
  2. The code is so complex (and probably optimized) that even a skillful programmer could hardly understand how it works (This is my guess, of course. I didn’t see the code)

So, misq, if you are interested in how fixed functionality is “emulated” with shaders take a look OpenGL Shading Language 2nd or 3rd edition. If you are interested only in testing your loading code, create shaders as simple as possible. Kyle gave you good example for GLSL 1.1. It can even remove input vertex attribute, and set a constant value for the position.

Probably this is better

uniform mat4 ProjectionModelviewMatrix;
void main() { gl_Position = ProjectionModelviewMatrix * gl_Vertex; }

and download some math library that computes matrices and upload to ProjectionModelviewMatrix.
Use GLM if you want.

I have now implemented all the code: It successfully creates and compiles two shaders (the vert and the frag shaders that kyle_ gave as an example, thank you!), creates a shader program and attaches the shaders, links the program and finally calls glUseProgram on the shader program, but nothing happens.

I guess that with the code you gave me, everything that is rendered is rendered without any transformations at all, and also rendered in yellow (I’m not that used to GLSL programming yet :slight_smile: )?

Well, everything looks just like normal (transformed and a lot of colors). Anyone knows why no shader program is loaded? If your wondering what system I’m running it’s Windows 7, and I’m using glew for the OpenGL functionality that is not supported in my version of OpenGL (which seems to be v.1.1).

I just notice one difference in my program; when I resize the window (I’m using wxWidgets as API), a resize event handler is called, but then it seems like the screen is re-rendered, because now the scene shows up for an extremely short moment on the rendering canvas and then the canvas goes completely black (which it didn’t before; just as if the shader program that is now loaded would be used when re-rendering the scene after a window resize, but not otherwise). But it seems strange that a shader program would be used only in some cases but not always; is that ever possible without calling glUseProgram in between? Hm, I should check if wxWidgets maybe is switching shader program without my knowledge, does that sound possible?

Edit: I tried calling glUseProgram before everytime I render, but it doesn’t seem to make any difference; the rendering still looks like normal, so it doesn’t seem likely that wxWidgets has turned off my shader program.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.