Index: ddraw/common.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2012 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -16,8 +16,8 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #pragma once
|
20 | | -#ifndef _STDAFX_H
|
21 | | -#define _STDAFX_H
|
| 20 | +#ifndef _COMMON_H
|
| 21 | +#define _COMMON_H
|
22 | 22 |
|
23 | 23 | #define WIN32_LEAN_AND_MEAN
|
24 | 24 | #include <windows.h>
|
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | #include <MMSystem.h>
|
27 | 27 | #include "include/winedef.h"
|
28 | 28 | #include <ddraw.h>
|
| 29 | +#define D3D_OVERLOADS
|
29 | 30 | #include "include/d3d.h"
|
30 | 31 | #include "GL/gl.h"
|
31 | 32 | #include "include/GL/glext.h"
|
— | — | @@ -77,4 +78,4 @@ |
78 | 79 | #define ERR(error) return error;
|
79 | 80 | #endif
|
80 | 81 | #include "../cfgmgr/cfgmgr.h"
|
81 | | -#endif //_STDAFX_H
|
| 82 | +#endif //_COMMON_H
|
Index: ddraw/ddraw.vcxproj |
— | — | @@ -165,6 +165,7 @@ |
166 | 166 | <ClInclude Include="glClassFactory.h" />
|
167 | 167 | <ClInclude Include="glDirect3D.h" />
|
168 | 168 | <ClInclude Include="glDirect3DDevice.h" />
|
| 169 | + <ClInclude Include="glDirect3DLight.h" />
|
169 | 170 | <ClInclude Include="glDirectDraw.h" />
|
170 | 171 | <ClInclude Include="glDirectDrawClipper.h" />
|
171 | 172 | <ClInclude Include="glDirectDrawPalette.h" />
|
— | — | @@ -204,6 +205,7 @@ |
205 | 206 | </ClCompile>
|
206 | 207 | <ClCompile Include="glDirect3D.cpp" />
|
207 | 208 | <ClCompile Include="glDirect3DDevice.cpp" />
|
| 209 | + <ClCompile Include="glDirect3DLight.cpp" />
|
208 | 210 | <ClCompile Include="glDirectDraw.cpp" />
|
209 | 211 | <ClCompile Include="glDirectDrawClipper.cpp" />
|
210 | 212 | <ClCompile Include="glDirectDrawPalette.cpp" />
|
Index: ddraw/ddraw.vcxproj.filters |
— | — | @@ -83,6 +83,9 @@ |
84 | 84 | <ClInclude Include="glDirect3DDevice.h">
|
85 | 85 | <Filter>Header Files</Filter>
|
86 | 86 | </ClInclude>
|
| 87 | + <ClInclude Include="glDirect3DLight.h">
|
| 88 | + <Filter>Header Files</Filter>
|
| 89 | + </ClInclude>
|
87 | 90 | </ItemGroup>
|
88 | 91 | <ItemGroup>
|
89 | 92 | <ClCompile Include="ddraw.cpp">
|
— | — | @@ -127,6 +130,9 @@ |
128 | 131 | <ClCompile Include="glDirect3DDevice.cpp">
|
129 | 132 | <Filter>Source Files</Filter>
|
130 | 133 | </ClCompile>
|
| 134 | + <ClCompile Include="glDirect3DLight.cpp">
|
| 135 | + <Filter>Source Files</Filter>
|
| 136 | + </ClCompile>
|
131 | 137 | </ItemGroup>
|
132 | 138 | <ItemGroup>
|
133 | 139 | <ResourceCompile Include="ddraw.rc">
|
Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2012 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -19,8 +19,8 @@ |
20 | 20 | #include "glDirect3D.h"
|
21 | 21 | #include "glDirectDrawSurface.h"
|
22 | 22 | #include "glDirect3DDevice.h"
|
| 23 | +#include "glDirect3DLight.h"
|
23 | 24 |
|
24 | | -
|
25 | 25 | const DWORD renderstate_default[153] = {0, // 0
|
26 | 26 | NULL, //texturehandle
|
27 | 27 | D3DANTIALIAS_NONE, //antialias
|
— | — | @@ -132,6 +132,10 @@ |
133 | 133 | glEnable(GL_LIGHTING);
|
134 | 134 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);
|
135 | 135 | ZeroMemory(&material,sizeof(D3DMATERIAL7));
|
| 136 | + lightsmax = 16;
|
| 137 | + lights = (glDirect3DLight**) malloc(16*sizeof(glDirect3DLight*));
|
| 138 | + ZeroMemory(lights,16*sizeof(glDirect3DLight*));
|
| 139 | + memset(gllights,0xff,8*sizeof(int));
|
136 | 140 |
|
137 | 141 | }
|
138 | 142 | glDirect3DDevice7::~glDirect3DDevice7()
|
— | — | @@ -140,6 +144,18 @@ |
141 | 145 | glDDS7->Release();
|
142 | 146 | }
|
143 | 147 |
|
| 148 | +int ExpandLightBuffer(glDirect3DLight ***lights, DWORD *maxlights, DWORD newmax)
|
| 149 | +{
|
| 150 | + if(newmax < *maxlights) return 1;
|
| 151 | + glDirect3DLight **tmp = (glDirect3DLight**)realloc(*lights,newmax*sizeof(glDirect3DLight*));
|
| 152 | + if(!tmp) return 0;
|
| 153 | + *lights = tmp;
|
| 154 | + for(DWORD i = *maxlights; i < newmax; i++)
|
| 155 | + lights[i] = NULL;
|
| 156 | + *maxlights = newmax;
|
| 157 | + return 1;
|
| 158 | +}
|
| 159 | +
|
144 | 160 | HRESULT WINAPI glDirect3DDevice7::QueryInterface(REFIID riid, void** ppvObj)
|
145 | 161 | {
|
146 | 162 | ERR(E_NOINTERFACE);
|
— | — | @@ -333,6 +349,30 @@ |
334 | 350 | }
|
335 | 351 | HRESULT WINAPI glDirect3DDevice7::LightEnable(DWORD dwLightIndex, BOOL bEnable)
|
336 | 352 | {
|
| 353 | + int i;
|
| 354 | + D3DLIGHT7 light;
|
| 355 | + bool foundlight = false;
|
| 356 | + if(dwLightIndex >= lightsmax)
|
| 357 | + {
|
| 358 | + if(!ExpandLightBuffer(&lights,&lightsmax,dwLightIndex-1)) return DDERR_OUTOFMEMORY;
|
| 359 | + }
|
| 360 | + if(!lights[dwLightIndex]) lights[dwLightIndex] = new glDirect3DLight;
|
| 361 | + if(bEnable)
|
| 362 | + {
|
| 363 | + for(i = 0; i < 8; i++)
|
| 364 | + if(gllights[i] == dwLightIndex) return D3D_OK;
|
| 365 | + for(i = 0; i < 8; i++)
|
| 366 | + {
|
| 367 | + if(gllights[i] == -1)
|
| 368 | + {
|
| 369 | + foundlight = true;
|
| 370 | + gllights[i] = dwLightIndex;
|
| 371 | + break;
|
| 372 | + }
|
| 373 | + }
|
| 374 | + if(!foundlight) return D3DERR_LIGHT_SET_FAILED;
|
| 375 | + lights[dwLightIndex]->SetGLLight(i);
|
| 376 | + }
|
337 | 377 | FIXME("glDirect3DDevice7::LightEnable: stub");
|
338 | 378 | ERR(DDERR_GENERIC);
|
339 | 379 | }
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2012 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | #ifndef __GLDIRECT3DDEVICE_H
|
21 | 21 | #define __GLDIRECT3DDEVICE_H
|
22 | 22 |
|
| 23 | +class glDirect3DLight;
|
23 | 24 | class glDirectDrawSurface7;
|
24 | 25 | class glDirect3DDevice7 : public IDirect3DDevice7
|
25 | 26 | {
|
— | — | @@ -92,6 +93,9 @@ |
93 | 94 | D3DVIEWPORT7 viewport;
|
94 | 95 | DWORD renderstate[153];
|
95 | 96 | D3DMATERIAL7 material;
|
| 97 | + glDirect3DLight **lights;
|
| 98 | + int gllights[8];
|
| 99 | + DWORD lightsmax;
|
96 | 100 | };
|
97 | 101 |
|
98 | 102 | #endif //__GLDIRECT3DDEVICE_H |
\ No newline at end of file |
Index: ddraw/glDirect3DLight.cpp |
— | — | @@ -0,0 +1,122 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2012 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library is distributed in the hope that it will be useful,
|
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#include "common.h"
|
| 20 | +#include "glDirect3DLight.h"
|
| 21 | +#define _USE_MATH_DEFINES
|
| 22 | +#include <math.h>
|
| 23 | +
|
| 24 | +
|
| 25 | +
|
| 26 | +glDirect3DLight::glDirect3DLight()
|
| 27 | +{
|
| 28 | + refcount=1;
|
| 29 | + gllight = -1;
|
| 30 | + ZeroMemory(&light,sizeof(D3DLIGHT7));
|
| 31 | + light.dltType = D3DLIGHT_DIRECTIONAL;
|
| 32 | + light.dcvAmbient.r = light.dcvAmbient.g = light.dcvAmbient.b = 1.0f;
|
| 33 | + light.dvDirection = D3DVECTOR(0,0,1.0);
|
| 34 | +}
|
| 35 | +glDirect3DLight::glDirect3DLight(D3DLIGHT7 *light_in)
|
| 36 | +{
|
| 37 | + refcount=1;
|
| 38 | + gllight = -1;
|
| 39 | + memcpy(&light,light_in,sizeof(D3DLIGHT7));
|
| 40 | +}
|
| 41 | +
|
| 42 | +glDirect3DLight::~glDirect3DLight()
|
| 43 | +{
|
| 44 | + if(gllight != -1)
|
| 45 | + glDisable(GL_LIGHT0+gllight);
|
| 46 | +}
|
| 47 | +
|
| 48 | +ULONG WINAPI glDirect3DLight::AddRef()
|
| 49 | +{
|
| 50 | + refcount++;
|
| 51 | + return refcount;
|
| 52 | +}
|
| 53 | +ULONG WINAPI glDirect3DLight::Release()
|
| 54 | +{
|
| 55 | + ULONG ret;
|
| 56 | + refcount--;
|
| 57 | + ret = refcount;
|
| 58 | + if(refcount == 0) delete this;
|
| 59 | + return ret;
|
| 60 | +}
|
| 61 | +
|
| 62 | +HRESULT WINAPI glDirect3DLight::Initialize(LPDIRECT3D lpDirect3D)
|
| 63 | +{
|
| 64 | + return DDERR_ALREADYINITIALIZED;
|
| 65 | +}
|
| 66 | +
|
| 67 | +HRESULT WINAPI glDirect3DLight::QueryInterface(REFIID riid, void** ppvObj)
|
| 68 | +{
|
| 69 | + return E_NOINTERFACE;
|
| 70 | +}
|
| 71 | +
|
| 72 | +void glDirect3DLight::GetLight7(LPD3DLIGHT7 lpLight7)
|
| 73 | +{
|
| 74 | + memcpy(lpLight7,&light,sizeof(D3DLIGHT7));
|
| 75 | +}
|
| 76 | +void glDirect3DLight::SetLight7(LPD3DLIGHT7 lpLight7)
|
| 77 | +{
|
| 78 | + memcpy(&light,lpLight7,sizeof(D3DLIGHT7));
|
| 79 | +}
|
| 80 | +
|
| 81 | +HRESULT WINAPI glDirect3DLight::GetLight(LPD3DLIGHT lpLight)
|
| 82 | +{
|
| 83 | + FIXME("glDirect3DLight::GetLight: stub");
|
| 84 | + ERR(DDERR_GENERIC);
|
| 85 | +}
|
| 86 | +HRESULT WINAPI glDirect3DLight::SetLight(LPD3DLIGHT lpLight)
|
| 87 | +{
|
| 88 | + FIXME("glDirect3DLight::SetLight: stub");
|
| 89 | + ERR(DDERR_GENERIC);
|
| 90 | +}
|
| 91 | +
|
| 92 | +void glDirect3DLight::SetGLLight(int gllightin)
|
| 93 | +{
|
| 94 | + const float angle_dx_gl = 90.0f / (float)M_PI;
|
| 95 | + if(gllightin != -1)
|
| 96 | + {
|
| 97 | + if(gllightin != gllight) glDisable(GL_LIGHT0+gllight);
|
| 98 | + GLfloat ambient[] = {light.dcvAmbient.r,light.dcvAmbient.g,light.dcvAmbient.b,light.dcvAmbient.a};
|
| 99 | + glLightfv(GL_LIGHT0+gllightin,GL_AMBIENT,ambient);
|
| 100 | + GLfloat diffuse[] = {light.dcvDiffuse.r,light.dcvDiffuse.g,light.dcvDiffuse.b,light.dcvDiffuse.a};
|
| 101 | + glLightfv(GL_LIGHT0+gllightin,GL_DIFFUSE,diffuse);
|
| 102 | + GLfloat specular[] = {light.dcvSpecular.r,light.dcvSpecular.g,light.dcvSpecular.b,light.dcvSpecular.a};
|
| 103 | + glLightfv(GL_LIGHT0+gllightin,GL_DIFFUSE,specular);
|
| 104 | + if(light.dltType == D3DLIGHT_DIRECTIONAL)
|
| 105 | + GLfloat position[] = {light.dvPosition.x,light.dvPosition.y,light.dvPosition.z,0.};
|
| 106 | + else GLfloat position[] = {light.dvPosition.x,light.dvPosition.y,light.dvPosition.z,1.};
|
| 107 | + glLightfv(GL_LIGHT0+gllightin,GL_POSITION,specular);
|
| 108 | + GLfloat direction[] = {light.dvDirection.x,light.dvDirection.y,light.dvDirection.z};
|
| 109 | + glLightfv(GL_LIGHT0+gllightin,GL_SPOT_DIRECTION,specular);
|
| 110 | + if(light.dltType == D3DLIGHT_SPOT)
|
| 111 | + glLightf(GL_LIGHT0+gllightin,GL_SPOT_CUTOFF,angle_dx_gl*light.dvPhi);
|
| 112 | + else glLightf(GL_LIGHT0+gllightin,GL_SPOT_CUTOFF,180.0);
|
| 113 | + glLightf(GL_LIGHT0+gllightin,GL_CONSTANT_ATTENUATION,light.dvAttenuation0);
|
| 114 | + glLightf(GL_LIGHT0+gllightin,GL_LINEAR_ATTENUATION,light.dvAttenuation1);
|
| 115 | + glLightf(GL_LIGHT0+gllightin,GL_QUADRATIC_ATTENUATION,light.dvAttenuation2);
|
| 116 | + glEnable(GL_LIGHT0+gllightin);
|
| 117 | + }
|
| 118 | + else
|
| 119 | + {
|
| 120 | + glDisable(GL_LIGHT0+gllightin);
|
| 121 | + }
|
| 122 | + gllight = gllightin;
|
| 123 | +} |
\ No newline at end of file |
Index: ddraw/glDirect3DLight.h |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2012 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library is distributed in the hope that it will be useful,
|
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#pragma once
|
| 20 | +#ifndef __GLDIRECT3DLIGHT_H
|
| 21 | +#define __GLDIRECT3DLIGHT_H
|
| 22 | +
|
| 23 | +class glDirect3DLight : public IDirect3DLight
|
| 24 | +{
|
| 25 | +public:
|
| 26 | + glDirect3DLight();
|
| 27 | + glDirect3DLight(D3DLIGHT7 *light_in);
|
| 28 | + virtual ~glDirect3DLight();
|
| 29 | +
|
| 30 | + HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
|
| 31 | + ULONG WINAPI AddRef();
|
| 32 | + ULONG WINAPI Release();
|
| 33 | + HRESULT WINAPI GetLight(LPD3DLIGHT lpLight);
|
| 34 | + void GetLight7(LPD3DLIGHT7 lpLight7);
|
| 35 | + HRESULT WINAPI Initialize(LPDIRECT3D lpDirect3D);
|
| 36 | + HRESULT WINAPI SetLight(LPD3DLIGHT lpLight);
|
| 37 | + void SetLight7(LPD3DLIGHT7 lpLight7);
|
| 38 | + void SetGLLight(int gllightin);
|
| 39 | + void GetGLLight(int *gllightout){*gllightout=gllight;};
|
| 40 | + D3DLIGHT7 light;
|
| 41 | +private:
|
| 42 | + ULONG refcount;
|
| 43 | + D3DLIGHT2 convert;
|
| 44 | + int gllight;
|
| 45 | +};
|
| 46 | +
|
| 47 | +#endif //__GLDIRECT3DLIGHT_H |
\ No newline at end of file |
Index: dxgltest/common.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2012 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -16,8 +16,8 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #pragma once
|
20 | | -#ifndef _STDAFX_H
|
21 | | -#define _STDAFX_H
|
| 20 | +#ifndef _COMMON_H
|
| 21 | +#define _COMMON_H
|
22 | 22 |
|
23 | 23 | #define _CRT_SECURE_NO_WARNINGS
|
24 | 24 |
|
— | — | @@ -60,4 +60,4 @@ |
61 | 61 | // DirectX/DXGL headers
|
62 | 62 | #include <ddraw.h>
|
63 | 63 | extern const unsigned char DefaultPalette[1024];
|
64 | | -#endif //_STDAFX_H
|
| 64 | +#endif //_COMMON_H
|