From b8483fc82178e500314479c6473ff3ae8f3cb3bc Mon Sep 17 00:00:00 2001 From: Sven Panne Date: Sat, 14 Feb 2009 20:38:53 +0000 Subject: [PATCH] Initial version of a fully OpenGL-3.0-compliant of the famous smooth.c from the Red Book. What has been done already: * Explicitly request a forward-compatible 3.0 context * Report GL errors, if any, at a few crucial places * Replaced gluOrtho2D with a home-grown matrix + glLoadMatrixf What remains to be done: * Use vertex shaders and fragment shaders * Use vertex buffer objects git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@774 7f0cb862-5218-0410-a997-914c9d46530a --- configure.ac | 2 +- progs/demos/Makefile.am | 2 +- progs/demos/smooth_opengl3/Makefile.am | 5 + progs/demos/smooth_opengl3/smooth_opengl3.c | 157 ++++++++++++++++++++ progs/demos/smooth_opengl3/smooth_opengl3.dsp | 100 +++++++++++++ .../demos/smooth_opengl3/smooth_opengl3Static.dsp | 102 +++++++++++++ 6 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 progs/demos/smooth_opengl3/Makefile.am create mode 100755 progs/demos/smooth_opengl3/smooth_opengl3.c create mode 100644 progs/demos/smooth_opengl3/smooth_opengl3.dsp create mode 100755 progs/demos/smooth_opengl3/smooth_opengl3Static.dsp diff --git a/configure.ac b/configure.ac index 2b8d043..fc90f54 100644 --- a/configure.ac +++ b/configure.ac @@ -95,5 +95,5 @@ if test "x$enable_debug" = xyes; then fi # Generate output. -AC_CONFIG_FILES([Makefile doc/Makefile include/GL/Makefile include/Makefile progs/Makefile progs/demos/CallbackMaker/Makefile progs/demos/Fractals/Makefile progs/demos/Fractals_random/Makefile progs/demos/Lorenz/Makefile progs/demos/Makefile progs/demos/One/Makefile progs/demos/shapes/Makefile src/Makefile]) +AC_CONFIG_FILES([Makefile doc/Makefile include/GL/Makefile include/Makefile progs/Makefile progs/demos/CallbackMaker/Makefile progs/demos/Fractals/Makefile progs/demos/Fractals_random/Makefile progs/demos/Lorenz/Makefile progs/demos/Makefile progs/demos/One/Makefile progs/demos/shapes/Makefile progs/demos/smooth_opengl3/Makefile src/Makefile]) AC_OUTPUT diff --git a/progs/demos/Makefile.am b/progs/demos/Makefile.am index 0cb3f88..661dc33 100644 --- a/progs/demos/Makefile.am +++ b/progs/demos/Makefile.am @@ -1,2 +1,2 @@ EXTRA_DIST = demos.dsw -SUBDIRS = CallbackMaker Fractals Fractals_random Lorenz One shapes +SUBDIRS = CallbackMaker Fractals Fractals_random Lorenz One shapes smooth_opengl3 diff --git a/progs/demos/smooth_opengl3/Makefile.am b/progs/demos/smooth_opengl3/Makefile.am new file mode 100644 index 0000000..493b742 --- /dev/null +++ b/progs/demos/smooth_opengl3/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = smooth_opengl3.c smooth_opengl3.dsp +noinst_PROGRAMS = smooth_opengl3 +smooth_opengl3_SOURCES = smooth_opengl3.c +smooth_opengl3_LDFLAGS = -export-dynamic ../../../src/lib@LIBRARY@.la +smooth_opengl3_CFLAGS = -I$(top_srcdir)/include $(X_CFLAGS) diff --git a/progs/demos/smooth_opengl3/smooth_opengl3.c b/progs/demos/smooth_opengl3/smooth_opengl3.c new file mode 100755 index 0000000..9a7915f --- /dev/null +++ b/progs/demos/smooth_opengl3/smooth_opengl3.c @@ -0,0 +1,157 @@ +/* + * smooth_opengl3.c, based on smooth.c, which is (c) by SGI, see below. + * This program demonstrates smooth shading in a way which is fully + * OpenGL-3.0-compliant. + * A smooth shaded polygon is drawn in a 2-D projection. + */ + +/* + * Original copyright notice from smooth.c: + * + * License Applicability. Except to the extent portions of this file are + * made subject to an alternative license as permitted in the SGI Free + * Software License B, Version 1.1 (the "License"), the contents of this + * file are subject only to the provisions of the License. You may not use + * this file except in compliance with the License. You may obtain a copy + * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 + * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: + * + * http://oss.sgi.com/projects/FreeB + * + * Note that, as provided in the License, the Software is distributed on an + * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS + * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND + * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A + * PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * + * Original Code. The Original Code is: OpenGL Sample Implementation, + * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + * Copyright in any portions created by third parties is as indicated + * elsewhere herein. All Rights Reserved. + * + * Additional Notice Provisions: The application programming interfaces + * established by SGI in conjunction with the Original Code are The + * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released + * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version + * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X + * Window System(R) (Version 1.3), released October 19, 1998. This software + * was created using the OpenGL(R) version 1.2.1 Sample Implementation + * published by SGI, but has not been independently verified as being + * compliant with the OpenGL(R) version 1.2.1 Specification. + * + */ + +#include +#include +#include + +void reportErrors(const char *message) +{ + GLenum error; + while (( error = glGetError() ) != GL_NO_ERROR) { + fprintf (stderr, "GL error 0x%X %s\n", error, message); + } +} + +void init(void) +{ + reportErrors ("at start of init"); + glClearColor (0.0, 0.0, 0.0, 0.0); + glShadeModel (GL_SMOOTH); + reportErrors ("at end of init"); +} + +void triangle(void) +{ + reportErrors ("at start of triangle"); + glBegin (GL_TRIANGLES); + glColor3f (1.0, 0.0, 0.0); + glVertex2f (5.0, 5.0); + glColor3f (0.0, 1.0, 0.0); + glVertex2f (25.0, 5.0); + glColor3f (0.0, 0.0, 1.0); + glVertex2f (5.0, 25.0); + glEnd(); + reportErrors ("at end of triangle"); +} + +void display(void) +{ + reportErrors ("at start of display"); + glClear (GL_COLOR_BUFFER_BIT); + triangle (); + glFlush (); + reportErrors ("at end of display"); +} + +void loadOrthof(GLfloat *m, GLfloat l, GLfloat r, GLfloat b, GLfloat t, + GLfloat n, GLfloat f) +{ + m[ 0] = 2.0f / (r - l); + m[ 1] = 0.0f; + m[ 2] = 0.0f; + m[ 3] = 0.0f; + + m[ 4] = 0.0f; + m[ 5] = 2.0f / (t - b); + m[ 6] = 0.0f; + m[ 7] = 0.0f; + + m[ 8] = 0.0f; + m[ 9] = 0.0f; + m[10] = -2.0f / (f - n); + m[11] = 0.0f; + + m[12] = -(r + l) / (r - l); + m[13] = -(t + b) / (t - b); + m[14] = -(f + n) / (f - n); + m[15] = 1.0f; +} + +void loadOrtho2Df(GLfloat *m, GLfloat l, GLfloat r, GLfloat b, GLfloat t) +{ + loadOrthof (m, l, r, b, t, -1.0f, 1.0f); +} + +void reshape (int w, int h) +{ + GLfloat m[16]; + reportErrors ("at start of reshape"); + glViewport (0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode (GL_PROJECTION); + if (w <= h) { + loadOrtho2Df (m, 0.0, 30.0, 0.0, 30.0 * (GLfloat) h/(GLfloat) w); + } else { + loadOrtho2Df (m, 0.0, 30.0 * (GLfloat) w/(GLfloat) h, 0.0, 30.0); + } + glLoadMatrixf (m); + glMatrixMode (GL_MODELVIEW); + reportErrors ("at end of reshape"); +} + +void keyboard(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + break; + } +} + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); + glutInitContextVersion(3, 0); + // glutInitContextFlags(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG); + glutInitWindowSize (500, 500); + glutInitWindowPosition (100, 100); + glutCreateWindow (argv[0]); + init (); + glutDisplayFunc(display); + glutReshapeFunc(reshape); + glutKeyboardFunc (keyboard); + glutMainLoop(); + return 0; +} diff --git a/progs/demos/smooth_opengl3/smooth_opengl3.dsp b/progs/demos/smooth_opengl3/smooth_opengl3.dsp new file mode 100644 index 0000000..7e5f443 --- /dev/null +++ b/progs/demos/smooth_opengl3/smooth_opengl3.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="smooth_opengl3" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=smooth_opengl3 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "smooth_opengl3.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "smooth_opengl3.mak" CFG="smooth_opengl3 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "smooth_opengl3 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "smooth_opengl3 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "smooth_opengl3 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../../../Release" + +!ELSEIF "$(CFG)" == "smooth_opengl3 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../../../Debug" + +!ENDIF + +# Begin Target + +# Name "smooth_opengl3 - Win32 Release" +# Name "smooth_opengl3 - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\smooth_opengl3.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/progs/demos/smooth_opengl3/smooth_opengl3Static.dsp b/progs/demos/smooth_opengl3/smooth_opengl3Static.dsp new file mode 100755 index 0000000..c1d8388 --- /dev/null +++ b/progs/demos/smooth_opengl3/smooth_opengl3Static.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="smooth_opengl3Static" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=smooth_opengl3Static - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "smooth_opengl3Static.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "smooth_opengl3Static.mak" CFG="smooth_opengl3Static - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "smooth_opengl3Static - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "smooth_opengl3Static - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "smooth_opengl3Static - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "smooth_opengl3Static___Win32_Release" +# PROP BASE Intermediate_Dir "smooth_opengl3Static___Win32_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseStatic" +# PROP Intermediate_Dir "ReleaseStatic" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "FREEGLUT_STATIC" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../../../ReleaseStatic" + +!ELSEIF "$(CFG)" == "smooth_opengl3Static - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "smooth_opengl3Static___Win32_Debug" +# PROP BASE Intermediate_Dir "smooth_opengl3Static___Win32_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "DebugStatic" +# PROP Intermediate_Dir "DebugStatic" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "FREEGLUT_STATIC" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../../../DebugStatic" + +!ENDIF + +# Begin Target + +# Name "smooth_opengl3Static - Win32 Release" +# Name "smooth_opengl3Static - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\smooth_opengl3.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project -- 1.7.10.4