summaryrefslogtreecommitdiffstats
path: root/progs/slang/framework.c
blob: 692cef9c8cb523060b63283e196acc602afae973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "framework.h"

/*
 * GL_ARB_multitexture
 */
#ifndef GL_ARB_multitexture
PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;
PFNGLMULTITEXCOORD4FVARBPROC glMultiTexCoord4fvARB;
#endif

/*
 * GL_ARB_shader_objects
 */
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
PFNGLGETHANDLEARBPROC glGetHandleARB;
PFNGLDETACHOBJECTARBPROC glDetachObjectARB;
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;

/*
 * GL_ARB_vertex_shader
 */
PFNGLVERTEXATTRIB4FVARBPROC glVertexAttrib4fvARB;
PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB;
PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB;
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB;
PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB;
PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB;

/*
 * GL_EXT_fog_coord
 */
PFNGLFOGCOORDFVEXTPROC glFogCoordfvEXT;
PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT;

/*
 * GL_EXT_secondary_color
 */
PFNGLSECONDARYCOLOR3FVEXTPROC glSecondaryColor3fvEXT;
PFNGLSECONDARYCOLORPOINTEREXTPROC glSecondaryColorPointerEXT;

static void Display (void)
{
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   RenderScene ();
   glutSwapBuffers ();
}

static void Idle (void)
{
   glutPostRedisplay ();
}

void InitFramework (int *argc, char *argv[])
{
   glutInit (argc, argv);
   glutInitWindowPosition (0, 0);
   glutInitWindowSize (200, 200);
   glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
   glutCreateWindow (argv[0]);

#ifndef GL_ARB_multitexture
   GETPROCADDR(glClientActiveTextureARB, PFNGLCLIENTACTIVETEXTUREARBPROC);
   GETPROCADDR(glMultiTexCoord4fvARB, PFNGLMULTITEXCOORD4FVARBPROC);
#endif

   GETPROCADDR(glDeleteObjectARB, PFNGLDELETEOBJECTARBPROC);
   GETPROCADDR(glGetHandleARB, PFNGLGETHANDLEARBPROC);
   GETPROCADDR(glDetachObjectARB, PFNGLDETACHOBJECTARBPROC);
   GETPROCADDR(glCreateShaderObjectARB, PFNGLCREATESHADEROBJECTARBPROC);
   GETPROCADDR(glShaderSourceARB, PFNGLSHADERSOURCEARBPROC);
   GETPROCADDR(glCompileShaderARB, PFNGLCOMPILESHADERARBPROC);
   GETPROCADDR(glCreateProgramObjectARB, PFNGLCREATEPROGRAMOBJECTARBPROC);
   GETPROCADDR(glAttachObjectARB, PFNGLATTACHOBJECTARBPROC);
   GETPROCADDR(glLinkProgramARB, PFNGLLINKPROGRAMARBPROC);
   GETPROCADDR(glUseProgramObjectARB, PFNGLUSEPROGRAMOBJECTARBPROC);
   GETPROCADDR(glGetObjectParameterivARB, PFNGLGETOBJECTPARAMETERIVARBPROC);
   GETPROCADDR(glGetInfoLogARB, PFNGLGETINFOLOGARBPROC);
   GETPROCADDR(glGetUniformLocationARB, PFNGLGETUNIFORMLOCATIONARBPROC);

   GETPROCADDR(glVertexAttrib4fvARB, PFNGLVERTEXATTRIB4FVARBPROC);
   GETPROCADDR(glVertexAttribPointerARB, PFNGLVERTEXATTRIBPOINTERARBPROC);
   GETPROCADDR(glEnableVertexAttribArrayARB, PFNGLENABLEVERTEXATTRIBARRAYARBPROC);
   GETPROCADDR(glDisableVertexAttribArrayARB, PFNGLDISABLEVERTEXATTRIBARRAYARBPROC);
   GETPROCADDR(glBindAttribLocationARB, PFNGLBINDATTRIBLOCATIONARBPROC);
   GETPROCADDR(glGetAttribLocationARB, PFNGLGETATTRIBLOCATIONARBPROC);

   GETPROCADDR(glFogCoordfvEXT, PFNGLFOGCOORDFVEXTPROC);
   GETPROCADDR(glFogCoordPointerEXT, PFNGLFOGCOORDPOINTEREXTPROC);

   GETPROCADDR(glSecondaryColor3fvEXT, PFNGLSECONDARYCOLOR3FVEXTPROC);
   GETPROCADDR(glSecondaryColorPointerEXT, PFNGLSECONDARYCOLORPOINTEREXTPROC);

   printf ("VENDOR: %s\n", glGetString (GL_VENDOR));
   printf ("RENDERER: %s\n", glGetString (GL_RENDERER));

   InitScene ();

   glutDisplayFunc (Display);
   glutIdleFunc (Idle);
   glutMainLoop ();
}

GLboolean CheckObjectStatus (GLhandleARB handle)
{
   GLint type, status, length;
   GLcharARB *infolog;

   glGetObjectParameterivARB (handle, GL_OBJECT_TYPE_ARB, &type);
   if (type == GL_SHADER_OBJECT_ARB)
      glGetObjectParameterivARB (handle, GL_OBJECT_COMPILE_STATUS_ARB, &status);
   else if (type == GL_PROGRAM_OBJECT_ARB)
      glGetObjectParameterivARB (handle, GL_OBJECT_LINK_STATUS_ARB, &status);
   else {
      assert (0);
      return GL_FALSE;
   }

   if (status)
      return GL_TRUE;

   printf ("\n%s FAILED. INFO LOG FOLLOWS:\n",
           type == GL_SHADER_OBJECT_ARB ? "SHADER COMPILE" : "PROGRAM LINK");

   glGetObjectParameterivARB (handle, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
   infolog = (GLcharARB *) (malloc (length));
   if (infolog != NULL) {
      glGetInfoLogARB (handle, length, NULL, infolog);
      printf ("%s", infolog);
      free (infolog);
   }

   printf ("\n");

   return GL_FALSE;
}