progs: Get more samples building on windows.

This commit is contained in:
José Fonseca
2009-02-01 12:00:07 +00:00
parent 7062b7c7cb
commit 9aa73cfae8
11 changed files with 105 additions and 72 deletions

View File

@@ -1,4 +1,5 @@
SConscript([ SConscript([
'util/SConscript',
'demos/SConscript', 'demos/SConscript',
'trivial/SConscript', 'trivial/SConscript',
'vp/SConscript', 'vp/SConscript',

View File

@@ -1,11 +1,22 @@
Import('env') Import('*')
if not env['GLUT']: if not env['GLUT']:
Return() Return()
env = env.Clone() env = env.Clone()
env.Prepend(LIBS = ['$GLUT_LIB']) env.Prepend(CPPPATH = [
'../util',
])
env.Prepend(LIBS = [
util,
'$GLUT_LIB'
])
if env['platform'] == 'windows':
env.Append(CPPDEFINES = ['NOMINMAX'])
env.Prepend(LIBS = ['winmm'])
progs = [ progs = [
'arbfplight', 'arbfplight',
@@ -38,7 +49,6 @@ progs = [
'multiarb', 'multiarb',
'paltex', 'paltex',
'pointblast', 'pointblast',
'rain',
'ray', 'ray',
'readpix', 'readpix',
'reflect', 'reflect',
@@ -65,7 +75,15 @@ progs = [
] ]
for prog in progs: for prog in progs:
prog = env.Program( env.Program(
target = prog, target = prog,
source = prog + '.c', source = prog + '.c',
) )
env.Program(
target = 'rain',
source = [
'rain.cxx',
'particles.cxx',
]
)

View File

@@ -7,19 +7,16 @@
* Daniel Borca * Daniel Borca
*/ */
#define GL_GLEXT_PROTOTYPES
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <GL/glew.h>
#include <GL/glut.h> #include <GL/glut.h>
#define DEPTH 5.0f #define DEPTH 5.0f
static PFNGLFOGCOORDFEXTPROC glFogCoordf_ext;
static PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointer_ext; static PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointer_ext;
static GLboolean have_fog_coord;
static GLfloat camz; static GLfloat camz;
static GLint fogMode; static GLint fogMode;
@@ -45,10 +42,11 @@ Reset(void)
} }
static void APIENTRY static void
glFogCoordf_nop (GLfloat f) glFogCoordf_ext (GLfloat f)
{ {
(void)f; if (fogCoord)
glFogCoordfEXT(f);
} }
@@ -120,14 +118,11 @@ SetFogMode(GLint fogMode)
static GLboolean static GLboolean
SetFogCoord(GLboolean fogCoord) SetFogCoord(GLboolean fogCoord)
{ {
glFogCoordf_ext = glFogCoordf_nop; if (!GLEW_EXT_fog_coord) {
if (!have_fog_coord) {
return GL_FALSE; return GL_FALSE;
} }
if (fogCoord) { if (fogCoord) {
glFogCoordf_ext = (PFNGLFOGCOORDFEXTPROC)glutGetProcAddress("glFogCoordfEXT");
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
} }
else { else {
@@ -372,8 +367,7 @@ Init(void)
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
have_fog_coord = glutExtensionSupported("GL_EXT_fog_coord"); if (!GLEW_EXT_fog_coord) {
if (!have_fog_coord) {
printf("GL_EXT_fog_coord not supported!\n"); printf("GL_EXT_fog_coord not supported!\n");
} }
@@ -400,10 +394,9 @@ Init(void)
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texcoord_pointer); glTexCoordPointer(2, GL_FLOAT, 0, texcoord_pointer);
if (have_fog_coord) { if (GLEW_EXT_fog_coord) {
glFogCoordPointer_ext = (PFNGLFOGCOORDPOINTEREXTPROC)glutGetProcAddress("glFogCoordPointerEXT");
glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT); glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
glFogCoordPointer_ext(GL_FLOAT, 0, fogcoord_pointer); glFogCoordPointerEXT(GL_FLOAT, 0, fogcoord_pointer);
} }
Reset(); Reset();
@@ -417,6 +410,7 @@ main( int argc, char *argv[] )
glutInitWindowSize( 600, 600 ); glutInitWindowSize( 600, 600 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow(argv[0]); glutCreateWindow(argv[0]);
glewInit();
glutReshapeFunc( Reshape ); glutReshapeFunc( Reshape );
glutKeyboardFunc( Key ); glutKeyboardFunc( Key );
glutDisplayFunc( Display ); glutDisplayFunc( Display );

View File

@@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <GL/glew.h>
#include <GL/glut.h> #include <GL/glut.h>
#include "readtex.h" #include "readtex.h"
@@ -438,6 +439,7 @@ int main( int argc, char *argv[] )
glutInitWindowSize(WinWidth, WinHeight); glutInitWindowSize(WinWidth, WinHeight);
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow(argv[0] ); glutCreateWindow(argv[0] );
glewInit();
glutReshapeFunc( Reshape ); glutReshapeFunc( Reshape );
glutKeyboardFunc( Key ); glutKeyboardFunc( Key );
glutDisplayFunc( Display ); glutDisplayFunc( Display );

View File

@@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <GL/glew.h>
#include <GL/glut.h> #include <GL/glut.h>
#include "readtex.h" #include "readtex.h"
@@ -326,6 +327,7 @@ int main( int argc, char *argv[] )
glutInitWindowPosition( 0, 0 ); glutInitWindowPosition( 0, 0 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow(argv[0] ); glutCreateWindow(argv[0] );
glewInit();
Init( argc, argv ); Init( argc, argv );

View File

@@ -24,8 +24,6 @@ extern "C" {
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include "particles.cxx"
#include "readtex.c"
#endif #endif
#ifdef XMESA #ifdef XMESA

View File

@@ -18,7 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <GL/gl.h> #include <GL/glew.h>
#include <GL/glut.h> #include <GL/glut.h>
@@ -662,6 +662,8 @@ main(int argc, char **argv)
exit(0); exit(0);
} }
glewInit();
init(); init();
printHelp(); printHelp();

View File

@@ -11,7 +11,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#endif #endif
#define GL_GLEXT_PROTOTYPES #include "GL/glew.h"
#include "GL/glut.h" #include "GL/glut.h"
#include "readtex.h" #include "readtex.h"
@@ -29,8 +29,7 @@ static GLubyte *Image;
static int ImgWidth, ImgHeight; static int ImgWidth, ImgHeight;
static GLenum ImgFormat; static GLenum ImgFormat;
typedef void (APIENTRY * PFNWINDOWPOSFUNC)(GLfloat x, GLfloat y); static PFNGLWINDOWPOS2FPROC WindowPosFunc;
static PFNWINDOWPOSFUNC WindowPosFunc;
static void draw( void ) static void draw( void )
{ {
@@ -71,19 +70,16 @@ static void reshape( int width, int height )
static void init( void ) static void init( void )
{ {
#ifdef GL_ARB_window_pos if (GLEW_ARB_window_pos) {
if (glutExtensionSupported("GL_ARB_window_pos")) {
printf("Using GL_ARB_window_pos\n"); printf("Using GL_ARB_window_pos\n");
WindowPosFunc = &glWindowPos2fARB; WindowPosFunc = glWindowPos2fARB;
} }
else else
#elif defined(GL_MESA_window_pos) if (GLEW_MESA_window_pos) {
if (glutExtensionSupported("GL_MESA_window_pos")) {
printf("Using GL_MESA_window_pos\n"); printf("Using GL_MESA_window_pos\n");
WindowPosFunc = &glWindowPos2fMESA; WindowPosFunc = glWindowPos2fMESA;
} }
else else
#endif
{ {
printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n"); printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n");
exit(1); exit(1);
@@ -109,6 +105,8 @@ int main( int argc, char *argv[] )
exit(0); exit(0);
} }
glewInit();
init(); init();
glutReshapeFunc( reshape ); glutReshapeFunc( reshape );

View File

@@ -5,10 +5,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <GL/gl.h> #include <GL/glew.h>
#include <GL/glut.h> #include <GL/glut.h>
#include <GL/glext.h>
#include "extfuncs.h"
static GLuint fragShader; static GLuint fragShader;
@@ -56,9 +54,9 @@ Reshape(int width, int height)
static void static void
CleanUp(void) CleanUp(void)
{ {
glDeleteShader_func(fragShader); glDeleteShader(fragShader);
glDeleteShader_func(vertShader); glDeleteShader(vertShader);
glDeleteProgram_func(program); glDeleteProgram(program);
glutDestroyWindow(win); glutDestroyWindow(win);
} }
@@ -110,15 +108,15 @@ LoadAndCompileShader(GLuint shader, const char *text)
{ {
GLint stat; GLint stat;
glShaderSource_func(shader, 1, (const GLchar **) &text, NULL); glShaderSource(shader, 1, (const GLchar **) &text, NULL);
glCompileShader_func(shader); glCompileShader(shader);
glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat); glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
if (!stat) { if (!stat) {
GLchar log[1000]; GLchar log[1000];
GLsizei len; GLsizei len;
glGetShaderInfoLog_func(shader, 1000, &len, log); glGetShaderInfoLog(shader, 1000, &len, log);
fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log); fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log);
exit(1); exit(1);
} }
@@ -129,11 +127,11 @@ static void
CheckLink(GLuint prog) CheckLink(GLuint prog)
{ {
GLint stat; GLint stat;
glGetProgramiv_func(prog, GL_LINK_STATUS, &stat); glGetProgramiv(prog, GL_LINK_STATUS, &stat);
if (!stat) { if (!stat) {
GLchar log[1000]; GLchar log[1000];
GLsizei len; GLsizei len;
glGetProgramInfoLog_func(prog, 1000, &len, log); glGetProgramInfoLog(prog, 1000, &len, log);
fprintf(stderr, "Linker error:\n%s\n", log); fprintf(stderr, "Linker error:\n%s\n", log);
} }
} }
@@ -165,24 +163,22 @@ Init(void)
exit(1); exit(1);
} }
GetExtensionFuncs(); fragShader = glCreateShader(GL_FRAGMENT_SHADER);
fragShader = glCreateShader_func(GL_FRAGMENT_SHADER);
LoadAndCompileShader(fragShader, fragShaderText); LoadAndCompileShader(fragShader, fragShaderText);
#if 0 #if 0
vertShader = glCreateShader_func(GL_VERTEX_SHADER); vertShader = glCreateShader(GL_VERTEX_SHADER);
LoadAndCompileShader(vertShader, vertShaderText); LoadAndCompileShader(vertShader, vertShaderText);
#endif #endif
program = glCreateProgram_func(); program = glCreateProgram();
glAttachShader_func(program, fragShader); glAttachShader(program, fragShader);
#if 0 #if 0
glAttachShader_func(program, vertShader); glAttachShader(program, vertShader);
#endif #endif
glLinkProgram_func(program); glLinkProgram(program);
CheckLink(program); CheckLink(program);
glUseProgram_func(program); glUseProgram(program);
assert(glGetError() == 0); assert(glGetError() == 0);
@@ -200,6 +196,7 @@ main(int argc, char *argv[])
glutInitWindowSize(200, 200); glutInitWindowSize(200, 200);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
win = glutCreateWindow(argv[0]); win = glutCreateWindow(argv[0]);
glewInit();
glutReshapeFunc(Reshape); glutReshapeFunc(Reshape);
glutKeyboardFunc(Key); glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey); glutSpecialFunc(SpecialKey);

15
progs/util/SConscript Normal file
View File

@@ -0,0 +1,15 @@
Import('env')
env = env.Clone()
util = env.StaticLibrary(
target = ['util'],
source = [
'readtex.c',
'trackball.c',
'showbuffer.c',
'shaderutil.c',
],
)
Export('util')

View File

@@ -303,7 +303,7 @@ def generate(env):
#'_UNICODE', #'_UNICODE',
#'UNICODE', #'UNICODE',
# http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx, # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
'WIN32_LEAN_AND_MEAN', #'WIN32_LEAN_AND_MEAN',
'VC_EXTRALEAN', 'VC_EXTRALEAN',
'_CRT_SECURE_NO_DEPRECATE', '_CRT_SECURE_NO_DEPRECATE',
] ]
@@ -362,24 +362,26 @@ def generate(env):
]) ])
# C compiler options # C compiler options
cflags = [] cflags = [] # C
cxxflags = [] # C++
ccflags = [] # C & C++
if gcc: if gcc:
if debug: if debug:
cflags += ['-O0', '-g3'] ccflags += ['-O0', '-g3']
else: else:
cflags += ['-O3', '-g0'] ccflags += ['-O3', '-g0']
if env['profile']: if env['profile']:
cflags += ['-pg'] ccflags += ['-pg']
if env['machine'] == 'x86': if env['machine'] == 'x86':
cflags += [ ccflags += [
'-m32', '-m32',
#'-march=pentium4', #'-march=pentium4',
'-mmmx', '-msse', '-msse2', # enable SIMD intrinsics '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
#'-mfpmath=sse', #'-mfpmath=sse',
] ]
if env['machine'] == 'x86_64': if env['machine'] == 'x86_64':
cflags += ['-m64'] ccflags += ['-m64']
cflags += [ ccflags += [
'-Wall', '-Wall',
'-Wmissing-prototypes', '-Wmissing-prototypes',
'-Wno-long-long', '-Wno-long-long',
@@ -387,43 +389,46 @@ def generate(env):
'-pedantic', '-pedantic',
'-fmessage-length=0', # be nice to Eclipse '-fmessage-length=0', # be nice to Eclipse
] ]
cflags += [
'-Wmissing-prototypes',
]
if msvc: if msvc:
# See also: # See also:
# - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
# - cl /? # - cl /?
if debug: if debug:
cflags += [ ccflags += [
'/Od', # disable optimizations '/Od', # disable optimizations
'/Oi', # enable intrinsic functions '/Oi', # enable intrinsic functions
'/Oy-', # disable frame pointer omission '/Oy-', # disable frame pointer omission
] ]
else: else:
cflags += [ ccflags += [
'/Ox', # maximum optimizations '/Ox', # maximum optimizations
'/Oi', # enable intrinsic functions '/Oi', # enable intrinsic functions
'/Ot', # favor code speed '/Ot', # favor code speed
#'/fp:fast', # fast floating point #'/fp:fast', # fast floating point
] ]
if env['profile']: if env['profile']:
cflags += [ ccflags += [
'/Gh', # enable _penter hook function '/Gh', # enable _penter hook function
'/GH', # enable _pexit hook function '/GH', # enable _pexit hook function
] ]
cflags += [ ccflags += [
'/W3', # warning level '/W3', # warning level
#'/Wp64', # enable 64 bit porting warnings #'/Wp64', # enable 64 bit porting warnings
] ]
if env['machine'] == 'x86': if env['machine'] == 'x86':
cflags += [ ccflags += [
#'/QIfist', # Suppress _ftol #'/QIfist', # Suppress _ftol
#'/arch:SSE2', # use the SSE2 instructions #'/arch:SSE2', # use the SSE2 instructions
] ]
if platform == 'windows': if platform == 'windows':
cflags += [ ccflags += [
# TODO # TODO
] ]
if platform == 'winddk': if platform == 'winddk':
cflags += [ ccflags += [
'/Zl', # omit default library name in .OBJ '/Zl', # omit default library name in .OBJ
'/Zp8', # 8bytes struct member alignment '/Zp8', # 8bytes struct member alignment
'/Gy', # separate functions for linker '/Gy', # separate functions for linker
@@ -442,7 +447,7 @@ def generate(env):
] ]
if platform == 'wince': if platform == 'wince':
# See also C:\WINCE600\public\common\oak\misc\makefile.def # See also C:\WINCE600\public\common\oak\misc\makefile.def
cflags += [ ccflags += [
'/Zl', # omit default library name in .OBJ '/Zl', # omit default library name in .OBJ
'/GF', # enable read-only string pooling '/GF', # enable read-only string pooling
'/GR-', # disable C++ RTTI '/GR-', # disable C++ RTTI
@@ -459,8 +464,9 @@ def generate(env):
# See http://scons.tigris.org/issues/show_bug.cgi?id=1656 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
env.EnsureSConsVersion(0, 98, 0) env.EnsureSConsVersion(0, 98, 0)
env['PDB'] = '${TARGET.base}.pdb' env['PDB'] = '${TARGET.base}.pdb'
env.Append(CCFLAGS = ccflags)
env.Append(CFLAGS = cflags) env.Append(CFLAGS = cflags)
env.Append(CXXFLAGS = cflags) env.Append(CXXFLAGS = cxxflags)
if env['platform'] == 'windows' and msvc: if env['platform'] == 'windows' and msvc:
# Choose the appropriate MSVC CRT # Choose the appropriate MSVC CRT