~ubuntu-branches/ubuntu/jaunty/mesa/jaunty

« back to all changes in this revision

Viewing changes to progs/glsl/twoside.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-01-23 10:20:24 UTC
  • mfrom: (1.2.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090123102024-1f3kmb3aea7wzk67
Tags: 7.3~rc3-1ubuntu1
* Merge with Debian experimental.
* Drop 102_dont_vblank.patch, since the new drm code in the kernel
  fixes the bugs that it worked around.
* Bump the build-dependency of libdrm to 2.4.4. It's the first version
  with necessary changes to build this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
static GLuint vertShader;
27
27
static GLuint program;
28
28
static GLint win = 0;
29
 
static GLboolean anim = 0*GL_TRUE;
30
 
static GLboolean DetermineInFragProg = GL_TRUE;
31
 
static GLfloat Xrot = 30.0f;
 
29
static GLboolean anim;
 
30
static GLboolean DetermineFacingInFragProg;
 
31
static GLfloat Xrot;
32
32
static GLint u_fragface;
33
 
static GLenum FrontWinding = GL_CCW;
 
33
static GLenum FrontWinding;
34
34
static int prevTime = 0;
35
35
 
36
36
 
37
 
static const GLfloat Red[4] = {1, 0, 0, 0};
 
37
static const GLfloat Red[4] = {1, 0, 0, 1};
38
38
static const GLfloat Green[4] = {0, 1, 0, 0};
39
39
 
40
40
 
41
41
static void
 
42
SetDefaults(void)
 
43
{
 
44
   DetermineFacingInFragProg = GL_TRUE;
 
45
   FrontWinding = GL_CCW;
 
46
   Xrot = 30;
 
47
   anim = 0;
 
48
   glutIdleFunc(NULL);
 
49
}
 
50
 
 
51
 
 
52
static void
42
53
Redisplay(void)
43
54
{
 
55
   const int sections = 20;
44
56
   int i;
45
57
   float radius = 2;
46
58
 
47
59
   glFrontFace(FrontWinding);
48
60
 
49
 
   if (DetermineInFragProg) {
 
61
   if (DetermineFacingInFragProg) {
50
62
      glUniform1i_func(u_fragface, 1);
51
63
      glDisable(GL_VERTEX_PROGRAM_TWO_SIDE);
52
64
   }
64
76
   glBegin(GL_TRIANGLE_STRIP);
65
77
   glColor4fv(Red);
66
78
   glSecondaryColor3fv_func(Green);
67
 
   for (i = 0; i < 20; i++) {
68
 
      float a = i / 19.0 * M_PI * 2.0;
 
79
   for (i = 0; i <= sections; i++) {
 
80
      float a = (float) i / (sections) * M_PI * 2.0;
69
81
      float x = radius * cos(a);
70
82
      float y = radius * sin(a);
71
83
      glVertex3f(x, -1, y);
139
151
      break;
140
152
   case 'f':
141
153
      printf("Using frag shader gl_FrontFacing\n");
142
 
      DetermineInFragProg = GL_TRUE;
 
154
      DetermineFacingInFragProg = GL_TRUE;
143
155
      break;
144
156
   case 'v':
145
157
      printf("Using vert shader Two-sided lighting\n");
146
 
      DetermineInFragProg = GL_FALSE;
 
158
      DetermineFacingInFragProg = GL_FALSE;
147
159
      break;
148
160
   case 'r':
149
161
      /* reset */
150
 
      Xrot = 30;
151
 
      anim = 0;
152
 
      glutIdleFunc(NULL);
 
162
      SetDefaults();
153
163
      break;
154
164
   case 's':
155
165
      Xrot += 5;
182
192
   static const char *fragShaderText =
183
193
      "uniform bool fragface; \n"
184
194
      "void main() { \n"
185
 
#if 0
 
195
#if 1
186
196
      "   if (!fragface || gl_FrontFacing) { \n"
187
197
      "      gl_FragColor = gl_Color; \n"
188
198
      "   } \n"
189
199
      "   else { \n"
 
200
      "      // note: dim green to help debug \n"
190
201
      "      gl_FragColor = 0.8 * gl_SecondaryColor; \n"
191
202
      "   } \n"
192
203
#else
 
204
      /* DEBUG CODE */
193
205
      "   bool f = gl_FrontFacing; \n"
194
206
      "   if (f) { \n"
195
207
      "      gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0); \n"
197
209
      "   else { \n"
198
210
      "      gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0); \n"
199
211
      "   } \n"
200
 
      "   //float g = float(gl_FrontFacing) * 0.5 + 0.5; \n"
201
 
      "   //gl_FragColor = vec4(g); \n"
202
212
#endif
203
213
      "} \n";
204
214
   static const char *vertShaderText =
241
251
   assert(glIsShader_func(vertShader));
242
252
 
243
253
   glEnable(GL_DEPTH_TEST);
 
254
 
 
255
   SetDefaults();
244
256
}
245
257
 
246
258