From 8140feac10efed41829dc0cd4d105faf85b0d52d Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 21 Dec 2015 12:34:51 +0300 Subject: [PATCH] add OpenGL example --- README.md | 6 +- dlangui-msvc.sln | 19 +- dub.json | 1 + examples/example1/dub.json | 4 - examples/example1/src/example1.d | 66 +-- examples/opengl/dub.json | 21 + examples/opengl/opengl-msvc.visualdproj | 414 +++++++++++++++++++ examples/opengl/src/openglexample.d | 379 +++++++++++++++++ examples/opengl/src/win_app.def | 2 + examples/opengl/views/res/mdpi/tx_fabric.jpg | Bin 0 -> 9061 bytes examples/opengl/views/resources.list | 1 + 11 files changed, 874 insertions(+), 39 deletions(-) create mode 100644 examples/opengl/dub.json create mode 100644 examples/opengl/opengl-msvc.visualdproj create mode 100644 examples/opengl/src/openglexample.d create mode 100644 examples/opengl/src/win_app.def create mode 100644 examples/opengl/views/res/mdpi/tx_fabric.jpg create mode 100644 examples/opengl/views/resources.list diff --git a/README.md b/README.md index 792aa093..6c24b9ff 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ Open solution file with Mono-D dlangui-monod-linux.sln -Try running examples: helloworld, example1, tetris, dmledit +Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps. @@ -304,7 +304,7 @@ Open solution file with Mono-D dlangui-monod-windows.sln -Try running examples: helloworld, example1, tetris, dmledit +Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps. @@ -378,7 +378,7 @@ Open solution file with Visual-D dlangui-msvc.sln -Try running examples: helloworld, example1, tetris, dmledit +Try running examples: helloworld, example1, tetris, dmledit, spreadsheet, opengl Configurations Debug, Release, Unittest build SDL2+OpenGL versions of apps. diff --git a/dlangui-msvc.sln b/dlangui-msvc.sln index 17ff89ca..bd813809 100644 --- a/dlangui-msvc.sln +++ b/dlangui-msvc.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "dlangui", "dlangui-msvc.visualdproj", "{52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}" EndProject @@ -40,6 +40,11 @@ Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "spreadsheet", "examples\spr {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5} = {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5} EndProjectSection EndProject +Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "opengl", "examples\opengl\opengl-msvc.visualdproj", "{29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}" + ProjectSection(ProjectDependencies) = postProject + {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5} = {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -101,14 +106,20 @@ Global {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Debug|x64.ActiveCfg = Debug|x64 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|Win32.ActiveCfg = Release|Win32 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|Win32.Build.0 = Release|Win32 - {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|x64.ActiveCfg = Release|Win32 + {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|x64.ActiveCfg = Release|x64 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|Win32.ActiveCfg = Debug|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|Win32.Build.0 = Debug|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|x64.ActiveCfg = Debug|x64 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|x64.Build.0 = Debug|x64 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|Win32.ActiveCfg = Release|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|Win32.Build.0 = Release|Win32 - {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|x64.ActiveCfg = Release|Win32 + {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|x64.ActiveCfg = Release|x64 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Debug|Win32.ActiveCfg = Debug|Win32 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Debug|Win32.Build.0 = Debug|Win32 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Debug|x64.ActiveCfg = Debug|x64 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Release|Win32.ActiveCfg = Release|Win32 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Release|Win32.Build.0 = Release|Win32 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Release|x64.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/dub.json b/dub.json index b240fff3..6ccab7e7 100644 --- a/dub.json +++ b/dub.json @@ -35,6 +35,7 @@ "./examples/dmledit/", "./examples/d3d/", "./examples/tetris/", + "./examples/opengl/", "./examples/spreadsheet/" ], diff --git a/examples/example1/dub.json b/examples/example1/dub.json index 86fcfa1c..d69f0dfe 100644 --- a/examples/example1/dub.json +++ b/examples/example1/dub.json @@ -17,9 +17,5 @@ "dependencies": { "dlangui": {"path": "../../"} - }, - - "subConfigurations": { - "dlangui": "minimal" } } diff --git a/examples/example1/src/example1.d b/examples/example1/src/example1.d index 1635fe15..90360bc9 100644 --- a/examples/example1/src/example1.d +++ b/examples/example1/src/example1.d @@ -239,7 +239,7 @@ extern (C) int UIAppMain(string[] args) { //} // create window - Window window = Platform.instance.createWindow("My Window", null, WindowFlag.Resizable, 800, 700); + Window window = Platform.instance.createWindow("DlangUI Example 1", null, WindowFlag.Resizable, 800, 700); static if (true) { VerticalLayout contentLayout = new VerticalLayout(); @@ -931,44 +931,54 @@ static if (ENABLE_OPENGL) { layoutWidth = FILL_PARENT; layoutHeight = FILL_PARENT; alignment = Align.Center; - backgroundDrawable = DrawableRef(new OpenGLDrawable(&doDraw)); // add some UI on top of OpenGL drawable Widget w = parseML(q{ VerticalLayout { - margins: 40 - padding: 40 alignment: center + layoutWidth: fill; layoutHeight: fill + // background for window - tiled texture + backgroundImageId: "tx_fabric.tiled" + VerticalLayout { + // child widget - will draw using OpenGL here + id: glView + margins: 20 + padding: 20 + layoutWidth: fill; layoutHeight: fill - //backgroundColor: "#C0E0E070" // semitransparent yellow background - // red bold text with size = 150% of base style size and font face Arial - TextWidget { text: "Hello World example for DlangUI"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" } - // arrange controls as form - table with two columns - TableLayout { - colCount: 2 - TextWidget { text: "param 1" } - EditLine { id: edit1; text: "some text" } - TextWidget { text: "param 2" } - EditLine { id: edit2; text: "some text for param2" } - TextWidget { text: "some radio buttons" } - // arrange some radio buttons vertically - VerticalLayout { - RadioButton { id: rb1; text: "Item 1" } - RadioButton { id: rb2; text: "Item 2" } - RadioButton { id: rb3; text: "Item 3" } + //backgroundColor: "#C0E0E070" // semitransparent yellow background + // red bold text with size = 150% of base style size and font face Arial + TextWidget { text: "Some controls to draw on top of OpenGL scene"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" } + // arrange controls as form - table with two columns + TableLayout { + colCount: 2 + TextWidget { text: "param 1" } + EditLine { id: edit1; text: "some text" } + TextWidget { text: "param 2" } + EditLine { id: edit2; text: "some text for param2" } + TextWidget { text: "some radio buttons" } + // arrange some radio buttons vertically + VerticalLayout { + RadioButton { id: rb1; text: "Item 1" } + RadioButton { id: rb2; text: "Item 2" } + RadioButton { id: rb3; text: "Item 3" } + } + TextWidget { text: "and checkboxes" } + // arrange some checkboxes horizontally + HorizontalLayout { + CheckBox { id: cb1; text: "checkbox 1" } + CheckBox { id: cb2; text: "checkbox 2" } + } } - TextWidget { text: "and checkboxes" } - // arrange some checkboxes horizontally + VSpacer { layoutWeight: 10 } HorizontalLayout { - CheckBox { id: cb1; text: "checkbox 1" } - CheckBox { id: cb2; text: "checkbox 2" } + Button { id: btnOk; text: "Ok" } + Button { id: btnCancel; text: "Cancel" } } } - HorizontalLayout { - Button { id: btnOk; text: "Ok" } - Button { id: btnCancel; text: "Cancel" } - } } }); + // setting OpenGL background drawable for one of child widgets + w.childById("glView").backgroundDrawable = DrawableRef(new OpenGLDrawable(&doDraw)); addChild(w); } diff --git a/examples/opengl/dub.json b/examples/opengl/dub.json new file mode 100644 index 00000000..19739cb7 --- /dev/null +++ b/examples/opengl/dub.json @@ -0,0 +1,21 @@ +{ + "name": "opengl", + "description": "dlangui library OpenGL example", + "homepage": "https://github.com/buggins/dlangui", + "license": "Boost", + "authors": ["Vadim Lopatin"], + + "targetPath": "bin", + "targetType": "executable", + "targetName": "openglexample", + + "stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"], + + "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], + + "versions": ["EmbedStandardResources"], + + "dependencies": { + "dlangui": {"path": "../../"} + } +} diff --git a/examples/opengl/opengl-msvc.visualdproj b/examples/opengl/opengl-msvc.visualdproj new file mode 100644 index 00000000..a37128b1 --- /dev/null +++ b/examples/opengl/opengl-msvc.visualdproj @@ -0,0 +1,414 @@ + + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF} + + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2.043 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + $(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/deps/DerelictGL3/source $(SolutionDir)/deps/DerelictUtil/source $(SolutionDir)/deps/DerelictFT/source $(SolutionDir)/deps/DerelictSDL2/source + views views/res views/res/i18n views/res/mdpi views/res/hdpi + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + USE_OPENGL EmbedStandardResources + 0 + 0 + 0 + + + + 0 + + 1 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + ole32.lib kernel32.lib user32.lib comctl32.lib comdlg32.lib + + + + $(OutDir)\$(ProjectName).exe + 1 + 2 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + + + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 3 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2.043 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + $(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/deps/DerelictGL3/source $(SolutionDir)/deps/DerelictUtil/source $(SolutionDir)/deps/DerelictFT/source $(SolutionDir)/deps/DerelictSDL2/source + views views/res views/res/i18n views/res/mdpi views/res/hdpi + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + USE_OPENGL EmbedStandardResources + 0 + 0 + 0 + + + + 0 + + 1 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + ole32.lib kernel32.lib user32.lib comctl32.lib comdlg32.lib + + + + $(OutDir)\$(ProjectName).exe + 1 + 2 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + + + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2.043 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + + + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + + 0 + 0 + 0 + + + + 0 + + 0 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + ole32.lib kernel32.lib user32.lib comctl32.lib comdlg32.lib + + + + $(OutDir)\$(ProjectName).exe + 1 + 1 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + + + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2.043 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + + + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + + 0 + 0 + 0 + + + + 0 + + 0 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + ole32.lib kernel32.lib user32.lib comctl32.lib comdlg32.lib + + + + $(OutDir)\$(ProjectName).exe + 1 + 1 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + + + + + diff --git a/examples/opengl/src/openglexample.d b/examples/opengl/src/openglexample.d new file mode 100644 index 00000000..9c7ffe20 --- /dev/null +++ b/examples/opengl/src/openglexample.d @@ -0,0 +1,379 @@ +module openglexample; + +import dlangui; + +mixin APP_ENTRY_POINT; + +/// entry point for dlangui based application +extern (C) int UIAppMain(string[] args) { + // embed resources listed in views/resources.list into executable + embeddedResourceList.addResources(embedResourcesFromList!("resources.list")()); + + // create window + Window window = Platform.instance.createWindow("DlangUI OpenGL Example", null, WindowFlag.Resizable, 800, 700); + + VerticalLayout contentLayout = new VerticalLayout(); + + static if (ENABLE_OPENGL) { + window.mainWidget = new MyOpenglWidget(); + } else { + window.mainWidget = new TextWidget(null, "DlangUI is built with OpenGL support disabled"d); + } + + window.windowIcon = drawableCache.getImage("dlangui-logo1"); + + window.show(); + // run message loop + return Platform.instance.enterMessageLoop(); +} + +static if (ENABLE_OPENGL) { + + import derelict.opengl3.gl3; + import derelict.opengl3.gl; + + class MyOpenglWidget : VerticalLayout { + this() { + super("OpenGLView"); + layoutWidth = FILL_PARENT; + layoutHeight = FILL_PARENT; + alignment = Align.Center; + // add some UI on top of OpenGL drawable + Widget w = parseML(q{ + VerticalLayout { + alignment: center + layoutWidth: fill; layoutHeight: fill + // background for window - tiled texture + backgroundImageId: "tx_fabric.tiled" + VerticalLayout { + // child widget - will draw using OpenGL here + id: glView + margins: 20 + padding: 20 + layoutWidth: fill; layoutHeight: fill + + //backgroundColor: "#C0E0E070" // semitransparent yellow background + // red bold text with size = 150% of base style size and font face Arial + TextWidget { text: "Some controls to draw on top of OpenGL scene"; textColor: "red"; fontSize: 150%; fontWeight: 800; fontFace: "Arial" } + // arrange controls as form - table with two columns + TableLayout { + colCount: 2 + TextWidget { text: "param 1" } + EditLine { id: edit1; text: "some text" } + TextWidget { text: "param 2" } + EditLine { id: edit2; text: "some text for param2" } + TextWidget { text: "some radio buttons" } + // arrange some radio buttons vertically + VerticalLayout { + RadioButton { id: rb1; text: "Item 1" } + RadioButton { id: rb2; text: "Item 2" } + RadioButton { id: rb3; text: "Item 3" } + } + TextWidget { text: "and checkboxes" } + // arrange some checkboxes horizontally + HorizontalLayout { + CheckBox { id: cb1; text: "checkbox 1" } + CheckBox { id: cb2; text: "checkbox 2" } + } + } + VSpacer { layoutWeight: 10 } + HorizontalLayout { + Button { id: btnOk; text: "Ok" } + Button { id: btnCancel; text: "Cancel" } + } + } + } + }); + // assign OpenGL drawable to child widget background + w.childById("glView").backgroundDrawable = DrawableRef(new OpenGLDrawable(&doDraw)); + addChild(w); + } + + bool _oldApi; + + /// this is OpenGLDrawableDelegate implementation + private void doDraw(Rect windowRect, Rect rc) { + Log.v("GlGears: MyOpenglWidget.doDraw() draw gears"); + if (!openglEnabled) { + Log.v("GlGears: OpenGL is disabled"); + return; + } + _oldApi = !!glLightfv; + if (_oldApi) { + drawUsingOldAPI(rc); + } else { + drawUsingNewAPI(rc); + } + } + + /// Legacy API example (glBegin/glEnd) + void drawUsingOldAPI(Rect rc) { + static bool _initCalled; + if (!_initCalled) { + Log.d("GlGears: calling init()"); + _initCalled = true; + glxgears_init(); + } + Log.v("GlGears: calling reshape()"); + glxgears_reshape(rc); + Log.v("GlGears: calling draw()"); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + glxgears_draw(); + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_DEPTH_TEST); + } + + /// New API example (OpenGL3+, shaders) + void drawUsingNewAPI(Rect rc) { + // TODO: put some sample code here + } + /// returns true is widget is being animated - need to call animate() and redraw + @property override bool animating() { return true; } + /// animates window; interval is time left from previous draw, in hnsecs (1/10000000 of second) + override void animate(long interval) { + if (_oldApi) { + // animate legacy API example + // rotate gears + angle += interval * 0.000002f; + } else { + // TODO: animate new API example + } + invalidate(); + } + } + + + // Sample project for old API: GlxGears + + import std.math; + static __gshared GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; + static __gshared GLint gear1, gear2, gear3; + static __gshared GLfloat angle = 0.0; + alias M_PI = std.math.PI; + + /* + * + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ + static void + gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth) + { + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + glShadeModel(GL_FLAT); + + glNormal3f(0.0, 0.0, 1.0); + + /* draw front face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + if (i < teeth) { + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + } + glEnd(); + + /* draw front sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + } + glEnd(); + + glNormal3f(0.0, 0.0, -1.0); + + /* draw back face */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + if (i < teeth) { + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + } + } + glEnd(); + + /* draw back sides of teeth */ + glBegin(GL_QUADS); + da = 2.0 * M_PI / teeth / 4.0; + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + } + glEnd(); + + /* draw outward faces of teeth */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + + glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); + glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); + u = r2 * cos(angle + da) - r1 * cos(angle); + v = r2 * sin(angle + da) - r1 * sin(angle); + len = sqrt(u * u + v * v); + u /= len; + v /= len; + glNormal3f(v, -u, 0.0); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); + glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + width * 0.5); + glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), + -width * 0.5); + u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); + v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); + glNormal3f(v, -u, 0.0); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + width * 0.5); + glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), + -width * 0.5); + glNormal3f(cos(angle), sin(angle), 0.0); + } + + glVertex3f(r1 * cos(0.0), r1 * sin(0.0), width * 0.5); + glVertex3f(r1 * cos(0.0), r1 * sin(0.0), -width * 0.5); + + glEnd(); + + glShadeModel(GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) { + angle = i * 2.0 * M_PI / teeth; + glNormal3f(-cos(angle), -sin(angle), 0.0); + glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); + glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); + } + glEnd(); + } + + + static void glxgears_draw() + { + glClear(/*GL_COLOR_BUFFER_BIT | */GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0, 0.0, 0.0); + glRotatef(view_roty, 0.0, 1.0, 0.0); + glRotatef(view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix(); + glTranslatef(-3.0, -2.0, 0.0); + glRotatef(angle, 0.0, 0.0, 1.0); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1, -2.0, 0.0); + glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1, 4.2, 0.0); + glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); + } + + + /* new window size or exposure */ + static void + glxgears_reshape(Rect rc) + { + GLfloat h = cast(GLfloat) rc.height / cast(GLfloat) rc.width; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); + } + + + static void glxgears_init() + { + static GLfloat[4] pos = [ 5.0, 5.0, 10.0, 0.0 ]; + static GLfloat[4] red = [ 0.8, 0.1, 0.0, 1.0 ]; + static GLfloat[4] green = [ 0.0, 0.8, 0.2, 1.0 ]; + static GLfloat[4] blue = [ 0.2, 0.2, 1.0, 1.0 ]; + + Log.d("GlGears: init - calling glLightfv"); + glLightfv(GL_LIGHT0, GL_POSITION, pos.ptr); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); + + Log.d("GlGears: init - calling genlists"); + /* make the gears */ + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red.ptr); + gear(1.0, 4.0, 1.0, 20, 0.7); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green.ptr); + gear(0.5, 2.0, 2.0, 10, 0.7); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue.ptr); + gear(1.3, 2.0, 0.5, 10, 0.7); + glEndList(); + + glEnable(GL_NORMALIZE); + } + + +} diff --git a/examples/opengl/src/win_app.def b/examples/opengl/src/win_app.def new file mode 100644 index 00000000..40b796c7 --- /dev/null +++ b/examples/opengl/src/win_app.def @@ -0,0 +1,2 @@ +EXETYPE NT +SUBSYSTEM WINDOWS diff --git a/examples/opengl/views/res/mdpi/tx_fabric.jpg b/examples/opengl/views/res/mdpi/tx_fabric.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6c33894a25239d022c5ccb70598f71cd9d0fff11 GIT binary patch literal 9061 zcmeHqcT`i&*X{{~9$E+(B-DgnUYc|%B9H*mL7FI4Kw1J)L=+GZFhmlhilGZCAiW4G z(nFP^f`GIDB1I{}3krPrYu{b>uY2!b_pWvKnpyLleP;H0o|%1S=A2BN%ro{Fg!^~_ z00tukFaiKT2b=}b0iaW4d|LVbg{@Ap1c>$@ewtIvMf2a-=RWu!e#cXP*=a?e)<5I_ z-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HY-r4d1P-U9`GT&>Pb(<1y#hta-aKLJKms z*CRTc^~JPWDxDxYE*3_7H;jGnRg|3p=X8>l5=t*t9b^0yoUl zBfFR1KeDt?z~jPs8DI^}9yM{(R}E|FfcP94K#l)3P@FtC1{`s(>^?d3B=yJtU3^K~Fn>MfvDptxGgz0z0KYCAIW+L%+fbx5Ln za;QaHAvwG-nMItu-`|`(Asvx0e~-T-K>tM=K6t~Fe5fwBVhEiVRcvOZ0J)%p5d&~i zU?ilG{p{;+>4|1e8@v>0Le>i=s%Y(%+L;5(UUz3RlU)dV3Cu#I=thG|Mz`MH3ISnW zUo5C?CVy8W`FueC`X_8g>%)G6gmX`oM@ai2vqXN)V0Quc_Z%XV10*IFJu%m-#vdhR z|K`1rCI9PIA5;LJAD;1m55D+0S%NJ-(qv~3iF;q?+qJ0eeBfp*EG`=LJnZfEhOBsq z-x-pD?Va`cOmV>{Fbj-}Q?H+^)d}DeA>!RbQ5kt%qZ+dRBFKPsrth=@Ut)_(OK zrk4DDn5AxVhhueu#kbE1f42d=dT@7($`+4W@YKx)brLWY<0WOrr1L}Wk)@s!5B&?j uH6`Rs--5%%1S|T@dx+2j0}Y9Sy9!Smp~jw3gUjSQ?i&U$W=+A9$^Qb_L(~fZ literal 0 HcmV?d00001 diff --git a/examples/opengl/views/resources.list b/examples/opengl/views/resources.list new file mode 100644 index 00000000..0fc68b55 --- /dev/null +++ b/examples/opengl/views/resources.list @@ -0,0 +1 @@ +res/mdpi/tx_fabric.jpg