139
138
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
140
139
info = SDL_stack_alloc(char, length+1);
141
140
glGetInfoLogARB(shader, length, NULL, info);
142
fprintf(stderr, "Failed to compile shader:\n%s\n%s", source, info);
141
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
143
142
SDL_stack_free(info);
145
144
return SDL_FALSE;
335
334
/* A general OpenGL initialization function. Sets all of the initial parameters. */
336
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
335
void InitGL(int Width, int Height) /* We call this right after our OpenGL window is created. */
340
339
glViewport(0, 0, Width, Height);
341
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
342
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
343
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
344
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
345
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
340
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* This Will Clear The Background Color To Black */
341
glClearDepth(1.0); /* Enables Clearing Of The Depth Buffer */
342
glDepthFunc(GL_LESS); /* The Type Of Depth Test To Do */
343
glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */
344
glShadeModel(GL_SMOOTH); /* Enables Smooth Color Shading */
347
346
glMatrixMode(GL_PROJECTION);
348
glLoadIdentity(); // Reset The Projection Matrix
347
glLoadIdentity(); /* Reset The Projection Matrix */
350
349
aspect = (GLdouble)Width / Height;
351
350
glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
367
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
368
glLoadIdentity(); // Reset The View
370
glTranslatef(-1.5f,0.0f,0.0f); // Move Left 1.5 Units
372
// draw a triangle (in smooth coloring mode)
373
glBegin(GL_POLYGON); // start drawing a polygon
374
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
375
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
376
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
377
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
378
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
379
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
380
glEnd(); // we're done with the polygon (smooth color interpolation)
382
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
366
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */
367
glLoadIdentity(); /* Reset The View */
369
glTranslatef(-1.5f,0.0f,0.0f); /* Move Left 1.5 Units */
371
/* draw a triangle (in smooth coloring mode) */
372
glBegin(GL_POLYGON); /* start drawing a polygon */
373
glColor3f(1.0f,0.0f,0.0f); /* Set The Color To Red */
374
glVertex3f( 0.0f, 1.0f, 0.0f); /* Top */
375
glColor3f(0.0f,1.0f,0.0f); /* Set The Color To Green */
376
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
377
glColor3f(0.0f,0.0f,1.0f); /* Set The Color To Blue */
378
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
379
glEnd(); /* we're done with the polygon (smooth color interpolation) */
381
glTranslatef(3.0f,0.0f,0.0f); /* Move Right 3 Units */
383
/* Enable blending */
385
384
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
386
385
glEnable(GL_BLEND);
387
386
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
389
// draw a textured square (quadrilateral)
388
/* draw a textured square (quadrilateral) */
390
389
glEnable(GL_TEXTURE_2D);
391
390
glBindTexture(GL_TEXTURE_2D, texture);
392
391
glColor3f(1.0f,1.0f,1.0f);
394
393
glUseProgramObjectARB(shaders[current_shader].program);
397
glBegin(GL_QUADS); // start drawing a polygon (4 sided)
396
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
398
397
glTexCoord2f(texcoord[MINX], texcoord[MINY]);
399
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
398
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left */
400
399
glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
401
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
400
glVertex3f( 1.0f, 1.0f, 0.0f); /* Top Right */
402
401
glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
403
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
402
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
404
403
glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
405
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
406
glEnd(); // done with the polygon
404
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
405
glEnd(); /* done with the polygon */
408
407
if (shaders_supported) {
409
408
glUseProgramObjectARB(0);
411
410
glDisable(GL_TEXTURE_2D);
413
// swap buffers to display, since we're double buffered.
412
/* swap buffers to display, since we're double buffered. */
414
413
SDL_GL_SwapWindow(window);
423
422
GLfloat texcoords[4];
424
/* Enable standard application logging */
425
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
425
427
/* Initialize SDL for video output */
426
428
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
427
fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
429
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
431
433
/* Create a 640x480 OpenGL screen */
432
434
window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
434
fprintf(stderr, "Unable to create OpenGL window: %s\n", SDL_GetError());
436
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
439
441
if ( !SDL_GL_CreateContext(window)) {
440
fprintf(stderr, "Unable to create OpenGL context: %s\n", SDL_GetError());
442
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError());
445
447
surface = SDL_LoadBMP("icon.bmp");
446
448
if ( ! surface ) {
447
fprintf(stderr, "Unable to load icon.bmp: %s\n", SDL_GetError());
449
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
454
456
/* Loop, drawing and checking events */
455
457
InitGL(640, 480);
456
458
if (InitShaders()) {
457
printf("Shaders supported, press SPACE to cycle them.\n");
459
SDL_Log("Shaders supported, press SPACE to cycle them.\n");
459
printf("Shaders not supported!\n");
461
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Shaders not supported!\n");
462
464
while ( ! done ) {