Hi all,
Here is some source code.
Its 1k, devCpp, gcc compatible.
Its opengl 2.0 and ps/vs 2.0 compliant.
With no ordinal import it compresses to 1k!!!
So here is an example of how to code GLSL shaders in 1k ... in C..a first I think..
// sek the intro fairy...
// use and abuse but a credit is a wonderful thing
// t2 sek would do.
#include <process.h>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
typedef unsigned char uchar;
typedef unsigned int uint;
// the vertex shader where most of the work is done...
const GLchar *vsh="\
varying vec4 c;\
void main(){\
gl_Position=gl_Vertex+\
vec4(gl_Normal,1)*\
abs(dot(sin((gl_Vertex+ftransform())*9.9),vec4(4)));\
c=cos(gl_Position*0.04)*length(gl_Position*0.04);\
}";
// the fragment shader - do as litte as possible here...
// take c and interpolate and ssign to the ouput fragcolor...
const GLchar *fsh="\
varying vec4 c;\
void main(){\
gl_FragColor=c;\
}";
typedef void (*GenFP)(void); // any function ptr type would do
static GenFP glFP[7];
const static char* glnames[]={
"glCreateShader", "glShaderSource", "glCompileShader",
"glCreateProgram", "glAttachShader", "glLinkProgram", "glUseProgram"
};
static void setShaders() {
int i;
for (i=0; i<7; i++) glFP[i] = wglGetProcAddress(glnames[i]);
GLuint v = ((PFNGLCREATESHADERPROC)(glFP[0]))(GL_VERTEX_SHADER);
GLuint f = ((PFNGLCREATESHADERPROC)(glFP[0]))(GL_FRAGMENT_SHADER);
GLuint p = ((PFNGLCREATEPROGRAMPROC)glFP[3])();
((PFNGLSHADERSOURCEPROC)glFP[1]) (v, 1, &vsh, NULL);
((PFNGLCOMPILESHADERPROC)glFP[2])(v);
((PFNGLSHADERSOURCEPROC)glFP[1]) (f, 1, &fsh, NULL);
((PFNGLCOMPILESHADERPROC)glFP[2])(f);
((PFNGLATTACHSHADERPROC)glFP[4])(p,v);
((PFNGLATTACHSHADERPROC)glFP[4])(p,f);
((PFNGLLINKPROGRAMPROC)glFP[5])(p);
((PFNGLUSEPROGRAMPROC) glFP[6])(p);
}
static PIXELFORMATDESCRIPTOR pfd;
void WINAPI WinMainCRTStartup()
{
// minimal windows setup code for opengl
pfd.cColorBits = pfd.cDepthBits = 32;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
PVOID hDC= GetDC ( CreateWindow("edit", 0,
WS_POPUP|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZE,
0, 0, 0,0, 0, 0, 0, 0) );
SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, &pfd) , &pfd );
wglMakeCurrent ( hDC, wglCreateContext(hDC) );
setShaders();
ShowCursor(FALSE);
//**********************
// NOW THE MAIN LOOP...
//**********************
// there is no depth test or clear screen...as we draw in order and cover
// the whole area of the screen.
do {
// we draw 3 spheres using the same shader which is *very* senesitive to radius
// so we see a 3 fold effect ... a trinity
glRotatef(3,3,3,3);
gluSphere(gluNewQuadric(),1.6,200,200);
gluSphere(gluNewQuadric(),1.04,200,200);
gluSphere(gluNewQuadric(),0.4,200,200);
SwapBuffers(hDC);
} while ( !GetAsyncKeyState(VK_ESCAPE) );
}
It draws 3 spheres and rotates them.
In order to apply different shaders simply substitute different strings for vsh and fsh.
TheFairy