# HG changeset patch # User John Tsiombikas # Date 1384651360 -7200 # Node ID 18879c956eb1750139d314b07915140f932eda3c # Parent ae47239c8c0da03de92aeab6e6a9257bbe0fbae6 - skycube example - added fatal_log - changed the dataset to keep the whole path while searching for data files diff -r ae47239c8c0d -r 18879c956eb1 examples/cubemap/cubemap.vcproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/cubemap/cubemap.vcproj Sun Nov 17 03:22:40 2013 +0200 @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r ae47239c8c0d -r 18879c956eb1 examples/cubemap/sdr/sky.p.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/cubemap/sdr/sky.p.glsl Sun Nov 17 03:22:40 2013 +0200 @@ -0,0 +1,8 @@ +uniform samplerCube cubemap; + +varying vec3 norm; + +void main() +{ + gl_FragColor = textureCube(cubemap, norm); +} diff -r ae47239c8c0d -r 18879c956eb1 examples/cubemap/sdr/sky.v.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/cubemap/sdr/sky.v.glsl Sun Nov 17 03:22:40 2013 +0200 @@ -0,0 +1,7 @@ +varying vec3 norm; + +void main() +{ + gl_Position = ftransform(); + norm = gl_NormalMatrix * gl_Normal; +} diff -r ae47239c8c0d -r 18879c956eb1 examples/cubemap/src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/cubemap/src/main.cc Sun Nov 17 03:22:40 2013 +0200 @@ -0,0 +1,192 @@ +#include +#include +#include +#include +#include + +#define CUBEMAP_FILENAME "data/cubemap3.jpg" + +static bool init(); +static void cleanup(); +static void display(); +static void skybox(const TextureCube *cubemap = 0); +static void reshape(int x, int y); +static void keyboard(unsigned char key, int x, int y); +static void mouse(int bn, int st, int x, int y); +static void motion(int x, int y); + +static float cam_theta, cam_phi; + +static TextureCube *cubemap; +static ShaderProg *sdrsky; + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitWindowSize(800, 600); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + glutCreateWindow("cubemap"); + + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); + glutMouseFunc(mouse); + glutMotionFunc(motion); + + if(!init()) { + return 1; + } + atexit(cleanup); + + glutMainLoop(); + return 0; +} + +static bool init() +{ + glewInit(); + + glEnable(GL_DEPTH_TEST); + //glEnable(GL_CULL_FACE); + + cubemap = new TextureCube; + if(!cubemap->load(CUBEMAP_FILENAME)) { + fatal_log("Failed to load cubemap: %s\n", CUBEMAP_FILENAME); + return false; + } + + if(!(sdrsky = get_sdrprog("sdr/sky.v.glsl", "sdr/sky.p.glsl"))) { + fatal_log("failed to load skybox shader\n"); + return false; + } + + return true; +} + +static void cleanup() +{ + delete cubemap; +} + +static void display() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + Matrix4x4 view_matrix; + view_matrix.rotate(Vector3(1, 0, 0), M_PI * cam_phi / 180.0); + view_matrix.rotate(Vector3(0, 1, 0), M_PI * cam_theta / 180.0); + set_view_matrix(view_matrix); + + setup_gl_matrices(); + + skybox(); + + /*glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glNormal3f(0, 1, 0); + glVertex3f(-0.8, -1, 0.8); + glVertex3f(0.8, -1, 0.8); + glVertex3f(0.8, -1, -0.8); + glVertex3f(-0.8, -1, -0.8); + glEnd();*/ + + glutSwapBuffers(); + CHECKGLERR; +} + +static void skybox(const TextureCube *cubemap) +{ + glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + + if(cubemap) cubemap->bind(); + sdrsky->bind(); + + glBegin(GL_QUADS); + // +X + glColor3f(1, 0, 0); + glVertex3f(1, -1, 1); + glVertex3f(1, -1, -1); + glVertex3f(1, 1, -1); + glVertex3f(1, 1, 1); + // -Z + glColor3f(0, 1, 0); + glVertex3f(1, -1, -1); + glVertex3f(-1, -1, -1); + glVertex3f(-1, 1, -1); + glVertex3f(1, 1, -1); + // -X + glColor3f(0, 0, 1); + glVertex3f(-1, -1, -1); + glVertex3f(-1, -1, 1); + glVertex3f(-1, 1, 1); + glVertex3f(-1, 1, -1); + // +Z + glColor3f(1, 1, 0); + glVertex3f(-1, -1, 1); + glVertex3f(1, -1, 1); + glVertex3f(1, 1, 1); + glVertex3f(-1, 1, 1); + // +Y + glColor3f(0, 1, 1); + glVertex3f(-1, 1, 1); + glVertex3f(1, 1, 1); + glVertex3f(1, 1, -1); + glVertex3f(-1, 1, -1); + // -Y + glColor3f(1, 0, 1); + glVertex3f(-1, -1, -1); + glVertex3f(1, -1, -1); + glVertex3f(1, -1, 1); + glVertex3f(-1, -1, 1); + glEnd(); + + glUseProgram(0); + glPopAttrib(); +} + +static void reshape(int x, int y) +{ + glViewport(0, 0, x, y); + + Matrix4x4 proj; + proj.set_perspective(M_PI / 4.0, (float)x / (float)y, 0.5, 500.0); + set_projection_matrix(proj); +} + +static void keyboard(unsigned char key, int x, int y) +{ + switch(key) { + case 27: + exit(0); + } +} + +static bool bnstate[16]; +static int prev_x, prev_y; + +static void mouse(int bn, int st, int x, int y) +{ + bnstate[bn - GLUT_LEFT_BUTTON] = st == GLUT_DOWN; + prev_x = x; + prev_y = y; +} + +static void motion(int x, int y) +{ + int dx = x - prev_x; + int dy = y - prev_y; + prev_x = x; + prev_y = y; + + if(!dx && !dy) return; + + if(bnstate[0]) { + cam_theta += dx * 0.5; + cam_phi += dy * 0.5; + cam_phi = std::max(-90.0f, std::min(90.0f, cam_phi)); + glutPostRedisplay(); + } +} diff -r ae47239c8c0d -r 18879c956eb1 examples/examples-debug.vsprop --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/examples-debug.vsprop Sun Nov 17 03:22:40 2013 +0200 @@ -0,0 +1,7 @@ + + + diff -r ae47239c8c0d -r 18879c956eb1 examples/examples.vsprop --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/examples.vsprop Sun Nov 17 03:22:40 2013 +0200 @@ -0,0 +1,7 @@ + + + diff -r ae47239c8c0d -r 18879c956eb1 goat3dgfx.sln --- a/goat3dgfx.sln Sat Nov 16 21:09:42 2013 +0200 +++ b/goat3dgfx.sln Sun Nov 17 03:22:40 2013 +0200 @@ -3,6 +3,11 @@ # Visual Studio 2008 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "goat3dgfx", "goat3dgfx.vcproj", "{251F8AFF-5A37-4F10-A519-C55C40E127AF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cubemap", "examples\cubemap\cubemap.vcproj", "{21606BDB-5E01-45F3-9431-D5F4AF5F2CC0}" + ProjectSection(ProjectDependencies) = postProject + {251F8AFF-5A37-4F10-A519-C55C40E127AF} = {251F8AFF-5A37-4F10-A519-C55C40E127AF} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -13,6 +18,10 @@ {251F8AFF-5A37-4F10-A519-C55C40E127AF}.Debug|Win32.Build.0 = Debug|Win32 {251F8AFF-5A37-4F10-A519-C55C40E127AF}.Release|Win32.ActiveCfg = Release|Win32 {251F8AFF-5A37-4F10-A519-C55C40E127AF}.Release|Win32.Build.0 = Release|Win32 + {21606BDB-5E01-45F3-9431-D5F4AF5F2CC0}.Debug|Win32.ActiveCfg = Debug|Win32 + {21606BDB-5E01-45F3-9431-D5F4AF5F2CC0}.Debug|Win32.Build.0 = Debug|Win32 + {21606BDB-5E01-45F3-9431-D5F4AF5F2CC0}.Release|Win32.ActiveCfg = Release|Win32 + {21606BDB-5E01-45F3-9431-D5F4AF5F2CC0}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff -r ae47239c8c0d -r 18879c956eb1 goat3dgfx.vcproj --- a/goat3dgfx.vcproj Sat Nov 16 21:09:42 2013 +0200 +++ b/goat3dgfx.vcproj Sun Nov 17 03:22:40 2013 +0200 @@ -21,7 +21,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="4" - CharacterSet="1" + CharacterSet="2" > second; } - const char *fname, *slash; - if((slash = strrchr(name, '/'))) { - fname = slash + 1; - } else { - fname = name; - } - - std::string path = datafile_path(fname); + std::string path = datafile_path(name); if(path.empty()) { fprintf(stderr, "can't find data file: %s\n", name); return 0; diff -r ae47239c8c0d -r 18879c956eb1 src/logger.cc --- a/src/logger.cc Sat Nov 16 21:09:42 2013 +0200 +++ b/src/logger.cc Sun Nov 17 03:22:40 2013 +0200 @@ -4,9 +4,11 @@ #if defined(unix) || defined(__unix__) || defined(__APPLE__) #include +#elif defined(WIN32) +#include #endif -enum { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG }; +enum { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL, LOG_DEBUG }; static int typecolor(int type); @@ -25,9 +27,18 @@ { vfprintf(fp, fmt, ap); } - if(type == LOG_ERROR || type == LOG_DEBUG) { + if(type == LOG_ERROR || type == LOG_FATAL || type == LOG_DEBUG) { fflush(fp); } + +#ifdef WIN32 + if(type == LOG_FATAL) { + static char msgbuf[1024]; + vsnprintf(msgbuf, sizeof msgbuf - 1, fmt, ap); + msgbuf[sizeof msgbuf - 1] = 0; + MessageBox(0, msgbuf, "Fatal error", MB_OK | MB_ICONSTOP); + } +#endif } void info_log(const char *fmt, ...) @@ -57,6 +68,15 @@ va_end(ap); } +void fatal_log(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + logmsg(LOG_FATAL, fmt, ap); + va_end(ap); +} + void debug_log(const char *fmt, ...) { va_list ap; @@ -85,6 +105,8 @@ switch(type) { case LOG_ERROR: return ANSI_FGCOLOR(RED); + case LOG_FATAL: + return ANSI_FGCOLOR(RED); // TODO differentiate from LOG_ERROR case LOG_WARNING: return ANSI_FGCOLOR(YELLOW); case LOG_DEBUG: diff -r ae47239c8c0d -r 18879c956eb1 src/logger.h --- a/src/logger.h Sat Nov 16 21:09:42 2013 +0200 +++ b/src/logger.h Sun Nov 17 03:22:40 2013 +0200 @@ -4,6 +4,7 @@ void info_log(const char *fmt, ...); void warning_log(const char *fmt, ...); void error_log(const char *fmt, ...); +void fatal_log(const char *fmt, ...); void debug_log(const char *fmt, ...); #endif // LOGGER_H_