diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index a0b8c370..de2384e2 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -12,7 +12,7 @@ # include "config.h" #endif -#if !defined _XBOX /* This file is meaningless on Xbox */ +#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ #if defined WIN32 && !_XBOX # define _USE_MATH_DEFINES /* for M_PI */ diff --git a/src/debug/sphere.cpp b/src/debug/sphere.cpp index a65a22bf..c6a812a3 100644 --- a/src/debug/sphere.cpp +++ b/src/debug/sphere.cpp @@ -12,7 +12,7 @@ # include "config.h" #endif -#if !defined _XBOX /* This file is meaningless on Xbox */ +#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ #if defined WIN32 # define _USE_MATH_DEFINES /* for M_PI */ diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index c3001876..a1feaae6 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -19,6 +19,10 @@ #ifdef WIN32 # define WIN32_LEAN_AND_MEAN # include +# if defined USE_D3D9 +# include +# include +# endif #endif #include "core.h" @@ -26,6 +30,12 @@ using namespace std; +#if defined USE_D3D9 +extern IDirect3DDevice9 *g_d3ddevice; +#elif defined _XBOX +extern D3DDevice *g_d3ddevice; +#endif + namespace lol { @@ -38,7 +48,11 @@ class ShaderData friend class Shader; private: -#if defined _XBOX +#if defined USE_D3D9 + IDirect3DVertexShader9 *vert_shader; + IDirect3DPixelShader9 *frag_shader; + ID3DXConstantTable *vert_table, *frag_table; +#elif defined _XBOX D3DVertexShader *vert_shader; D3DPixelShader *frag_shader; ID3DXConstantTable *vert_table, *frag_table; @@ -92,8 +106,7 @@ void Shader::Destroy(Shader *shader) Shader::Shader(char const *vert, char const *frag) : data(new ShaderData()) { -#if defined _XBOX - extern D3DDevice *g_d3ddevice; +#if defined USE_D3D9 || defined _XBOX ID3DXBuffer *shader_code, *error_msg; HRESULT hr; #elif !defined __CELLOS_LV2__ @@ -109,7 +122,7 @@ Shader::Shader(char const *vert, char const *frag) /* Compile vertex shader */ data->vert_crc = Hash::Crc32(vert); -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX hr = D3DXCompileShader(vert, (UINT)strlen(vert), NULL, NULL, "main", "vs_2_0", 0, &shader_code, &error_msg, &data->vert_table); @@ -148,7 +161,7 @@ Shader::Shader(char const *vert, char const *frag) /* Compile fragment shader */ data->frag_crc = Hash::Crc32(frag); -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX hr = D3DXCompileShader(frag, (UINT)strlen(frag), NULL, NULL, "main", "ps_2_0", 0, &shader_code, &error_msg, &data->frag_table); @@ -185,7 +198,7 @@ Shader::Shader(char const *vert, char const *frag) } #endif -#if !defined _XBOX && !defined __CELLOS_LV2__ +#if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__ /* Create program */ data->prog_id = glCreateProgram(); glAttachShader(data->prog_id, data->vert_id); @@ -198,7 +211,7 @@ Shader::Shader(char const *vert, char const *frag) int Shader::GetAttribLocation(char const *attr) const { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX /* FIXME: do we have attribs? */ return 0; #elif !defined __CELLOS_LV2__ @@ -211,9 +224,9 @@ int Shader::GetAttribLocation(char const *attr) const int Shader::GetUniformLocation(char const *uni) const { -#if defined _XBOX - D3DXHANDLE hr1 = data->frag_table->GetConstantByName(NULL, uni); - D3DXHANDLE hr2 = data->vert_table->GetConstantByName(NULL, uni); +#if defined USE_D3D9 || defined _XBOX + UINT hr1 = (uintptr_t)data->frag_table->GetConstantByName(NULL, uni); + UINT hr2 = (uintptr_t)data->vert_table->GetConstantByName(NULL, uni); return (int)(((uint32_t)hr1 << 16) | (uint32_t)hr2); #elif !defined __CELLOS_LV2__ return glGetUniformLocation(data->prog_id, uni); @@ -229,7 +242,7 @@ int Shader::GetUniformLocation(char const *uni) const void Shader::SetUniform(int uni, float f) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX SetUniform(uni, vec4(f, 0, 0, 0)); #elif !defined __CELLOS_LV2__ glUniform1f(uni, f); @@ -240,7 +253,7 @@ void Shader::SetUniform(int uni, float f) void Shader::SetUniform(int uni, vec2 const &v) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX SetUniform(uni, vec4(v, 0, 0)); #elif !defined __CELLOS_LV2__ glUniform2f(uni, v.x, v.y); @@ -251,7 +264,7 @@ void Shader::SetUniform(int uni, vec2 const &v) void Shader::SetUniform(int uni, vec3 const &v) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX SetUniform(uni, vec4(v, 0)); #elif !defined __CELLOS_LV2__ glUniform3f(uni, v.x, v.y, v.z); @@ -263,10 +276,9 @@ void Shader::SetUniform(int uni, vec3 const &v) void Shader::SetUniform(int uni, vec4 const &v) { /* FIXME: use the array versions of these functions */ -#if defined _XBOX - extern D3DDevice *g_d3ddevice; - D3DXHANDLE hr1 = (uint32_t)uni >> 16; - D3DXHANDLE hr2 = (uint32_t)(uint16_t)uni; +#if defined USE_D3D9 || defined _XBOX + UINT hr1 = (uint32_t)uni >> 16; + UINT hr2 = (uint32_t)(uint16_t)uni; g_d3ddevice->SetPixelShaderConstantF(hr1, &v[0], 1); g_d3ddevice->SetVertexShaderConstantF(hr2, &v[0], 1); #elif !defined __CELLOS_LV2__ @@ -278,10 +290,9 @@ void Shader::SetUniform(int uni, vec4 const &v) void Shader::SetUniform(int uni, mat4 const &m) { -#if defined _XBOX - extern D3DDevice *g_d3ddevice; - D3DXHANDLE hr1 = (uint32_t)uni >> 16; - D3DXHANDLE hr2 = (uint32_t)(uint16_t)uni; +#if defined USE_D3D9 || defined _XBOX + UINT hr1 = (uint32_t)uni >> 16; + UINT hr2 = (uint32_t)(uint16_t)uni; g_d3ddevice->SetPixelShaderConstantF(hr1, &m[0][0], 4); g_d3ddevice->SetVertexShaderConstantF(hr2, &m[0][0], 4); #elif !defined __CELLOS_LV2__ @@ -293,10 +304,10 @@ void Shader::SetUniform(int uni, mat4 const &m) void Shader::Bind() const { -#if defined _XBOX - extern D3DDevice *g_d3ddevice; - g_d3ddevice->SetVertexShader(data->vert_shader); - g_d3ddevice->SetPixelShader(data->frag_shader); +#if defined USE_D3D9 || defined _XBOX + HRESULT hr; + hr = g_d3ddevice->SetVertexShader(data->vert_shader); + hr = g_d3ddevice->SetPixelShader(data->frag_shader); #elif !defined __CELLOS_LV2__ glUseProgram(data->prog_id); #else @@ -309,8 +320,7 @@ void Shader::Bind() const Shader::~Shader() { -#if defined _XBOX - extern D3DDevice *g_d3ddevice; +#if defined USE_D3D9 || defined _XBOX data->vert_shader->Release(); data->vert_table->Release(); data->frag_shader->Release(); @@ -333,7 +343,7 @@ int ShaderData::GetVersion() { static int version = 0; -#if !defined _XBOX && !defined __CELLOS_LV2__ +#if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__ if (!version) { char buf[4096]; diff --git a/src/gradient.cpp b/src/gradient.cpp index 3fed292b..cdb776e8 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -32,7 +32,7 @@ class GradientData private: Shader *shader; -#if !defined _XBOX /* This file is meaningless on Xbox */ +#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ GLuint bufs[2]; #if defined HAVE_GL_2X && !defined __APPLE__ @@ -65,7 +65,7 @@ void Gradient::TickDraw(float deltams) { Entity::TickDraw(deltams); -#if !defined _XBOX /* This file is meaningless on Xbox */ +#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ if (!data->shader) { #if !defined __CELLOS_LV2__ diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 2d04ca6a..551d82ef 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -14,6 +14,10 @@ #if defined USE_SDL # include +# if defined USE_D3D9 +# include +# include +# endif #endif #include "core.h" @@ -21,6 +25,10 @@ #include "platform/sdl/sdlapp.h" #include "platform/sdl/sdlinput.h" +#if defined USE_D3D9 +HWND g_hwnd = NULL; +#endif + namespace lol { @@ -51,12 +59,20 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : exit(EXIT_FAILURE); } +# if defined USE_D3D9 + SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 16, 0); + SDL_SysWMinfo wminfo; + SDL_VERSION(&wminfo.version); + SDL_GetWMInfo(&wminfo); + g_hwnd = wminfo.window; +# else SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); +# endif if (!video) { - Log::Error("cannot create OpenGL screen: %s\n", SDL_GetError()); + Log::Error("cannot create rendering window: %s\n", SDL_GetError()); SDL_Quit(); exit(EXIT_FAILURE); } @@ -84,10 +100,19 @@ void SdlApp::Run() { while (!Ticker::Finished()) { +#if defined USE_SDL && defined USE_D3D9 + extern IDirect3DDevice9 *g_d3ddevice; + g_d3ddevice->BeginScene(); +#endif /* Tick the renderer, show the frame and clamp to desired framerate. */ Ticker::TickDraw(); #if defined USE_SDL +# if defined USE_D3D9 + g_d3ddevice->EndScene(); + g_d3ddevice->Present(NULL, NULL, NULL, NULL); +# else SDL_GL_SwapBuffers(); +# endif #endif } } diff --git a/src/scene.cpp b/src/scene.cpp index e4f7fc72..06adeaac 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -60,7 +60,7 @@ private: int ntiles; float angle; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene not implemented") @@ -90,7 +90,7 @@ Scene::Scene(float angle) data->ntiles = 0; data->angle = angle; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Scene() not implemented") @@ -108,7 +108,7 @@ Scene::Scene(float angle) Scene::~Scene() { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::~Scene() not implemented") @@ -144,7 +144,7 @@ void Scene::Reset() void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) { -#if !defined _XBOX /* No WPOS on Xbox */ +#if !defined USE_D3D9 && !defined _XBOX if ((data->ntiles % 1024) == 0) data->tiles = (Tile *)realloc(data->tiles, (data->ntiles + 1024) * sizeof(Tile)); @@ -161,7 +161,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) void Scene::Render() // XXX: rename to Blit() { -#if !defined _XBOX /* No WPOS on Xbox */ +#if !defined USE_D3D9 && !defined _XBOX /* No WPOS on Xbox, what about Win32? */ if (!stdshader) { #if !defined _XBOX && !defined __CELLOS_LV2__ @@ -343,7 +343,7 @@ void Scene::Render() // XXX: rename to Blit() uni_mat = stdshader->GetUniformLocation("model_matrix"); stdshader->SetUniform(uni_mat, data->model_matrix); -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") @@ -358,7 +358,7 @@ void Scene::Render() // XXX: rename to Blit() //cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0); #endif -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") @@ -380,7 +380,7 @@ void Scene::Render() // XXX: rename to Blit() for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") @@ -422,7 +422,7 @@ void Scene::Render() // XXX: rename to Blit() #if defined HAVE_GL_2X && !defined __APPLE__ glBindVertexArray(data->vao); #endif -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") @@ -473,7 +473,7 @@ void Scene::Render() // XXX: rename to Blit() data->tiles = 0; data->ntiles = 0; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") @@ -489,7 +489,7 @@ void Scene::Render() // XXX: rename to Blit() #endif glDisable(GL_BLEND); #endif -#endif /* _XBOX */ +#endif /* _XBOX || USE_D3D9 */ } } /* namespace lol */ diff --git a/src/tileset.cpp b/src/tileset.cpp index 81bb588b..92b79cb3 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -46,7 +46,7 @@ private: float tx, ty; Image *img; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet not implemented") @@ -69,7 +69,7 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count) sprintf(data->name, " %s", path); data->tiles = NULL; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") @@ -118,7 +118,7 @@ void TileSet::TickDraw(float deltams) { if (data->img) delete data->img; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") @@ -131,7 +131,7 @@ void TileSet::TickDraw(float deltams) } else if (data->img) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") @@ -203,7 +203,7 @@ ivec2 TileSet::GetSize(int tileid) const void TileSet::Bind() { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::Bind() not implemented") @@ -228,7 +228,7 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, int dy = o ? 0 : data->size.y * scale.y; int dz = o ? data->size.y * scale.y : 0; -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") diff --git a/src/video.cpp b/src/video.cpp index 0d007091..7ee21828 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -14,7 +14,9 @@ #include -#if _XBOX +#if defined USE_D3D9 +# include +#elif defined _XBOX # include # undef near /* Fuck Microsoft */ # undef far /* Fuck Microsoft again */ @@ -30,8 +32,13 @@ using namespace std; -#if defined _XBOX /* FIXME: g_d3ddevice should never be exported */ +#if defined USE_D3D9 +IDirect3DDevice9 *g_d3ddevice; +# if defined USE_SDL +extern HWND g_hwnd; +# endif +#elif defined _XBOX D3DDevice *g_d3ddevice; #endif @@ -45,7 +52,11 @@ class VideoData private: static mat4 proj_matrix, view_matrix; static ivec2 saved_viewport; -#if defined _XBOX +#if defined USE_D3D9 + static IDirect3D9 *d3d_ctx; + static IDirect3DDevice9 *d3d_dev; + static D3DCOLOR clear_color; +#elif defined _XBOX static Direct3D *d3d_ctx; static D3DDevice *d3d_dev; static D3DCOLOR clear_color; @@ -56,7 +67,11 @@ mat4 VideoData::proj_matrix; mat4 VideoData::view_matrix; ivec2 VideoData::saved_viewport(0, 0); -#if defined _XBOX +#if defined USE_D3D9 +IDirect3D9 *VideoData::d3d_ctx; +IDirect3DDevice9 *VideoData::d3d_dev; +D3DCOLOR VideoData::clear_color; +#elif defined _XBOX Direct3D *VideoData::d3d_ctx; D3DDevice *VideoData::d3d_dev; D3DCOLOR VideoData::clear_color; @@ -68,7 +83,7 @@ D3DCOLOR VideoData::clear_color; void Video::Setup(ivec2 size) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION); if (!VideoData::d3d_ctx) { @@ -76,15 +91,22 @@ void Video::Setup(ivec2 size) exit(EXIT_FAILURE); } + HWND window = 0; D3DPRESENT_PARAMETERS d3dpp; memset(&d3dpp, 0, sizeof(d3dpp)); +# if defined USE_SDL + window = g_hwnd; + d3dpp.hDeviceWindow = g_hwnd; + d3dpp.Windowed = TRUE; +# elif defined _XBOX XVIDEO_MODE VideoMode; XGetVideoMode( &VideoMode ); if (size.x > VideoMode.dwDisplayWidth) size.x = VideoMode.dwDisplayWidth; if (size.y > VideoMode.dwDisplayHeight) size.y = VideoMode.dwDisplayHeight; +# endif VideoData::saved_viewport = size; VideoData::clear_color = D3DCOLOR_XRGB(26, 51, 77); @@ -98,9 +120,10 @@ void Video::Setup(ivec2 size) d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - if (FAILED(VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL, - D3DCREATE_HARDWARE_VERTEXPROCESSING, - &d3dpp, &VideoData::d3d_dev))) + HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, window, + D3DCREATE_HARDWARE_VERTEXPROCESSING, + &d3dpp, &VideoData::d3d_dev); + if (FAILED(hr)) { Log::Error("cannot create D3D device\n"); exit(EXIT_FAILURE); @@ -177,7 +200,7 @@ void Video::SetFov(float theta) void Video::SetDepth(bool set) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX # define STR0(x) #x # define STR(x) STR0(x) # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetDepth() not implemented") @@ -191,7 +214,7 @@ void Video::SetDepth(bool set) void Video::SetClearColor(vec4 color) { -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX VideoData::clear_color = D3DCOLOR_XRGB((int)(color.r * 255.999f), (int)(color.g * 255.999f), (int)(color.b * 255.999f)); @@ -203,7 +226,7 @@ void Video::SetClearColor(vec4 color) void Video::Clear() { ivec2 size = GetSize(); -#if defined _XBOX +#if defined USE_D3D9 || defined _XBOX VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, VideoData::clear_color, 1.0f, 0); @@ -222,7 +245,7 @@ void Video::Destroy() void Video::Capture(uint32_t *buffer) { -#if _XBOX +#if defined USE_D3D9 || defined _XBOX /* TODO */ #else GLint v[4]; @@ -258,7 +281,7 @@ void Video::Capture(uint32_t *buffer) ivec2 Video::GetSize() { -#if _XBOX +#if defined USE_D3D9 || defined _XBOX return VideoData::saved_viewport; #elif 1 /* GetSize() is called too often on the game thread; we cannot rely on diff --git a/test/tutorial/tut01.cpp b/test/tutorial/tut01.cpp index 4cb80bb2..84e0015a 100644 --- a/test/tutorial/tut01.cpp +++ b/test/tutorial/tut01.cpp @@ -19,6 +19,12 @@ using namespace std; using namespace lol; +#if defined _WIN32 && defined USE_D3D9 +# define FAR +# define NEAR +# include +#endif + #if USE_SDL && defined __APPLE__ # include #endif @@ -32,6 +38,12 @@ using namespace lol; # include #endif +#if defined USE_D3D9 +extern IDirect3DDevice9 *g_d3ddevice; +#elif defined _XBOX +extern D3DDevice *g_d3ddevice; +#endif + class Triangle : public WorldEntity { public: @@ -50,7 +62,7 @@ public: if (!m_ready) { m_shader = Shader::Create( -#if !defined __CELLOS_LV2__ && !defined _XBOX +#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 "#version 120\n" "attribute vec2 in_Position;" "void main(void) {" @@ -72,21 +84,20 @@ public: "}" #endif ); -#if !defined _XBOX +#if !defined _XBOX && !defined USE_D3D9 m_attrib = m_shader->GetAttribLocation("in_Position"); #endif m_ready = true; -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 /* Method 1: store vertex buffer on the GPU memory */ glGenBuffers(1, &m_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices, GL_STATIC_DRAW); -#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX +#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 /* Method 2: upload vertex information at each frame */ -#elif defined _XBOX - extern D3DDevice *g_d3ddevice; +#elif defined _XBOX || defined USE_D3D9 D3DVERTEXELEMENT9 const elements[2] = { { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, @@ -108,8 +119,7 @@ public: } m_shader->Bind(); -#if defined _XBOX - extern D3DDevice *g_d3ddevice; +#if defined _XBOX || defined USE_D3D9 g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); g_d3ddevice->SetVertexDeclaration(m_vdecl); g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices)); @@ -126,13 +136,13 @@ public: glVertexPointer(3, GL_FLOAT, 0, m_vertices); #endif -#if defined _XBOX - g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); +#if defined _XBOX || defined USE_D3D9 + g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 3); #else glDrawArrays(GL_TRIANGLES, 0, 3); #endif -#if defined _XBOX +#if defined _XBOX || defined USE_D3D9 /* FIXME: do we need to unset anything here? */ #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ glDisableVertexAttribArray(m_attrib); @@ -148,7 +158,10 @@ public: private: vec2 m_vertices[3]; Shader *m_shader; -#if defined _XBOX +#if defined USE_D3D9 + IDirect3DVertexDeclaration9 *m_vdecl; + IDirect3DVertexBuffer9 *m_vbo; +#elif defined _XBOX D3DVertexDeclaration *m_vdecl; D3DVertexBuffer *m_vbo; #else diff --git a/test/tutorial/tut02.cpp b/test/tutorial/tut02.cpp index a4570211..dba6a3c4 100644 --- a/test/tutorial/tut02.cpp +++ b/test/tutorial/tut02.cpp @@ -19,6 +19,12 @@ using namespace std; using namespace lol; +#if defined _WIN32 && defined USE_D3D9 +# define FAR +# define NEAR +# include +#endif + #if USE_SDL && defined __APPLE__ # include #endif @@ -28,6 +34,12 @@ using namespace lol; # include #endif +#if defined USE_D3D9 +extern IDirect3DDevice9 *g_d3ddevice; +#elif defined _XBOX +extern D3DDevice *g_d3ddevice; +#endif + class Cube : public WorldEntity { public: @@ -92,7 +104,7 @@ public: if (!m_ready) { m_shader = Shader::Create( -#if !defined __CELLOS_LV2__ && !defined _XBOX +#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 "#version 120\n" "attribute vec3 in_Vertex;" "attribute vec3 in_Color;" @@ -126,14 +138,14 @@ public: "}" #endif ); -#if !defined _XBOX +#if !defined _XBOX && !defined USE_D3D9 m_coord = m_shader->GetAttribLocation("in_Vertex"); m_color = m_shader->GetAttribLocation("in_Color"); #endif m_mvp = m_shader->GetUniformLocation("in_Matrix"); m_ready = true; -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 /* Method 1: store vertex buffer on the GPU memory */ glGenBuffers(1, &m_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_vbo); @@ -147,8 +159,7 @@ public: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_indices), m_indices, GL_STATIC_DRAW); -#elif defined _XBOX - extern D3DDevice *g_d3ddevice; +#elif defined _XBOX || defined USE_D3D9 D3DVERTEXELEMENT9 const elements[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, @@ -191,8 +202,7 @@ public: m_shader->Bind(); m_shader->SetUniform(m_mvp, m_matrix); -#if defined _XBOX - extern D3DDevice *g_d3ddevice; +#if defined _XBOX || defined USE_D3D9 g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); g_d3ddevice->SetVertexDeclaration(m_vdecl); g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices)); @@ -232,7 +242,11 @@ private: vec3 m_colors[8]; i16vec3 m_indices[12]; Shader *m_shader; -#if defined _XBOX +#if defined USE_D3D9 + IDirect3DVertexDeclaration9 *m_vdecl; + IDirect3DVertexBuffer9 *m_vbo, *m_cbo; + IDirect3DIndexBuffer9 *m_ibo; +#elif defined _XBOX D3DVertexDeclaration *m_vdecl; D3DVertexBuffer *m_vbo, *m_cbo; D3DIndexBuffer *m_ibo; diff --git a/win32/Lol.Rules.props b/win32/Lol.Rules.props index 8a467f76..075366e8 100644 --- a/win32/Lol.Rules.props +++ b/win32/Lol.Rules.props @@ -10,7 +10,7 @@ true Fast $(SolutionDir)\..\src;%(AdditionalIncludeDirectories) - $(GlIncludes);$(SdlIncludes);%(AdditionalIncludeDirectories) + $(GlIncludes);$(SdlIncludes);$(D3d9Includes);%(AdditionalIncludeDirectories) WIN32;$(Win32Defines);%(PreprocessorDefinitions) _XBOX;$(XboxDefines);%(PreprocessorDefinitions) false @@ -32,8 +32,8 @@ true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(SdlDeps);$(GdiDeps);$(GlDeps);%(AdditionalDependencies) - $(SdlLibs);$(GlLibs);%(AdditionalLibraryDirectories) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(SdlDeps);$(GdiDeps);$(GlDeps);$(D3d9Deps);%(AdditionalDependencies) + $(SdlLibs);$(GlLibs);$(D3d9Libs);%(AdditionalLibraryDirectories) xapilibd.lib;d3d9d.lib;d3dx9d.lib;xgraphicsd.lib;xboxkrnl.lib;xnetd.lib;xaudiod2.lib;xactd3.lib;x3daudiod.lib;xmcored.lib;xbdm.lib;vcompd.lib;%(AdditionalDependencies) xapilib.lib;d3d9.lib;d3dx9.lib;xgraphics.lib;xboxkrnl.lib;xnet.lib;xaudio2.lib;xact3.lib;x3daudio.lib;xmcore.lib;vcomp.lib;%(AdditionalDependencies) diff --git a/win32/Lol.Vars.props b/win32/Lol.Vars.props index 7d46299b..1794bd13 100644 --- a/win32/Lol.Vars.props +++ b/win32/Lol.Vars.props @@ -3,45 +3,64 @@ $(SolutionDir)\..\contrib - $(ContribDir)\glew-1.7.0 - $(ContribDir)\gtk-2.22.1 - $(ContribDir)\gtkglarea-2.0.1 + + $(ContribDir)\sdl-1.2.14 $(ContribDir)\sdl-image-1.2.10 $(ContribDir)\sdl-mixer-1.2.11 - $(GlewDir)\include\GL - $(GtkDir)\lib\glib-2.0\include;$(GtkDir)\lib\gtk-2.0\include;$(GtkDir)\include\glib-2.0;$(GtkDir)\include\gtk-2.0;$(GtkDir)\include\cairo;$(GtkDir)\include\pango-1.0;$(GtkDir)\include\gdk-pixbuf-2.0;$(GtkDir)\include\atk-1.0;$(GtkGlDir)\include $(SdlDir)\include;$(SdlImageDir)\include;$(SdlMixerDir)\include - $(GlewDir)\lib\i686-w64-mingw32 - $(GtkDir)\lib;$(GtkDir)\bin;$(GtkGlDir)\lib $(SdlDir)\lib\i686-w64-mingw32;$(SdlImageDir)\lib\i686-w64-mingw32;$(SdlMixerDir)\lib\i686-w64-mingw32 + SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib + + + $(ContribDir)\gtk-2.22.1 + $(ContribDir)\gtkglarea-2.0.1 + $(GtkDir)\lib\glib-2.0\include;$(GtkDir)\lib\gtk-2.0\include;$(GtkDir)\include\glib-2.0;$(GtkDir)\include\gtk-2.0;$(GtkDir)\include\cairo;$(GtkDir)\include\pango-1.0;$(GtkDir)\include\gdk-pixbuf-2.0;$(GtkDir)\include\atk-1.0;$(GtkGlDir)\include + $(GtkDir)\lib;$(GtkDir)\bin;$(GtkGlDir)\lib + gobject-2.0.lib;gthread-2.0.lib;glib-2.0.lib;gdk-win32-2.0.lib;gtk-win32-2.0.lib;gtkgl-2.0.lib + + Gdiplus.lib + + + $(ContribDir)\glew-1.7.0 + $(GlewDir)\include\GL + $(GlewDir)\lib\i686-w64-mingw32 opengl32.lib;glew32.lib - gobject-2.0.lib;gthread-2.0.lib;glib-2.0.lib;gdk-win32-2.0.lib;gtk-win32-2.0.lib;gtkgl-2.0.lib - SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib - USE_GLEW;GLEW_STATIC;HAVE_SDL_H;USE_SDL;USE_GDIPLUS + + + $(DXSDK_DIR)\Include + $(DXSDK_DIR)\Lib\x86 + $(DXSDK_DIR)\Lib\x64 + d3d9.lib;d3dx9.lib + d3d9.lib;d3dx9d.lib + + HAVE_SDL_H;USE_SDL;USE_GDIPLUS;USE_D3D9 $(ContribDir) - $(GlewDir) - $(GtkDir) - $(GtkGlDir) $(SdlDir) $(SdlImageDir) $(SdlMixerDir) - $(GlIncludes) - $(GtkIncludes) $(SdlIncludes) - $(GlLibs) - $(GtkLibs) $(SdlLibs) + $(SdlDeps) + $(GtkDir) + $(GtkGlDir) + $(GtkIncludes) + $(GtkLibs) + $(GtkDeps) $(GdiDeps) + $(GlewDir) + $(GlIncludes) + $(GlLibs) $(GlDeps) - $(GtkDeps) - $(SdlDeps) + $(D3d9Includes) + $(D3d9Libs) + $(D3d9Deps) $(Win32Defines) $(XboxDefines)