summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mingw3d/LICENSE1
-rw-r--r--mingw3d/LICENSE.CPOL163
-rwxr-xr-xmingw3d/build6
-rwxr-xr-xmingw3d/build_ddk_wine8
-rw-r--r--mingw3d/mingw3d.cpp393
5 files changed, 571 insertions, 0 deletions
diff --git a/mingw3d/LICENSE b/mingw3d/LICENSE
new file mode 100644
index 0000000..b27b4fd
--- /dev/null
+++ b/mingw3d/LICENSE
@@ -0,0 +1 @@
+mingw3d.cpp is taken from the code project and is under the CPOL (code project open license) 1.0.2, see LICENSE.CPOL
diff --git a/mingw3d/LICENSE.CPOL b/mingw3d/LICENSE.CPOL
new file mode 100644
index 0000000..4cc1e09
--- /dev/null
+++ b/mingw3d/LICENSE.CPOL
@@ -0,0 +1,163 @@
+ The Code Project Open License (CPOL) 1.02
+
+Preamble
+
+ This License governs Your use of the Work. This License is intended to allow developers to use the
+ Source Code and Executable Files provided as part of the Work in any application in any form.
+
+ The main points subject to the terms of the License are:
+
+ * Source Code and Executable Files can be used in commercial applications;
+ * Source Code and Executable Files can be redistributed; and
+ * Source Code can be modified to create derivative works.
+ * No claim of suitability, guarantee, or any warranty whatsoever is provided. The software is provided
+ "as-is".
+ * The Article accompanying the Work may not be distributed or republished without the Author's consent
+
+ This License is entered between You, the individual or other entity reading or otherwise making
+ use of the Work licensed pursuant to this License and the individual or other entity which offers
+ the Work under the terms of this License ("Author").
+
+License
+
+ THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CODE PROJECT OPEN LICENSE
+ ("LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK
+ OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
+
+ BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HEREIN, YOU ACCEPT AND AGREE TO BE BOUND BY THE
+ TERMS OF THIS LICENSE. THE AUTHOR GRANTS YOU THE RIGHTS CONTAINED HEREIN IN CONSIDERATION OF YOUR
+ ACCEPTANCE OF SUCH TERMS AND CONDITIONS. IF YOU DO NOT AGREE TO ACCEPT AND BE BOUND BY THE TERMS
+ OF THIS LICENSE, YOU CANNOT MAKE ANY USE OF THE WORK.
+
+ 1. Definitions.
+
+  1. "Articles" means, collectively, all articles written by Author which describes how the Source
+ Code and Executable Files for the Work may be used by a user.
+  2. "Author" means the individual or entity that offers the Work under the terms of this License.
+  3. "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing
+ works.
+  4. "Executable Files" refer to the executables, binary files, configuration and any required data
+ files included in the Work.
+  5. "Publisher" means the provider of the website, magazine, CD-ROM, DVD or other medium from or by
+ which the Work is obtained by You.
+  6. "Source Code" refers to the collection of source code and configuration files used to create
+ the Executable Files.
+  7. "Standard Version" refers to such a Work if it has not been modified, or has been modified in
+ accordance with the consent of the Author, such consent being in the full discretion of the
+ Author.
+  8. "Work" refers to the collection of files distributed by the Publisher, including the Source
+ Code, Executable Files, binaries, data files, documentation, whitepapers and the Articles.
+  9. "You" is you, an individual or entity wishing to use the Work and exercise your rights under
+ this License.
+
+ 2. Fair Use/Fair Use Rights. Nothing in this License is intended to reduce, limit, or restrict any
+ rights arising from fair use, fair dealing, first sale or other limitations on the exclusive rights
+ of the copyright owner under copyright law or other applicable laws.
+ 3. License Grant. Subject to the terms and conditions of this License, the Author hereby grants You a
+ worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright)
+ license to exercise the rights in the Work as stated below:
+
+  1. You may use the standard version of the Source Code or Executable Files in Your own
+ applications.
+  2. You may apply bug fixes, portability fixes and other modifications obtained from the Public
+ Domain or from the Author. A Work modified in such a way shall still be considered the standard
+ version and will be subject to this License.
+  3. You may otherwise modify Your copy of this Work (excluding the Articles) in any way to create a
+ Derivative Work, provided that You insert a prominent notice in each changed file stating how,
+ when and where You changed that file.
+  4. You may distribute the standard version of the Executable Files and Source Code or Derivative
+ Work in aggregate with other (possibly commercial) programs as part of a larger (possibly
+ commercial) software distribution.
+  5. The Articles discussing the Work published in any form by the author may not be distributed or
+ republished without the Author's consent. The author retains copyright to any such Articles.
+ You may use the Executable Files and Source Code pursuant to this License but you may not
+ repost or republish or otherwise distribute or make available the Articles, without the prior
+ written consent of the Author.
+
+ Any subroutines or modules supplied by You and linked into the Source Code or Executable Files of
+ this Work shall not be considered part of this Work and will not be subject to the terms of this
+ License.
+ 4. Patent License. Subject to the terms and conditions of this License, each Author hereby grants to
+ You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in
+ this section) patent license to make, have made, use, import, and otherwise transfer the Work.
+ 5. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the
+ following restrictions:
+
+  1. You agree not to remove any of the original copyright, patent, trademark, and attribution
+ notices and associated disclaimers that may appear in the Source Code or Executable Files.
+  2. You agree not to advertise or in any way imply that this Work is a product of Your own.
+  3. The name of the Author may not be used to endorse or promote products derived from the Work
+ without the prior written consent of the Author.
+  4. You agree not to sell, lease, or rent any part of the Work. This does not restrict you from
+ including the Work or any part of the Work inside a larger software distribution that itself is
+ being sold. The Work by itself, though, cannot be sold, leased or rented.
+  5. You may distribute the Executable Files and Source Code only under the terms of this License,
+ and You must include a copy of, or the Uniform Resource Identifier for, this License with every
+ copy of the Executable Files or Source Code You distribute and ensure that anyone receiving
+ such Executable Files and Source Code agrees that the terms of this License apply to such
+ Executable Files and/or Source Code. You may not offer or impose any terms on the Work that
+ alter or restrict the terms of this License or the recipients' exercise of the rights granted
+ hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this
+ License and to the disclaimer of warranties. You may not distribute the Executable Files or
+ Source Code with any technological measures that control access or use of the Work in a manner
+ inconsistent with the terms of this License.
+  6. You agree not to use the Work for illegal, immoral or improper purposes, or on pages containing
+ illegal, immoral or improper material. The Work is subject to applicable export laws. You agree
+ to comply with all such laws and regulations that may apply to the Work after Your receipt of
+ the Work.
+
+ 6. Representations, Warranties and Disclaimer. THIS WORK IS PROVIDED "AS IS", "WHERE IS" AND "AS
+ AVAILABLE", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES OR CONDITIONS OR GUARANTEES. YOU, THE USER,
+ ASSUME ALL RISK IN ITS USE, INCLUDING COPYRIGHT INFRINGEMENT, PATENT INFRINGEMENT, SUITABILITY, ETC.
+ AUTHOR EXPRESSLY DISCLAIMS ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES OR CONDITIONS, INCLUDING
+ WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF MERCHANTABILITY, MERCHANTABLE QUALITY OR FITNESS FOR
+ A PARTICULAR PURPOSE, OR ANY WARRANTY OF TITLE OR NON-INFRINGEMENT, OR THAT THE WORK (OR ANY PORTION
+ THEREOF) IS CORRECT, USEFUL, BUG-FREE OR FREE OF VIRUSES. YOU MUST PASS THIS DISCLAIMER ON WHENEVER
+ YOU DISTRIBUTE THE WORK OR DERIVATIVE WORKS.
+ 7. Indemnity. You agree to defend, indemnify and hold harmless the Author and the Publisher from and
+ against any claims, suits, losses, damages, liabilities, costs, and expenses (including reasonable
+ legal or attorneys� fees) resulting from or relating to any use of the Work by You.
+ 8. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL THE
+ AUTHOR OR THE PUBLISHER BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL,
+ CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK OR
+ OTHERWISE, EVEN IF THE AUTHOR OR THE PUBLISHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ 9. Termination.
+
+  1. This License and the rights granted hereunder will terminate automatically upon any breach by
+ You of any term of this License. Individuals or entities who have received Derivative Works
+ from You under this License, however, will not have their licenses terminated provided such
+ individuals or entities remain in full compliance with those licenses. Sections 1, 2, 6, 7, 8,
+ 9, 10 and 11 will survive any termination of this License.
+  2. If You bring a copyright, trademark, patent or any other infringement claim against any
+ contributor over infringements You claim are made by the Work, your License from such
+ contributor to the Work ends automatically.
+  3. Subject to the above terms and conditions, this License is perpetual (for the duration of the
+ applicable copyright in the Work). Notwithstanding the above, the Author reserves the right to
+ release the Work under different license terms or to stop distributing the Work at any time;
+ provided, however that any such election will not serve to withdraw this License (or any other
+ license that has been, or is required to be, granted under the terms of this License), and this
+ License will continue in full force and effect unless terminated as stated above.
+
+10. Publisher. The parties hereby confirm that the Publisher shall not, under any circumstances, be
+ responsible for and shall not have any liability in respect of the subject matter of this License.
+ The Publisher makes no warranty whatsoever in connection with the Work and shall not be liable to
+ You or any party on any legal theory for any damages whatsoever, including without limitation any
+ general, special, incidental or consequential damages arising in connection to this license. The
+ Publisher reserves the right to cease making the Work available to You at any time without notice
+11. Miscellaneous
+
+  1. This License shall be governed by the laws of the location of the head office of the Author or
+ if the Author is an individual, the laws of location of the principal place of residence of the
+ Author.
+  2. If any provision of this License is invalid or unenforceable under applicable law, it shall not
+ affect the validity or enforceability of the remainder of the terms of this License, and
+ without further action by the parties to this License, such provision shall be reformed to the
+ minimum extent necessary to make such provision valid and enforceable.
+  3. No term or provision of this License shall be deemed waived and no breach consented to unless
+ such waiver or consent shall be in writing and signed by the party to be charged with such
+ waiver or consent.
+  4. This License constitutes the entire agreement between the parties with respect to the Work
+ licensed herein. There are no understandings, agreements or representations with respect to the
+ Work not specified herein. The Author shall not be bound by any additional provisions that may
+ appear in any communication from You. This License may not be modified without the mutual
+ written agreement of the Author and You.
diff --git a/mingw3d/build b/mingw3d/build
new file mode 100755
index 0000000..faa44f9
--- /dev/null
+++ b/mingw3d/build
@@ -0,0 +1,6 @@
+#!/bin/bash
+SDK="/home/alon/.wine/drive_c/Program Files (x86)/Microsoft DirectX SDK (August 2007)"
+LIB="$SDK/Lib/x86"
+#winmm.lib
+i686-w64-mingw32-g++ -g -c mingw3d.cpp
+i686-w64-mingw32-g++ -g -fcheck-new -o mingw3d_2.exe -mwindows -I "$SDK/Include/" -L "$SDK/Lib/" -ld3d9 mingw3d.o "$LIB/d3d9.lib" "$LIB/d3dxof.lib" "$LIB/dxguid.lib" "$LIB/d3dx9d.lib"
diff --git a/mingw3d/build_ddk_wine b/mingw3d/build_ddk_wine
new file mode 100755
index 0000000..b6ff0c3
--- /dev/null
+++ b/mingw3d/build_ddk_wine
@@ -0,0 +1,8 @@
+#!/bin/bash
+SDK="/home/alon/.wine/drive_c/Program Files (x86)/Microsoft DirectX SDK (August 2007)"
+DDK="$HOME/.wine/drive_c/WinDDK/7600.16385.1/"
+CC="$DDX/bin/x86/x86/cl.exe"
+LIB="$SDK/Lib/x86"
+#winmm.lib
+$CC /g /c mingw3d.cpp
+$CC /o mingw3d_2.exe -mwindows -I "$SDK/Include/" -L "$SDK/Lib/" -ld3d9 mingw3d.o "$LIB/d3d9.lib" "$LIB/d3dxof.lib" "$LIB/dxguid.lib" "$LIB/d3dx9d.lib"
diff --git a/mingw3d/mingw3d.cpp b/mingw3d/mingw3d.cpp
new file mode 100644
index 0000000..921d76c
--- /dev/null
+++ b/mingw3d/mingw3d.cpp
@@ -0,0 +1,393 @@
+/************************
+ Direct3D Demo
+ J. Beau Wilkinson
+ ************************/
+
+// Include the basic windows header files and the Direct3D header file
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#include <windows.h>
+
+//Include the Direct3D header
+#include <d3dx9.h>
+
+// Screen resolutions... freely adjustable within the limits of the hardware
+#define APP_WIDTH 800
+#define APP_HEIGHT 600
+
+//This helps clean up COM objects
+#define RELEASE_COM_OBJECT(i) if(i!=NULL&& i) i->Release();
+
+// Global declarations... generally, it's wise to minimize globals. These items
+// are needed by WindowProc(), or in functions called by the WindowProc
+// function. Because the signature of WindowProc is set, it's impossible to
+// access these as parameters, and some sort of global access is necessary.
+
+LPDIRECT3D9 d3d=NULL; //Pointer to our Direct3D interface
+LPDIRECT3DDEVICE9 device=NULL; //Pointer to the device class
+LPDIRECT3DVERTEXBUFFER9 vertex_buffer=NULL; //The pointer to the vertex buffer
+LPDIRECT3DTEXTURE9 texture_1=NULL; //Texture for our single large solid
+
+// Demo constants
+#define CUBE_ACCEL 1.0025
+#define CUBE_START_SPEED 0.02
+#define CUBE_MAX_SPEED 0.10
+#define CAMERA_DISTANCE 19.5
+#define AMBIENT_BRIGHTNESS 140
+#define TEXTURE_SIZE 1024
+#define VERTICAL_VIEWFIELD_DEGREES 45.0
+#define FRUSTUM_NEAR_Z 1.0f
+#define FRUSTUM_FAR_Z 100.0f
+#define LIGHT_DISTANCE 40.0f
+#define LIGHT_RANGE 60.0f
+#define LIGHT_CONE_RADIANS_INNER 0.405f;
+#define LIGHT_CONE_RADIANS_OUTER 0.425f;
+#define TEXTURE_FILE_NAME "plaintex.png"
+#define CUBE_VERTICES 24
+
+//
+// Function prototypes... these are the backbone upon which the 3D app is built
+//
+void init_device(HWND hWnd);
+void render();
+void cleanup();
+void init_graphics();
+void init_lights();
+void restore_surfaces(HWND hWnd);
+
+//Direct3D makes us declare out own vertex type... we include the obvious i.e.
+// coordinates in 3 dimensions, normal vector, and U/V for texture mapping.
+struct MYVERTEXTYPE {FLOAT X, Y, Z; D3DVECTOR NORMAL; FLOAT U, V;};
+#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)
+
+// the WindowProc function prototype
+LRESULT CALLBACK
+ WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+
+// Main entry point
+int WINAPI WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
+{
+
+ WNDCLASSEX wc;
+
+ ZeroMemory(&wc, sizeof(WNDCLASSEX));
+
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.style = CS_HREDRAW | CS_VREDRAW;
+ wc.lpfnWndProc = (WNDPROC)WindowProc;
+ wc.hInstance = hInstance;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+
+ //MinGW uses 8-bit characters (ASCII) by default
+ wc.lpszClassName = "WindowClass";
+
+ RegisterClassEx(&wc);
+
+ HWND hWnd = CreateWindowEx(0, "WindowClass", "MinGW3D",
+ WS_EX_TOPMOST | WS_SYSMENU, 0, 0, APP_WIDTH,
+ APP_HEIGHT, NULL, NULL, hInstance, NULL);
+
+ ShowWindow(hWnd, nCmdShow);
+
+ // set up and initialize Direct3D
+ init_device(hWnd);
+
+ MSG msg;
+
+ //Game loop...
+ // This is basically a "Do Events" action followed by a call to "render()"
+ while(TRUE)
+ {
+ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ if (msg.message == WM_QUIT)
+ break;
+
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ render();
+
+ }
+
+ // clean up DirectX and COM
+ cleanup();
+
+ return msg.wParam;
+
+}
+
+//
+// This is the main message handler for the program
+//
+LRESULT CALLBACK WindowProc
+ (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch(message)
+ {
+ case WM_SYSCOMMAND: //screen saver... exit to allow
+ if(wParam==SC_SCREENSAVE)
+ {
+ PostQuitMessage(0);
+ return 0;
+ }
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ return 0;
+ break;
+
+ case WM_SETFOCUS:
+ restore_surfaces(hWnd);
+ break;
+
+ }
+ return DefWindowProc (hWnd, message, wParam, lParam);
+}
+
+// This function initializes and prepares Direct3D for use
+void init_device(HWND hWnd)
+{
+
+ d3d = Direct3DCreate9(D3D_SDK_VERSION);
+
+ D3DPRESENT_PARAMETERS d3dpp;
+
+ ZeroMemory(&d3dpp, sizeof(d3dpp));
+ d3dpp.Windowed = TRUE;
+ d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+ d3dpp.hDeviceWindow = hWnd;
+ d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
+ d3dpp.BackBufferWidth = APP_WIDTH;
+ d3dpp.BackBufferHeight = APP_HEIGHT;
+
+ // Device Creation
+ d3d->CreateDevice(
+ D3DADAPTER_DEFAULT,
+ D3DDEVTYPE_HAL,
+ hWnd,
+ D3DCREATE_SOFTWARE_VERTEXPROCESSING,
+ &d3dpp,
+ &device);
+
+ init_graphics();
+ init_lights();
+
+ device->SetRenderState(D3DRS_LIGHTING, TRUE); // Turn on the 3D lighting
+ device->SetRenderState(D3DRS_ZENABLE, TRUE); // Turn on the z-buffer
+
+ device->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
+
+ // ambient light
+ device->SetRenderState(D3DRS_AMBIENT,
+ D3DCOLOR_XRGB(AMBIENT_BRIGHTNESS,AMBIENT_BRIGHTNESS,AMBIENT_BRIGHTNESS));
+
+
+ // set the view transform
+ D3DXMATRIX matView; // the view transform matrix
+
+ D3DXVECTOR3 camera(0.0f, 0.0f, -CAMERA_DISTANCE);
+ D3DXVECTOR3 lookat(0.0f, 0.0f, 0.0f);
+ D3DXVECTOR3 upvector(0.0f, 1.0f, 0.0f);
+
+ D3DXMatrixLookAtLH(&matView,
+ &camera, // the camera position
+ &lookat, // the look-at position
+ &upvector); // the up direction
+
+ device->SetTransform(D3DTS_VIEW, &matView);
+
+ // This is the projection transform.. the last parameter to the call
+ // is the point in positive Z-dimension that things become invisible
+ D3DXMATRIX matProjection;
+
+ D3DXMatrixPerspectiveFovLH
+ (&matProjection,
+ D3DXToRadian(VERTICAL_VIEWFIELD_DEGREES),
+ (FLOAT)APP_WIDTH / (FLOAT)APP_HEIGHT,
+ FRUSTUM_NEAR_Z, //Defined near top of file
+ FRUSTUM_FAR_Z);
+
+ device->SetTransform(D3DTS_PROJECTION, &matProjection);
+
+ device->SetFVF(CUSTOMFVF);
+
+
+}
+
+// this is the function used to render a single frame
+void render()
+{
+
+ static float index = 0.0 ;
+
+ //Clear output buffer and vertex buffer
+ device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
+ device->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
+
+ device->BeginScene();
+
+ //
+ //Index is used to spin the main cube... a rotation of index is applied in
+ // each dimension to make things interesting
+ //
+ static float speed = CUBE_START_SPEED;
+ speed *= CUBE_ACCEL;
+
+ if(speed>CUBE_MAX_SPEED) speed=CUBE_MAX_SPEED;
+
+ index+=speed;
+
+ D3DXMATRIX matRotateX;
+
+ D3DXMatrixRotationYawPitchRoll(&matRotateX,index,index,index);
+
+ // set the world transform
+ device->SetTransform(D3DTS_WORLDMATRIX(0), &(matRotateX));
+ device->SetStreamSource(0, vertex_buffer, 0, sizeof(MYVERTEXTYPE));
+
+ device->SetTexture(0, texture_1);
+
+ device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
+ device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2);
+ device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2);
+ device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2);
+ device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 16, 2);
+ device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2);
+
+ device->EndScene();
+ device->Present(NULL, NULL, NULL, NULL) ;
+
+}
+
+// this is the function that cleans up Direct3D and COM
+void cleanup()
+{
+ RELEASE_COM_OBJECT(vertex_buffer)
+ RELEASE_COM_OBJECT(texture_1)
+ RELEASE_COM_OBJECT(device)
+ RELEASE_COM_OBJECT(d3d)
+}
+
+
+// This is the function that defines the 3D cube
+void init_graphics()
+{
+
+ D3DXCreateTextureFromFileEx(
+ device,
+ TEXTURE_FILE_NAME,
+ TEXTURE_SIZE,TEXTURE_SIZE,
+ D3DX_DEFAULT,0,D3DFMT_X8R8G8B8,D3DPOOL_MANAGED,
+ D3DX_DEFAULT,D3DX_DEFAULT,0, NULL, NULL, &texture_1
+ );
+
+
+ //
+ // This defines the shape of our single large polyhedron
+ //
+ MYVERTEXTYPE demo_vertices[] =
+ {
+ //
+ //Each of these groups-of-four is a face of our solid
+ //
+
+ { -5.0f, 5.0f, -5.0f, 0, 0, -1, 0, 0 }, // Front face
+ { 5.0f, 5.0f, -5.0f, 0, 0, -1, 1, 0 },
+ { -5.0f, -5.0f, -5.0f, 0, 0, -1, 0, 1 },
+ { 5.0f, -5.0f, -5.0f, 0, 0, -1, 1, 1 },
+
+ { 5.0f, 5.0f, 5.0f, 0, 0, 1, 0, 0 }, // Back face
+ { -5.0f, 5.0f, 5.0f, 0, 0, 1, 1, 0 },
+ { 5.0f, -5.0f, 5.0f, 0, 0, 1, 0, 1 },
+ { -5.0f, -5.0f, 5.0f, 0, 0, 1, 1, 1 },
+
+ { -5.0f, 5.0f, 5.0f, 0, 1, 0, 0, 0 }, // Top face
+ { 5.0f, 5.0f, 5.0f, 0, 1, 0, 1, 0 },
+ { -5.0f, 5.0f, -5.0f, 0, 1, 0, 0, 1 },
+ { 5.0f, 5.0f, -5.0f, 0, 1, 0, 1, 1 },
+
+ { 5.0f, 5.0f, -5.0f, 1, 0, 0, 0, 0 }, // Right face
+ { 5.0f, 5.0f, 5.0f, 1, 0, 0, 1, 0 },
+ { 5.0f, -5.0f, -5.0f, 1, 0, 0, 0, 1 },
+ { 5.0f, -5.0f, 5.0f, 1, 0, 0, 1, 1 },
+
+ { -5.0f, -5.0f, -5.0f, 0, -1, 0, 0, 0 }, //Bottom face
+ { 5.0f, -5.0f, -5.0f, 0, -1, 0, 1, 0 },
+ { -5.0f, -5.0f, 5.0f, 0, -1, 0, 0, 1 },
+ { 5.0f, -5.0f, 5.0f, 0, -1, 0, 1, 1 },
+
+ { -5.0f, 5.0f, 5.0f, -1, 0, 0, 0, 0 }, //Left face
+ { -5.0f, 5.0f, -5.0f, -1, 0, 0, 1, 0 },
+ { -5.0f, -5.0f, 5.0f, -1, 0, 0, 0, 1 },
+ { -5.0f, -5.0f, -5.0f, -1, 0, 0, 1, 1 },
+
+ };
+
+ // COM creation of vertex buffer
+ device->CreateVertexBuffer(
+ CUBE_VERTICES*sizeof(MYVERTEXTYPE), //Cube has 24 vertices
+ 0,
+ CUSTOMFVF,
+ D3DPOOL_MANAGED,
+ &vertex_buffer,
+ NULL);
+
+ VOID* pVoid; // a void pointer
+
+ // Lock vertex_buffer and load the vertices into it
+ vertex_buffer->Lock(0, 0, (void**)&pVoid, 0);
+ memcpy(pVoid, demo_vertices, sizeof(demo_vertices));
+ vertex_buffer->Unlock();
+
+}
+
+// Gets called after we leave then return to this program; handled by
+// throwing away our old COM objects and re-doing initialization
+void restore_surfaces(HWND hWnd)
+{
+ cleanup();
+ init_device(hWnd);
+}
+
+// Sets up the lights and "material" parameter
+void init_lights()
+{
+
+ D3DMATERIAL9 material;
+
+ D3DVECTOR look = {0.00f, 0.0f, 1.0f}; // the direction of the light
+
+ // the location of the light
+ D3DVECTOR at = {0.0f, 0.0f, -LIGHT_DISTANCE};
+
+ D3DLIGHT9 flashlight;
+ ZeroMemory(&flashlight, sizeof(D3DLIGHT9));
+
+ flashlight.Type = D3DLIGHT_SPOT;
+ flashlight.Diffuse.r = flashlight.Ambient.r = 1.0f; //1.0 = max value
+ flashlight.Diffuse.g = flashlight.Ambient.g = 1.0f;
+ flashlight.Diffuse.b = flashlight.Ambient.b = 1.0f;
+ flashlight.Diffuse.a = flashlight.Ambient.a = 1.0f;
+ flashlight.Range = LIGHT_RANGE;
+ flashlight.Position = at;
+ flashlight.Direction = look;
+ flashlight.Phi = LIGHT_CONE_RADIANS_OUTER;
+ flashlight.Theta = LIGHT_CONE_RADIANS_INNER;
+ flashlight.Attenuation0 = 0.0f; //Constant attenuation
+ flashlight.Attenuation1 = 0.01f; //Linear attenuation
+ flashlight.Attenuation2 = 0.0f; //Quadratic attenuation
+ flashlight.Falloff = 1.0f; //Microsoft recommends linear falloff
+ device->SetLight(0, &flashlight);
+ device->LightEnable(0, TRUE);
+ ZeroMemory(&material, sizeof(D3DMATERIAL9));
+ material.Diffuse.r = material.Ambient.r = 1.0f;
+ material.Diffuse.g = material.Ambient.g = 1.0f;
+ material.Diffuse.b = material.Ambient.b = 1.0f;
+ material.Diffuse.a = material.Ambient.a = 1.0f;
+ device->SetMaterial(&material);
+
+}