-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to use Awesomium for game gui and editor gui
- Loading branch information
unknown
authored and
unknown
committed
Sep 10, 2011
1 parent
edf6618
commit e71dbf1
Showing
16 changed files
with
563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
/** | ||
* This is a simple example of using Awesomium with OpenGL. | ||
* | ||
* It loads a page and displays it using OpenGL and GLUT. | ||
*/ | ||
|
||
// Various included headers | ||
#include <Awesomium/awesomium_capi.h> | ||
#if defined(__WIN32__) || defined(_WIN32) | ||
#include <windows.h> | ||
#include <gl/gl.h> | ||
#include "gl/freeglut.h" | ||
#define GL_BGRA GL_BGRA_EXT | ||
#elif defined(__APPLE__) | ||
#include <unistd.h> | ||
#include <OpenGL/OpenGL.h> | ||
#include <GLUT/GLUT.h> | ||
#endif | ||
|
||
// Various macro definitions | ||
#define WIDTH 1024 | ||
#define HEIGHT 768 | ||
#define URL "http://www.google.com" | ||
#define UPDATE_DELAY_MS 25 | ||
|
||
void cleanup(); | ||
void display(); | ||
void update(int val); | ||
void mouseMoved(int x, int y); | ||
void mousePressed(int button, int state, int x, int y); | ||
void keyPressed(unsigned char key, int x, int y); | ||
void specialKeyPressed(int key, int x, int y); | ||
void injectSpecialKey(int keyCode); | ||
|
||
static awe_webview* webView = 0; | ||
|
||
// Our main program | ||
int main(int argc, char *argv[]) | ||
{ | ||
glutInit(&argc, argv); | ||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | ||
glutInitWindowSize(WIDTH, HEIGHT); | ||
glutCreateWindow("AwesomiumGL Sample"); | ||
|
||
// Initialize OpenGL | ||
glViewport(0, 0, WIDTH, HEIGHT); | ||
glMatrixMode(GL_MODELVIEW); | ||
glLoadIdentity(); | ||
glMatrixMode(GL_PROJECTION); | ||
glLoadIdentity(); | ||
gluOrtho2D(0, WIDTH, 0, HEIGHT); | ||
|
||
// Create our WebCore singleton with the default options | ||
awe_webcore_initialize_default(); | ||
|
||
// Create a new WebView instance with a certain width and height, using the | ||
// WebCore we just created | ||
webView = awe_webcore_create_webview(WIDTH, HEIGHT, false); | ||
|
||
// Load a certain URL into our WebView instance | ||
awe_string* url_str = awe_string_create_from_ascii(URL, strlen(URL)); | ||
awe_webview_load_url(webView, url_str, awe_string_empty(), awe_string_empty(), awe_string_empty()); | ||
// destroy string | ||
awe_string_destroy(url_str); | ||
|
||
awe_webview_focus(webView); | ||
|
||
glutDisplayFunc(display); | ||
glutTimerFunc(UPDATE_DELAY_MS, update, 0); | ||
glutMouseFunc(mousePressed); | ||
glutMotionFunc(mouseMoved); | ||
glutPassiveMotionFunc(mouseMoved); | ||
glutKeyboardFunc(keyPressed); | ||
glutSpecialFunc(specialKeyPressed); | ||
|
||
atexit(cleanup); | ||
|
||
glutMainLoop(); | ||
|
||
return 0; | ||
} | ||
|
||
void cleanup() | ||
{ | ||
// Destroy our WebView instance | ||
awe_webview_destroy(webView); | ||
|
||
// Destroy our WebCore instance | ||
// NOTE: Since we don't have access to the main loop of | ||
// our application (a limitation of GLUT), we scheduled | ||
// this cleanup() method using atexit. The problem is | ||
// that Awesomium schedules some items for cleanup using | ||
// atexit as well and their order of execution is not | ||
// guaranteed which may cause a crash to occur. | ||
// | ||
// The Solution: Don't use GLUT or atexit :-) | ||
awe_webcore_shutdown(); | ||
} | ||
|
||
void display() | ||
{ | ||
|
||
|
||
glClear(GL_COLOR_BUFFER_BIT); | ||
|
||
// Flip image vertically | ||
glRasterPos2i(0, HEIGHT); | ||
glPixelZoom(1.0f,-1.0f); | ||
|
||
const awe_renderbuffer* renderBuffer = awe_webview_render(webView); | ||
|
||
if(renderBuffer != NULL) | ||
{ | ||
// Draw pixels directly to screen from our image buffer | ||
glDrawPixels(WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, awe_renderbuffer_get_buffer(renderBuffer)); | ||
} | ||
|
||
glutSwapBuffers(); | ||
} | ||
|
||
void update(int val) | ||
{ | ||
awe_webcore_update(); | ||
|
||
// Call our display func when the WebView needs rendering | ||
if(awe_webview_is_dirty(webView)) | ||
glutPostRedisplay(); | ||
|
||
glutTimerFunc(UPDATE_DELAY_MS, update, 0); | ||
} | ||
|
||
void mouseMoved(int x, int y) | ||
{ | ||
awe_webview_inject_mouse_move(webView, x, y); | ||
} | ||
|
||
void mousePressed(int button, int state, int x, int y) | ||
{ | ||
if(button == GLUT_LEFT_BUTTON) | ||
{ | ||
if(state == GLUT_DOWN) | ||
awe_webview_inject_mouse_down(webView, AWE_MB_LEFT); | ||
else | ||
awe_webview_inject_mouse_up(webView, AWE_MB_LEFT); | ||
} | ||
} | ||
|
||
|
||
void keyPressed(unsigned char key, int x, int y) | ||
{ | ||
if(key == 8 || key == 127) // Backspace or Delete key | ||
{ | ||
injectSpecialKey(VK_BACK); | ||
return; | ||
} | ||
else if(key == 9) // Tab key | ||
{ | ||
injectSpecialKey(VK_TAB); | ||
return; | ||
} | ||
else if(key == 13){ | ||
// enter key | ||
injectSpecialKey(13); | ||
return; | ||
} | ||
else if(key == 27) // Escape key | ||
{ | ||
exit(0); | ||
} | ||
|
||
// injection of normal character keys | ||
awe_webkeyboardevent e; | ||
e.type = AWE_WKT_CHAR; | ||
e.is_system_key = false; | ||
e.text[0] = key; | ||
e.text[1] = 0; | ||
e.text[2] = 0; | ||
e.text[3] = 0; | ||
e.unmodified_text[0] = 0; | ||
e.unmodified_text[1] = 0; | ||
e.unmodified_text[2] = 0; | ||
e.unmodified_text[3] = 0; | ||
e.virtual_key_code = 0; | ||
e.native_key_code = 0; | ||
awe_webview_inject_keyboard_event(webView, e); | ||
} | ||
|
||
void specialKeyPressed(int key, int x, int y) | ||
{ | ||
switch(key) | ||
{ | ||
case GLUT_KEY_LEFT: | ||
injectSpecialKey(VK_LEFT); | ||
break; | ||
case GLUT_KEY_UP: | ||
injectSpecialKey(VK_UP); | ||
break; | ||
case GLUT_KEY_RIGHT: | ||
injectSpecialKey(VK_RIGHT); | ||
break; | ||
case GLUT_KEY_DOWN: | ||
injectSpecialKey(VK_DOWN); | ||
break; | ||
case GLUT_KEY_PAGE_UP: | ||
injectSpecialKey(VK_PRIOR); | ||
break; | ||
case GLUT_KEY_PAGE_DOWN: | ||
injectSpecialKey(VK_NEXT); | ||
break; | ||
case GLUT_KEY_HOME: | ||
injectSpecialKey(VK_HOME); | ||
break; | ||
case GLUT_KEY_END: | ||
injectSpecialKey(VK_END); | ||
break; | ||
} | ||
} | ||
|
||
void injectSpecialKey(int keyCode) | ||
{ | ||
wchar16 key = keyCode; | ||
|
||
// Key Down | ||
awe_webkeyboardevent e; | ||
e.is_system_key = false; | ||
e.modifiers = 0; | ||
|
||
e.text[0] = key; | ||
e.text[1] = 0; | ||
e.text[2] = 0; | ||
e.text[3] = 0; | ||
e.unmodified_text[0] = key; | ||
e.unmodified_text[1] = 0; | ||
e.unmodified_text[2] = 0; | ||
e.unmodified_text[3] = 0; | ||
e.virtual_key_code = key; | ||
e.native_key_code = key; | ||
e.type = AWE_WKT_KEYDOWN; | ||
awe_webview_inject_keyboard_event(webView, e); | ||
|
||
// Key Up | ||
e.is_system_key = false; | ||
e.modifiers = 0; | ||
|
||
e.text[0] = key; | ||
e.text[1] = 0; | ||
e.text[2] = 0; | ||
e.text[3] = 0; | ||
e.unmodified_text[0] = key; | ||
e.unmodified_text[1] = 0; | ||
e.unmodified_text[2] = 0; | ||
e.unmodified_text[3] = 0; | ||
e.virtual_key_code = key; | ||
e.native_key_code = key; | ||
e.type = AWE_WKT_KEYUP; | ||
awe_webview_inject_keyboard_event(webView, e); | ||
awe_webcore_update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{544AEA15-603A-4643-AB3E-87D2A241EF97}</ProjectGuid> | ||
<RootNamespace>Awesomium</RootNamespace> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<OutDir>$(SolutionDir)$(Configuration)\</OutDir> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<AdditionalIncludeDirectories>E:\awesomium-1.6.2\include;..\PhysicsEngine;..\MathLib;..\GraphicsEngine;..\..\lib\freeglut\include;..\..\lib\glew-1.6.0\include;..\..\lib\rapidxml-1.13;..\Pugixml;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<PerUserRedirection>false</PerUserRedirection> | ||
<AdditionalLibraryDirectories>E:\awesomium-1.6.2\build\lib\debug;..\..\lib\DevIL-SDK-x86-1.7.8\lib;E:\Microsoft DirectX SDK\Lib\x86;..\..\lib\freeglut\lib;..\..\lib\glew-1.6.0\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>Awesomium_d.lib;opengl32.lib;glu32.lib;freeglut.lib;DevIL.lib;ILU.lib;ILUT.lib;dinput8.lib;dxguid.lib;glew32.lib;glew32mx.lib;glew32mxs.lib;glew32s.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<AdditionalIncludeDirectories>E:\awesomium-1.6.2\include;..\PhysicsEngine;..\MathLib;..\GraphicsEngine;..\..\lib\freeglut\include;..\..\lib\glew-1.6.0\include;..\..\lib\rapidxml-1.13;..\Pugixml;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<AdditionalLibraryDirectories>E:\awesomium-1.6.2\build\lib\release;..\..\lib\DevIL-SDK-x86-1.7.8\lib;E:\Microsoft DirectX SDK\Lib\x86;..\..\lib\freeglut\lib;..\..\lib\glew-1.6.0\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>Awesomium.lib;opengl32.lib;glu32.lib;freeglut.lib;DevIL.lib;ILU.lib;ILUT.lib;dinput8.lib;dxguid.lib;glew32.lib;glew32mx.lib;glew32mxs.lib;glew32s.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="Awesomium.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\GraphicsEngine\GraphicsEngine.vcxproj"> | ||
<Project>{49e1b397-f49f-4ed2-ab96-f1f2d5554f9f}</Project> | ||
</ProjectReference> | ||
<ProjectReference Include="..\MathLib\MathLib.vcxproj"> | ||
<Project>{81e06cc5-ae46-43a1-8620-d917f0676499}</Project> | ||
</ProjectReference> | ||
<ProjectReference Include="..\PhysicsEngine\PhysicsEngine.vcxproj"> | ||
<Project>{7bd022bb-a440-45ba-b0ed-aeacab29d802}</Project> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Pugixml\Pugixml.vcxproj"> | ||
<Project>{082260f9-4fca-446b-8652-e5b5eec19fce}</Project> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="Awesomium.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
</Project> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "GameEditor.h" | ||
|
||
|
||
GameEditor::GameEditor(void) | ||
{ | ||
} | ||
|
||
|
||
GameEditor::~GameEditor(void) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
class GameEditor | ||
{ | ||
public: | ||
GameEditor(void); | ||
~GameEditor(void); | ||
}; | ||
|
Oops, something went wrong.