diff options
Diffstat (limited to 'sdl/platform.c')
-rw-r--r-- | sdl/platform.c | 81 |
1 files changed, 56 insertions, 25 deletions
diff --git a/sdl/platform.c b/sdl/platform.c index 270a938..677b5b8 100644 --- a/sdl/platform.c +++ b/sdl/platform.c @@ -2,6 +2,7 @@ * * Platform * + * Notes: Assumes multisampling is always enabled * */ @@ -11,15 +12,14 @@ #include "platform.h" /* few light arrays */ -GLfloat fNoLight[] = { 0.0f, 0.0f, 0.0f, 0.0f }; -GLfloat fLowLight[] = { 0.25f, 0.25f, 0.25f, 1.0f }; -GLfloat fMedLight[] = { 0.50f, 0.50f, 0.50f, 1.0f }; -GLfloat fBrightLight[] = { 1.0f, 1.0f, 1.0f, 1.0f }; +const GLfloat fNoLight[] = { 0.0f, 0.0f, 0.0f, 1.0f }; +const GLfloat fLowLight[] = { 0.25f, 0.25f, 0.25f, 1.0f }; +const GLfloat fMedLight[] = { 0.50f, 0.50f, 0.50f, 1.0f }; +const GLfloat fShinyLight[] = { 0.70f, 0.70f, 0.70f, 1.0f }; +const GLfloat fBrightLight[] = { 1.0f, 1.0f, 1.0f, 1.0f }; /* light values and coordinates */ -GLfloat whiteLight[] = { 0.05f, 0.05f, 0.05f, 1.0f }; -GLfloat sourceLight[] = { 0.75f, 0.75f, 0.75f, 1.0f }; -GLfloat lightPos[] = { -10.f, 5.0f, 5.0f, 1.0f }; +const GLfloat lightPos[] = { -10.f, 5.0f, 5.0f, 1.0f }; /* variables that should be already defined and declared for us by main program */ extern const unsigned int xres_w; @@ -38,47 +38,74 @@ void setup_opengl(void) glFogf(GL_FOG_END, 20.0f); glFogi(GL_FOG_MODE, GL_LINEAR); /* fog equation */ - glEnable(GL_DEPTH_TEST); /* hidden surface removal */ + glEnable(GL_DEPTH_TEST); /* hidden surface removal, aka Z-buffer */ glFrontFace(GL_CCW); /* counter clock-wise polygons face out */ glEnable(GL_CULL_FACE); /* do not calculate inside of a pyramid */ - /* enable lighting */ + /* enable lighting, primitives now need to define color properties */ glEnable(GL_LIGHTING); /* global illumination, ambient RGBA intensity of the entire scene */ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fLowLight); /* setup and enable light 0 */ - glLightfv(GL_LIGHT0, GL_AMBIENT, fMedLight); - glLightfv(GL_LIGHT0, GL_DIFFUSE, fMedLight); + glLightfv(GL_LIGHT0, GL_AMBIENT, fMedLight); + glLightfv(GL_LIGHT0, GL_DIFFUSE, fShinyLight); glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glEnable(GL_LIGHT0); - /* enable color tracking */ - glEnable(GL_COLOR_MATERIAL); - - /* set material properties to follow glColor values */ + /* set material properties to follow all glColor values */ /* all primitives specified after the glMaterial call are affected by the * last values set, until another call to glMaterial is made */ glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); + + /* enable color tracking, should be called after glColorMaterial */ + glEnable(GL_COLOR_MATERIAL); + + /* set globally, sets specular reflection to a white color, + * this call follows all subsequent primitives */ glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight); - glMateriali(GL_FRONT, GL_SHININESS, 128); - /* turn on anti aliasing for points, lines, and polygons */ + /* default (0), by increasing this value you reduce the size and increase + * the focus of the specular highlight, causing a shiny spot to appear */ + glMateriali(GL_FRONT, GL_SHININESS, 64); + + /* multisampling for polygons, conflicts with *polygon* anti-aliasing */ + /* enabled by default, that's what man page says, hmmm! */ + glEnable(GL_MULTISAMPLE); + + if (glIsEnabled(GL_MULTISAMPLE) == GL_FALSE) + { + fprintf(stderr, "OpenGL error: multisampling cannot be enabled!\n"); + exit(-1); + } + + /* turn off AA forever, it enables blending globally, so depth test goes out + * of the window, blended objects should be rendered in back to front order, + * also, following lines are ignored by OpenGL if multisampling is enabled */ +#if 0 + /* turn on anti aliasing for points and lines */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); +#endif - /* screws up snowman, this has been replaced by superior multisampling */ - //glEnable(GL_POLYGON_SMOOTH); - //glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); + /* we will keep the blending function and hints though */ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - /* multisampling for polygons, conflicts with *polygon* anti-aliasing */ - glEnable(GL_MULTISAMPLE); + /* XXX: anisotropic filtering */ + +#if 0 + /* screws up snowman, this has been replaced by superior multisampling */ + glEnable(GL_POLYGON_SMOOTH); + glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); +#endif /* how OpenGL combines the colors from texels with the color of the underlying * geometry is controlled by the texture environment mode */ @@ -88,8 +115,11 @@ void setup_opengl(void) * that specifies coordinates, ORLY? */ glEnable(GL_TEXTURE_2D); - /* don't know about this, but why not */ + /* specular highlights for textured items */ glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); + /* glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_COLOR_SINGLE); */ + /* only if lighting is disabled */ + /* glEnable(GL_COLOR_SUM); */ /* gray background */ glClearColor(0.5f, 0.5f, 0.5f, 1.0f); @@ -127,7 +157,7 @@ SDL_Surface *setup_sdl_video(int w, int h, int bpp, unsigned int flags) return srfc; } -void setup_sdl(void) +SDL_Surface *setup_sdl(void) { SDL_Surface *screen; const SDL_VideoInfo* info = NULL; @@ -194,6 +224,7 @@ void setup_sdl(void) SDL_PushEvent(&resizeEvent); /* save the surf pointer in platform */ + return screen; } void setup_glew(void) @@ -213,6 +244,6 @@ void setup_glew(void) GLint minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); - fprintf(stdout, "GLEW: detected OpenGL %d.%d\n", major, minor); + fprintf(stdout, "GLEW: initialized OpenGL %d.%d\n", major, minor); } |