ReactOS 0.4.17-dev-934-g091855f
d3dx9shape.h File Reference
#include "d3dx9.h"
Include dependency graph for d3dx9shape.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define D3DXCreateText   WINELIB_NAME_AW(D3DXCreateText)
 

Functions

HRESULT WINAPI D3DXCreateBox (struct IDirect3DDevice9 *device, float width, float height, float depth, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateCylinder (struct IDirect3DDevice9 *device, float radius1, float radius2, float length, UINT slices, UINT stacks, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreatePolygon (struct IDirect3DDevice9 *device, float length, UINT sides, struct ID3DXMesh **mesh, ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateSphere (struct IDirect3DDevice9 *device, float radius, UINT slices, UINT stacks, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateTeapot (struct IDirect3DDevice9 *device, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateTextA (struct IDirect3DDevice9 *device, HDC hdc, const char *text, float deviation, float extrusion, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
 
HRESULT WINAPI D3DXCreateTextW (struct IDirect3DDevice9 *device, HDC hdc, const WCHAR *text, float deviation, FLOAT extrusion, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
 
HRESULT WINAPI D3DXCreateTorus (struct IDirect3DDevice9 *device, float innerradius, float outerradius, UINT sides, UINT rings, struct ID3DXMesh **mesh, ID3DXBuffer **adjacency)
 

Macro Definition Documentation

◆ D3DXCreateText

#define D3DXCreateText   WINELIB_NAME_AW(D3DXCreateText)

Definition at line 44 of file d3dx9shape.h.

Function Documentation

◆ D3DXCreateBox()

HRESULT WINAPI D3DXCreateBox ( struct IDirect3DDevice9 *  device,
float  width,
float  height,
float  depth,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 4760 of file mesh.c.

4762{
4763 HRESULT hr;
4764 ID3DXMesh *box;
4765 struct vertex *vertices;
4766 WORD (*faces)[3];
4767 DWORD *adjacency_buf;
4768 unsigned int i, face;
4769 static const D3DXVECTOR3 unit_box[] =
4770 {
4771 {-0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, 0.5f}, {-0.5f, 0.5f, 0.5f}, {-0.5f, 0.5f, -0.5f},
4772 {-0.5f, 0.5f, -0.5f}, {-0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, -0.5f},
4773 { 0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f}, { 0.5f, -0.5f, 0.5f}, { 0.5f, -0.5f, -0.5f},
4774 {-0.5f, -0.5f, 0.5f}, {-0.5f, -0.5f, -0.5f}, { 0.5f, -0.5f, -0.5f}, { 0.5f, -0.5f, 0.5f},
4775 {-0.5f, -0.5f, 0.5f}, { 0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f}, {-0.5f, 0.5f, 0.5f},
4776 {-0.5f, -0.5f, -0.5f}, {-0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, -0.5f}, { 0.5f, -0.5f, -0.5f}
4777 };
4778 static const D3DXVECTOR3 normals[] =
4779 {
4780 {-1.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, { 1.0f, 0.0f, 0.0f},
4781 { 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, -1.0f}
4782 };
4783 static const DWORD adjacency_table[] =
4784 {
4785 6, 9, 1, 2, 10, 0, 1, 9, 3, 4, 10, 2,
4786 3, 8, 5, 7, 11, 4, 0, 11, 7, 5, 8, 6,
4787 7, 4, 9, 2, 0, 8, 1, 3, 11, 5, 6, 10
4788 };
4789
4790 TRACE("device %p, width %f, height %f, depth %f, mesh %p, adjacency %p\n",
4791 device, width, height, depth, mesh, adjacency);
4792
4793 if (!device || width < 0.0f || height < 0.0f || depth < 0.0f || !mesh)
4794 {
4795 return D3DERR_INVALIDCALL;
4796 }
4797
4799 {
4800 return hr;
4801 }
4802
4803 if (FAILED(hr = box->lpVtbl->LockVertexBuffer(box, 0, (void **)&vertices)))
4804 {
4805 box->lpVtbl->Release(box);
4806 return hr;
4807 }
4808
4809 if (FAILED(hr = box->lpVtbl->LockIndexBuffer(box, 0, (void **)&faces)))
4810 {
4811 box->lpVtbl->UnlockVertexBuffer(box);
4812 box->lpVtbl->Release(box);
4813 return hr;
4814 }
4815
4816 for (i = 0; i < 24; i++)
4817 {
4818 vertices[i].position.x = width * unit_box[i].x;
4819 vertices[i].position.y = height * unit_box[i].y;
4820 vertices[i].position.z = depth * unit_box[i].z;
4821 vertices[i].normal.x = normals[i / 4].x;
4822 vertices[i].normal.y = normals[i / 4].y;
4823 vertices[i].normal.z = normals[i / 4].z;
4824 }
4825
4826 face = 0;
4827 for (i = 0; i < 12; i++)
4828 {
4829 faces[i][0] = face++;
4830 faces[i][1] = face++;
4831 faces[i][2] = (i % 2) ? face - 4 : face;
4832 }
4833
4834 box->lpVtbl->UnlockIndexBuffer(box);
4835 box->lpVtbl->UnlockVertexBuffer(box);
4836
4837 if (adjacency)
4838 {
4839 if (FAILED(hr = D3DXCreateBuffer(sizeof(adjacency_table), adjacency)))
4840 {
4841 box->lpVtbl->Release(box);
4842 return hr;
4843 }
4844
4845 adjacency_buf = ID3DXBuffer_GetBufferPointer(*adjacency);
4846 memcpy(adjacency_buf, adjacency_table, sizeof(adjacency_table));
4847 }
4848
4849 *mesh = box;
4850
4851 return D3D_OK;
4852}
#define D3DERR_INVALIDCALL
Definition: d3d10_private.h:42
#define D3DFVF_XYZ
Definition: d3d8types.h:113
#define D3DFVF_NORMAL
Definition: d3d8types.h:120
#define D3D_OK
Definition: d3d.h:106
HRESULT hr
Definition: delayimp.cpp:582
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
Definition: core.c:127
HRESULT WINAPI D3DXCreateMeshFVF(DWORD face_count, DWORD vertex_count, DWORD options, DWORD fvf, struct IDirect3DDevice9 *device, struct ID3DXMesh **mesh)
Definition: mesh.c:2577
WORD face[3]
Definition: mesh.c:4854
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
@ D3DXMESH_MANAGED
Definition: d3dx9mesh.h:64
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FAILED(hr)
Definition: intsafe.h:51
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define TRACE(s)
Definition: solgame.cpp:4
Definition: palette.c:466
Definition: devices.h:37
Definition: mesh.c:189
Definition: mesh.c:4665

Referenced by D3DXCreateBoxTest(), test_box(), and test_compute_normals().

◆ D3DXCreateCylinder()

HRESULT WINAPI D3DXCreateCylinder ( struct IDirect3DDevice9 *  device,
float  radius1,
float  radius2,
float  length,
UINT  slices,
UINT  stacks,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 5082 of file mesh.c.

5084{
5085 DWORD number_of_vertices, number_of_faces;
5086 HRESULT hr;
5087 ID3DXMesh *cylinder;
5088 struct vertex *vertices;
5089 face *faces;
5090 float theta_step, theta_start;
5091 struct sincos_table theta;
5092 float delta_radius, radius, radius_step;
5093 float z, z_step, z_normal;
5095
5096 TRACE("(%p, %f, %f, %f, %u, %u, %p, %p)\n", device, radius1, radius2, length, slices, stacks, mesh, adjacency);
5097
5098 if (device == NULL || radius1 < 0.0f || radius2 < 0.0f || length < 0.0f || slices < 2 || stacks < 1 || mesh == NULL)
5099 {
5100 return D3DERR_INVALIDCALL;
5101 }
5102
5103 number_of_vertices = 2 + (slices * (3 + stacks));
5104 number_of_faces = 2 * slices + stacks * (2 * slices);
5105
5106 hr = D3DXCreateMeshFVF(number_of_faces, number_of_vertices, D3DXMESH_MANAGED,
5108 if (FAILED(hr))
5109 {
5110 return hr;
5111 }
5112
5113 if (FAILED(hr = cylinder->lpVtbl->LockVertexBuffer(cylinder, 0, (void **)&vertices)))
5114 {
5115 cylinder->lpVtbl->Release(cylinder);
5116 return hr;
5117 }
5118
5119 if (FAILED(hr = cylinder->lpVtbl->LockIndexBuffer(cylinder, 0, (void **)&faces)))
5120 {
5121 cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
5122 cylinder->lpVtbl->Release(cylinder);
5123 return hr;
5124 }
5125
5126 /* theta = angle on xy plane wrt x axis */
5127 theta_step = -2.0f * D3DX_PI / slices;
5128 theta_start = D3DX_PI / 2.0f;
5129
5130 if (!compute_sincos_table(&theta, theta_start, theta_step, slices))
5131 {
5132 cylinder->lpVtbl->UnlockIndexBuffer(cylinder);
5133 cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
5134 cylinder->lpVtbl->Release(cylinder);
5135 return E_OUTOFMEMORY;
5136 }
5137
5138 vertex = 0;
5139 face = 0;
5140
5141 delta_radius = radius1 - radius2;
5142 radius = radius1;
5143 radius_step = delta_radius / stacks;
5144
5145 z = -length / 2;
5146 z_step = length / stacks;
5147 z_normal = delta_radius / length;
5148 if (isnan(z_normal))
5149 {
5150 z_normal = 0.0f;
5151 }
5152
5153 vertices[vertex].normal.x = 0.0f;
5154 vertices[vertex].normal.y = 0.0f;
5155 vertices[vertex].normal.z = -1.0f;
5156 vertices[vertex].position.x = 0.0f;
5157 vertices[vertex].position.y = 0.0f;
5158 vertices[vertex++].position.z = z;
5159
5160 for (slice = 0; slice < slices; slice++, vertex++)
5161 {
5162 vertices[vertex].normal.x = 0.0f;
5163 vertices[vertex].normal.y = 0.0f;
5164 vertices[vertex].normal.z = -1.0f;
5165 vertices[vertex].position.x = radius * theta.cos[slice];
5166 vertices[vertex].position.y = radius * theta.sin[slice];
5167 vertices[vertex].position.z = z;
5168
5169 if (slice > 0)
5170 {
5171 faces[face][0] = 0;
5172 faces[face][1] = slice;
5173 faces[face++][2] = slice + 1;
5174 }
5175 }
5176
5177 faces[face][0] = 0;
5178 faces[face][1] = slice;
5179 faces[face++][2] = 1;
5180
5181 for (stack = 1; stack <= stacks+1; stack++)
5182 {
5183 for (slice = 0; slice < slices; slice++, vertex++)
5184 {
5185 vertices[vertex].normal.x = theta.cos[slice];
5186 vertices[vertex].normal.y = theta.sin[slice];
5187 vertices[vertex].normal.z = z_normal;
5188 D3DXVec3Normalize(&vertices[vertex].normal, &vertices[vertex].normal);
5189 vertices[vertex].position.x = radius * theta.cos[slice];
5190 vertices[vertex].position.y = radius * theta.sin[slice];
5191 vertices[vertex].position.z = z;
5192
5193 if (stack > 1 && slice > 0)
5194 {
5195 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5196 faces[face][1] = vertex_index(slices, slice-1, stack);
5197 faces[face++][2] = vertex_index(slices, slice, stack-1);
5198
5199 faces[face][0] = vertex_index(slices, slice, stack-1);
5200 faces[face][1] = vertex_index(slices, slice-1, stack);
5201 faces[face++][2] = vertex_index(slices, slice, stack);
5202 }
5203 }
5204
5205 if (stack > 1)
5206 {
5207 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5208 faces[face][1] = vertex_index(slices, slice-1, stack);
5209 faces[face++][2] = vertex_index(slices, 0, stack-1);
5210
5211 faces[face][0] = vertex_index(slices, 0, stack-1);
5212 faces[face][1] = vertex_index(slices, slice-1, stack);
5213 faces[face++][2] = vertex_index(slices, 0, stack);
5214 }
5215
5216 if (stack < stacks + 1)
5217 {
5218 z += z_step;
5219 radius -= radius_step;
5220 }
5221 }
5222
5223 for (slice = 0; slice < slices; slice++, vertex++)
5224 {
5225 vertices[vertex].normal.x = 0.0f;
5226 vertices[vertex].normal.y = 0.0f;
5227 vertices[vertex].normal.z = 1.0f;
5228 vertices[vertex].position.x = radius * theta.cos[slice];
5229 vertices[vertex].position.y = radius * theta.sin[slice];
5230 vertices[vertex].position.z = z;
5231
5232 if (slice > 0)
5233 {
5234 faces[face][0] = vertex_index(slices, slice-1, stack);
5235 faces[face][1] = number_of_vertices - 1;
5236 faces[face++][2] = vertex_index(slices, slice, stack);
5237 }
5238 }
5239
5240 vertices[vertex].position.x = 0.0f;
5241 vertices[vertex].position.y = 0.0f;
5242 vertices[vertex].position.z = z;
5243 vertices[vertex].normal.x = 0.0f;
5244 vertices[vertex].normal.y = 0.0f;
5245 vertices[vertex].normal.z = 1.0f;
5246
5247 faces[face][0] = vertex_index(slices, slice-1, stack);
5248 faces[face][1] = number_of_vertices - 1;
5249 faces[face][2] = vertex_index(slices, 0, stack);
5250
5251 free_sincos_table(&theta);
5252 cylinder->lpVtbl->UnlockIndexBuffer(cylinder);
5253 cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
5254
5255 if (adjacency)
5256 {
5257 if (FAILED(hr = D3DXCreateBuffer(number_of_faces * sizeof(DWORD) * 3, adjacency)))
5258 {
5259 cylinder->lpVtbl->Release(cylinder);
5260 return hr;
5261 }
5262
5263 if (FAILED(hr = cylinder->lpVtbl->GenerateAdjacency(cylinder, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
5264 {
5265 (*adjacency)->lpVtbl->Release(*adjacency);
5266 cylinder->lpVtbl->Release(cylinder);
5267 return hr;
5268 }
5269 }
5270
5271 *mesh = cylinder;
5272
5273 return D3D_OK;
5274}
GLUquadricObj * cylinder
Definition: cylfrac.c:44
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
D3DXVECTOR3 *WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout, const D3DXVECTOR3 *pv)
Definition: math.c:1805
static void free_sincos_table(struct sincos_table *sincos_table)
Definition: mesh.c:4862
static BOOL compute_sincos_table(struct sincos_table *sincos_table, float angle_start, float angle_step, int n)
Definition: mesh.c:4869
static WORD vertex_index(UINT slices, int slice, int stack)
Definition: mesh.c:4897
#define isnan(x)
Definition: math.h:360
#define D3DX_PI
Definition: d3dx9math.h:27
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLdouble GLdouble z
Definition: glext.h:5874
ULONG Release()
@ normal
Definition: optimize.h:166
Definition: format.c:80

Referenced by D3DXCreateCylinderTest(), and test_cylinder().

◆ D3DXCreatePolygon()

HRESULT WINAPI D3DXCreatePolygon ( struct IDirect3DDevice9 *  device,
float  length,
UINT  sides,
struct ID3DXMesh **  mesh,
ID3DXBuffer **  adjacency 
)

Definition at line 4670 of file mesh.c.

4672{
4673 HRESULT hr;
4674 ID3DXMesh *polygon;
4675 struct vertex *vertices;
4676 WORD (*faces)[3];
4677 DWORD (*adjacency_buf)[3];
4678 float angle, scale;
4679 unsigned int i;
4680
4681 TRACE("device %p, length %f, sides %u, mesh %p, adjacency %p.\n",
4682 device, length, sides, mesh, adjacency);
4683
4684 if (!device || length < 0.0f || sides < 3 || !mesh)
4685 return D3DERR_INVALIDCALL;
4686
4687 if (FAILED(hr = D3DXCreateMeshFVF(sides, sides + 1, D3DXMESH_MANAGED,
4688 D3DFVF_XYZ | D3DFVF_NORMAL, device, &polygon)))
4689 {
4690 return hr;
4691 }
4692
4693 if (FAILED(hr = polygon->lpVtbl->LockVertexBuffer(polygon, 0, (void **)&vertices)))
4694 {
4695 polygon->lpVtbl->Release(polygon);
4696 return hr;
4697 }
4698
4699 if (FAILED(hr = polygon->lpVtbl->LockIndexBuffer(polygon, 0, (void **)&faces)))
4700 {
4701 polygon->lpVtbl->UnlockVertexBuffer(polygon);
4702 polygon->lpVtbl->Release(polygon);
4703 return hr;
4704 }
4705
4706 angle = D3DX_PI / sides;
4707 scale = 0.5f * length / sinf(angle);
4708 angle *= 2.0f;
4709
4710 vertices[0].position.x = 0.0f;
4711 vertices[0].position.y = 0.0f;
4712 vertices[0].position.z = 0.0f;
4713 vertices[0].normal.x = 0.0f;
4714 vertices[0].normal.y = 0.0f;
4715 vertices[0].normal.z = 1.0f;
4716
4717 for (i = 0; i < sides; ++i)
4718 {
4719 vertices[i + 1].position.x = cosf(angle * i) * scale;
4720 vertices[i + 1].position.y = sinf(angle * i) * scale;
4721 vertices[i + 1].position.z = 0.0f;
4722 vertices[i + 1].normal.x = 0.0f;
4723 vertices[i + 1].normal.y = 0.0f;
4724 vertices[i + 1].normal.z = 1.0f;
4725
4726 faces[i][0] = 0;
4727 faces[i][1] = i + 1;
4728 faces[i][2] = i + 2;
4729 }
4730
4731 faces[sides - 1][2] = 1;
4732
4733 polygon->lpVtbl->UnlockVertexBuffer(polygon);
4734 polygon->lpVtbl->UnlockIndexBuffer(polygon);
4735
4736 if (adjacency)
4737 {
4738 if (FAILED(hr = D3DXCreateBuffer(sides * sizeof(DWORD) * 3, adjacency)))
4739 {
4740 polygon->lpVtbl->Release(polygon);
4741 return hr;
4742 }
4743
4744 adjacency_buf = ID3DXBuffer_GetBufferPointer(*adjacency);
4745 for (i = 0; i < sides; ++i)
4746 {
4747 adjacency_buf[i][0] = i - 1;
4748 adjacency_buf[i][1] = ~0U;
4749 adjacency_buf[i][2] = i + 1;
4750 }
4751 adjacency_buf[0][0] = sides - 1;
4752 adjacency_buf[sides - 1][2] = 0;
4753 }
4754
4755 *mesh = polygon;
4756
4757 return D3D_OK;
4758}
#define U(x)
Definition: wordpad.c:45
_ACRTIMP float __cdecl cosf(float)
Definition: cosf.c:13
_ACRTIMP float __cdecl sinf(float)
Definition: sinf.c:13
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9032
GLfloat angle
Definition: glext.h:10853
nsrefcnt Release()
#define DWORD
Definition: nt_native.h:44

Referenced by D3DXCreatePolygonTest(), and test_polygon().

◆ D3DXCreateSphere()

HRESULT WINAPI D3DXCreateSphere ( struct IDirect3DDevice9 *  device,
float  radius,
UINT  slices,
UINT  stacks,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 4902 of file mesh.c.

4904{
4905 DWORD number_of_vertices, number_of_faces;
4906 HRESULT hr;
4907 ID3DXMesh *sphere;
4908 struct vertex *vertices;
4909 face *faces;
4910 float phi_step, phi_start;
4911 struct sincos_table phi;
4912 float theta_step, theta, sin_theta, cos_theta;
4914
4915 TRACE("(%p, %f, %u, %u, %p, %p)\n", device, radius, slices, stacks, mesh, adjacency);
4916
4917 if (!device || radius < 0.0f || slices < 2 || stacks < 2 || !mesh)
4918 {
4919 return D3DERR_INVALIDCALL;
4920 }
4921
4922 number_of_vertices = 2 + slices * (stacks-1);
4923 number_of_faces = 2 * slices + (stacks - 2) * (2 * slices);
4924
4925 hr = D3DXCreateMeshFVF(number_of_faces, number_of_vertices, D3DXMESH_MANAGED,
4926 D3DFVF_XYZ | D3DFVF_NORMAL, device, &sphere);
4927 if (FAILED(hr))
4928 {
4929 return hr;
4930 }
4931
4932 if (FAILED(hr = sphere->lpVtbl->LockVertexBuffer(sphere, 0, (void **)&vertices)))
4933 {
4934 sphere->lpVtbl->Release(sphere);
4935 return hr;
4936 }
4937
4938 if (FAILED(hr = sphere->lpVtbl->LockIndexBuffer(sphere, 0, (void **)&faces)))
4939 {
4940 sphere->lpVtbl->UnlockVertexBuffer(sphere);
4941 sphere->lpVtbl->Release(sphere);
4942 return hr;
4943 }
4944
4945 /* phi = angle on xz plane wrt z axis */
4946 phi_step = -2.0f * D3DX_PI / slices;
4947 phi_start = D3DX_PI / 2.0f;
4948
4949 if (!compute_sincos_table(&phi, phi_start, phi_step, slices))
4950 {
4951 sphere->lpVtbl->UnlockIndexBuffer(sphere);
4952 sphere->lpVtbl->UnlockVertexBuffer(sphere);
4953 sphere->lpVtbl->Release(sphere);
4954 return E_OUTOFMEMORY;
4955 }
4956
4957 /* theta = angle on xy plane wrt x axis */
4958 theta_step = D3DX_PI / stacks;
4959 theta = theta_step;
4960
4961 vertex = 0;
4962 face = 0;
4963
4964 vertices[vertex].normal.x = 0.0f;
4965 vertices[vertex].normal.y = 0.0f;
4966 vertices[vertex].normal.z = 1.0f;
4967 vertices[vertex].position.x = 0.0f;
4968 vertices[vertex].position.y = 0.0f;
4969 vertices[vertex].position.z = radius;
4970 vertex++;
4971
4972 for (stack = 0; stack < stacks - 1; stack++)
4973 {
4974 sin_theta = sinf(theta);
4975 cos_theta = cosf(theta);
4976
4977 for (slice = 0; slice < slices; slice++)
4978 {
4979 vertices[vertex].normal.x = sin_theta * phi.cos[slice];
4980 vertices[vertex].normal.y = sin_theta * phi.sin[slice];
4981 vertices[vertex].normal.z = cos_theta;
4982 vertices[vertex].position.x = radius * sin_theta * phi.cos[slice];
4983 vertices[vertex].position.y = radius * sin_theta * phi.sin[slice];
4984 vertices[vertex].position.z = radius * cos_theta;
4985 vertex++;
4986
4987 if (slice > 0)
4988 {
4989 if (stack == 0)
4990 {
4991 /* top stack is triangle fan */
4992 faces[face][0] = 0;
4993 faces[face][1] = slice + 1;
4994 faces[face][2] = slice;
4995 face++;
4996 }
4997 else
4998 {
4999 /* stacks in between top and bottom are quad strips */
5000 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5001 faces[face][1] = vertex_index(slices, slice, stack-1);
5002 faces[face][2] = vertex_index(slices, slice-1, stack);
5003 face++;
5004
5005 faces[face][0] = vertex_index(slices, slice, stack-1);
5006 faces[face][1] = vertex_index(slices, slice, stack);
5007 faces[face][2] = vertex_index(slices, slice-1, stack);
5008 face++;
5009 }
5010 }
5011 }
5012
5013 theta += theta_step;
5014
5015 if (stack == 0)
5016 {
5017 faces[face][0] = 0;
5018 faces[face][1] = 1;
5019 faces[face][2] = slice;
5020 face++;
5021 }
5022 else
5023 {
5024 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5025 faces[face][1] = vertex_index(slices, 0, stack-1);
5026 faces[face][2] = vertex_index(slices, slice-1, stack);
5027 face++;
5028
5029 faces[face][0] = vertex_index(slices, 0, stack-1);
5030 faces[face][1] = vertex_index(slices, 0, stack);
5031 faces[face][2] = vertex_index(slices, slice-1, stack);
5032 face++;
5033 }
5034 }
5035
5036 vertices[vertex].position.x = 0.0f;
5037 vertices[vertex].position.y = 0.0f;
5038 vertices[vertex].position.z = -radius;
5039 vertices[vertex].normal.x = 0.0f;
5040 vertices[vertex].normal.y = 0.0f;
5041 vertices[vertex].normal.z = -1.0f;
5042
5043 /* bottom stack is triangle fan */
5044 for (slice = 1; slice < slices; slice++)
5045 {
5046 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5047 faces[face][1] = vertex_index(slices, slice, stack-1);
5048 faces[face][2] = vertex;
5049 face++;
5050 }
5051
5052 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5053 faces[face][1] = vertex_index(slices, 0, stack-1);
5054 faces[face][2] = vertex;
5055
5056 free_sincos_table(&phi);
5057 sphere->lpVtbl->UnlockIndexBuffer(sphere);
5058 sphere->lpVtbl->UnlockVertexBuffer(sphere);
5059
5060
5061 if (adjacency)
5062 {
5063 if (FAILED(hr = D3DXCreateBuffer(number_of_faces * sizeof(DWORD) * 3, adjacency)))
5064 {
5065 sphere->lpVtbl->Release(sphere);
5066 return hr;
5067 }
5068
5069 if (FAILED(hr = sphere->lpVtbl->GenerateAdjacency(sphere, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
5070 {
5071 (*adjacency)->lpVtbl->Release(*adjacency);
5072 sphere->lpVtbl->Release(sphere);
5073 return hr;
5074 }
5075 }
5076
5077 *mesh = sphere;
5078
5079 return D3D_OK;
5080}

Referenced by D3DXCreateSphereTest(), D3DXCreateTeapot(), test_compute_normals(), and test_sphere().

◆ D3DXCreateTeapot()

HRESULT WINAPI D3DXCreateTeapot ( struct IDirect3DDevice9 *  device,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 5276 of file mesh.c.

5278{
5279 FIXME("device %p, mesh %p, adjacency %p semi-stub.\n", device, mesh, adjacency);
5280
5281 return D3DXCreateSphere(device, 1.0f, 4, 4, mesh, adjacency);
5282}
#define FIXME(fmt,...)
Definition: precomp.h:53
HRESULT WINAPI D3DXCreateSphere(struct IDirect3DDevice9 *device, float radius, UINT slices, UINT stacks, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
Definition: mesh.c:4902

◆ D3DXCreateTextA()

HRESULT WINAPI D3DXCreateTextA ( struct IDirect3DDevice9 *  device,
HDC  hdc,
const char *  text,
float  deviation,
float  extrusion,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency,
GLYPHMETRICSFLOAT *  glyphmetrics 
)

Definition at line 5284 of file mesh.c.

5286{
5287 WCHAR *textW;
5288 HRESULT hr;
5289 int len;
5290
5291 TRACE("device %p, hdc %p, text %s, deviation %.8e, extrusion %.8e, mesh %p, adjacency %p, glyphmetrics %p.\n",
5292 device, hdc, debugstr_a(text), deviation, extrusion, mesh, adjacency, glyphmetrics);
5293
5294 if (!text)
5295 return D3DERR_INVALIDCALL;
5296
5297 len = MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
5298 textW = malloc(len * sizeof(WCHAR));
5300
5301 hr = D3DXCreateTextW(device, hdc, textW, deviation, extrusion,
5302 mesh, adjacency, glyphmetrics);
5303 free(textW);
5304
5305 return hr;
5306}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT WINAPI D3DXCreateTextW(struct IDirect3DDevice9 *device, HDC hdc, const WCHAR *text, float deviation, float extrusion, struct ID3DXMesh **mesh_ptr, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
Definition: mesh.c:6192
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
const WCHAR * text
Definition: package.c:1826
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_a
Definition: kernel32.h:31
HDC hdc
Definition: main.c:9
static const WCHAR textW[]
Definition: itemdlg.c:1621
short WCHAR
Definition: pedump.c:58

Referenced by D3DXCreateTextTest(), and test_createtext().

◆ D3DXCreateTextW()

HRESULT WINAPI D3DXCreateTextW ( struct IDirect3DDevice9 *  device,
HDC  hdc,
const WCHAR *  text,
float  deviation,
FLOAT  extrusion,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency,
GLYPHMETRICSFLOAT *  glyphmetrics 
)

Definition at line 6192 of file mesh.c.

6194{
6195 HRESULT hr;
6196 ID3DXMesh *mesh = NULL;
6197 DWORD nb_vertices, nb_faces;
6198 DWORD nb_front_faces, nb_corners, nb_outline_points;
6199 struct vertex *vertices = NULL;
6200 face *faces = NULL;
6201 int textlen = 0;
6202 float offset_x;
6203 LOGFONTW lf;
6205 HFONT font = NULL, oldfont = NULL;
6206 const MAT2 identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
6207 void *raw_outline = NULL;
6208 int bufsize = 0;
6209 struct glyphinfo *glyphs = NULL;
6210 GLYPHMETRICS gm;
6211 struct triangulation_array triangulations = {0, 0, NULL};
6212 int i;
6213 struct vertex *vertex_ptr;
6214 face *face_ptr;
6215 float max_deviation_sq;
6216 const struct cos_table cos_table = {
6217 cosf(D3DXToRadian(0.5f)),
6218 cosf(D3DXToRadian(45.0f)),
6219 cosf(D3DXToRadian(90.0f)),
6220 };
6221 int f1, f2;
6222
6223 TRACE("(%p, %p, %s, %f, %f, %p, %p, %p)\n", device, hdc,
6224 debugstr_w(text), deviation, extrusion, mesh_ptr, adjacency, glyphmetrics);
6225
6226 if (!device || !hdc || !text || !*text || deviation < 0.0f || extrusion < 0.0f || !mesh_ptr)
6227 return D3DERR_INVALIDCALL;
6228
6229 if (adjacency)
6230 {
6231 FIXME("Case of adjacency != NULL not implemented.\n");
6232 return E_NOTIMPL;
6233 }
6234
6235 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf) ||
6236 !GetOutlineTextMetricsW(hdc, sizeof(otm), &otm))
6237 {
6238 return D3DERR_INVALIDCALL;
6239 }
6240
6241 if (deviation == 0.0f)
6242 deviation = 1.0f / otm.otmEMSquare;
6243 max_deviation_sq = deviation * deviation;
6244
6245 lf.lfHeight = otm.otmEMSquare;
6246 lf.lfWidth = 0;
6248 if (!font) {
6249 hr = E_OUTOFMEMORY;
6250 goto error;
6251 }
6252 oldfont = SelectObject(hdc, font);
6253
6254 textlen = lstrlenW(text);
6255 for (i = 0; i < textlen; i++)
6256 {
6258 if (datasize < 0)
6259 return D3DERR_INVALIDCALL;
6260 if (bufsize < datasize)
6261 bufsize = datasize;
6262 }
6263 if (!bufsize) { /* e.g. text == " " */
6265 goto error;
6266 }
6267
6268 glyphs = calloc(textlen, sizeof(*glyphs));
6269 raw_outline = malloc(bufsize);
6270 if (!glyphs || !raw_outline) {
6271 hr = E_OUTOFMEMORY;
6272 goto error;
6273 }
6274
6275 offset_x = 0.0f;
6276 for (i = 0; i < textlen; i++)
6277 {
6278 /* get outline points from data returned from GetGlyphOutline */
6279 int datasize;
6280
6281 glyphs[i].offset_x = offset_x;
6282
6283 datasize = GetGlyphOutlineW(hdc, text[i], GGO_NATIVE, &gm, bufsize, raw_outline, &identity);
6284 hr = create_outline(&glyphs[i], raw_outline, datasize,
6285 max_deviation_sq, otm.otmEMSquare, &cos_table);
6286 if (hr != S_OK) goto error;
6287
6288 triangulations.glyph = &glyphs[i];
6289 hr = triangulate(&triangulations);
6290 if (hr != S_OK) goto error;
6291 if (triangulations.count) {
6292 ERR("%d incomplete triangulations of glyph (%u).\n", triangulations.count, text[i]);
6293 triangulations.count = 0;
6294 }
6295
6296 if (glyphmetrics)
6297 {
6298 glyphmetrics[i].gmfBlackBoxX = gm.gmBlackBoxX / (float)otm.otmEMSquare;
6299 glyphmetrics[i].gmfBlackBoxY = gm.gmBlackBoxY / (float)otm.otmEMSquare;
6300 glyphmetrics[i].gmfptGlyphOrigin.x = gm.gmptGlyphOrigin.x / (float)otm.otmEMSquare;
6301 glyphmetrics[i].gmfptGlyphOrigin.y = gm.gmptGlyphOrigin.y / (float)otm.otmEMSquare;
6302 glyphmetrics[i].gmfCellIncX = gm.gmCellIncX / (float)otm.otmEMSquare;
6303 glyphmetrics[i].gmfCellIncY = gm.gmCellIncY / (float)otm.otmEMSquare;
6304 }
6305 offset_x += gm.gmCellIncX / (float)otm.otmEMSquare;
6306 }
6307
6308 /* corner points need an extra vertex for the different side faces normals */
6309 nb_corners = 0;
6310 nb_outline_points = 0;
6311 nb_front_faces = 0;
6312 for (i = 0; i < textlen; i++)
6313 {
6314 int j;
6315 nb_outline_points += glyphs[i].ordered_vertices.count;
6316 nb_front_faces += glyphs[i].faces.count;
6317 for (j = 0; j < glyphs[i].outlines.count; j++)
6318 {
6319 int k;
6320 struct outline *outline = &glyphs[i].outlines.items[j];
6321 nb_corners++; /* first outline point always repeated as a corner */
6322 for (k = 1; k < outline->count; k++)
6323 if (outline->items[k].corner)
6324 nb_corners++;
6325 }
6326 }
6327
6328 nb_vertices = (nb_outline_points + nb_corners) * 2 + nb_outline_points * 2;
6329 nb_faces = nb_outline_points * 2 + nb_front_faces * 2;
6330
6331
6332 hr = D3DXCreateMeshFVF(nb_faces, nb_vertices, D3DXMESH_MANAGED,
6334 if (FAILED(hr))
6335 goto error;
6336
6337 if (FAILED(hr = mesh->lpVtbl->LockVertexBuffer(mesh, 0, (void **)&vertices)))
6338 goto error;
6339
6340 if (FAILED(hr = mesh->lpVtbl->LockIndexBuffer(mesh, 0, (void **)&faces)))
6341 goto error;
6342
6343 /* convert 2D vertices and faces into 3D mesh */
6344 vertex_ptr = vertices;
6345 face_ptr = faces;
6346 if (extrusion == 0.0f) {
6347 f1 = 1;
6348 f2 = 2;
6349 } else {
6350 f1 = 2;
6351 f2 = 1;
6352 }
6353 for (i = 0; i < textlen; i++)
6354 {
6355 int j;
6356 int count;
6357 struct vertex *back_vertices;
6358 face *back_faces;
6359
6360 /* side vertices and faces */
6361 for (j = 0; j < glyphs[i].outlines.count; j++)
6362 {
6363 struct vertex *outline_vertices = vertex_ptr;
6364 struct outline *outline = &glyphs[i].outlines.items[j];
6365 int k;
6366 struct point2d *prevpt = &outline->items[outline->count - 1];
6367 struct point2d *pt = &outline->items[0];
6368
6369 for (k = 1; k <= outline->count; k++)
6370 {
6371 struct vertex vtx;
6372 struct point2d *nextpt = &outline->items[k % outline->count];
6373 WORD vtx_idx = vertex_ptr - vertices;
6375
6376 if (pt->corner == POINTTYPE_CURVE_START)
6377 D3DXVec2Subtract(&vec, &pt->pos, &prevpt->pos);
6378 else if (pt->corner)
6379 D3DXVec2Subtract(&vec, &nextpt->pos, &pt->pos);
6380 else
6381 D3DXVec2Subtract(&vec, &nextpt->pos, &prevpt->pos);
6383 vtx.normal.x = -vec.y;
6384 vtx.normal.y = vec.x;
6385 vtx.normal.z = 0;
6386
6387 vtx.position.x = pt->pos.x + glyphs[i].offset_x;
6388 vtx.position.y = pt->pos.y;
6389 vtx.position.z = 0;
6390 *vertex_ptr++ = vtx;
6391
6392 vtx.position.z = -extrusion;
6393 *vertex_ptr++ = vtx;
6394
6395 vtx.position.x = nextpt->pos.x + glyphs[i].offset_x;
6396 vtx.position.y = nextpt->pos.y;
6397 if (pt->corner && nextpt->corner && nextpt->corner != POINTTYPE_CURVE_END) {
6398 vtx.position.z = -extrusion;
6399 *vertex_ptr++ = vtx;
6400 vtx.position.z = 0;
6401 *vertex_ptr++ = vtx;
6402
6403 (*face_ptr)[0] = vtx_idx;
6404 (*face_ptr)[1] = vtx_idx + 2;
6405 (*face_ptr)[2] = vtx_idx + 1;
6406 face_ptr++;
6407
6408 (*face_ptr)[0] = vtx_idx;
6409 (*face_ptr)[1] = vtx_idx + 3;
6410 (*face_ptr)[2] = vtx_idx + 2;
6411 face_ptr++;
6412 } else {
6413 if (nextpt->corner) {
6414 if (nextpt->corner == POINTTYPE_CURVE_END) {
6415 D3DXVECTOR2 *nextpt2 = &outline->items[(k + 1) % outline->count].pos;
6416 D3DXVec2Subtract(&vec, nextpt2, &nextpt->pos);
6417 } else {
6418 D3DXVec2Subtract(&vec, &nextpt->pos, &pt->pos);
6419 }
6421 vtx.normal.x = -vec.y;
6422 vtx.normal.y = vec.x;
6423
6424 vtx.position.z = 0;
6425 *vertex_ptr++ = vtx;
6426 vtx.position.z = -extrusion;
6427 *vertex_ptr++ = vtx;
6428 }
6429
6430 (*face_ptr)[0] = vtx_idx;
6431 (*face_ptr)[1] = vtx_idx + 3;
6432 (*face_ptr)[2] = vtx_idx + 1;
6433 face_ptr++;
6434
6435 (*face_ptr)[0] = vtx_idx;
6436 (*face_ptr)[1] = vtx_idx + 2;
6437 (*face_ptr)[2] = vtx_idx + 3;
6438 face_ptr++;
6439 }
6440
6441 prevpt = pt;
6442 pt = nextpt;
6443 }
6444 if (!pt->corner) {
6445 *vertex_ptr++ = *outline_vertices++;
6446 *vertex_ptr++ = *outline_vertices++;
6447 }
6448 }
6449
6450 /* back vertices and faces */
6451 back_faces = face_ptr;
6452 back_vertices = vertex_ptr;
6453 for (j = 0; j < glyphs[i].ordered_vertices.count; j++)
6454 {
6455 D3DXVECTOR2 *pt = get_ordered_vertex(&glyphs[i], j);
6456 vertex_ptr->position.x = pt->x + glyphs[i].offset_x;
6457 vertex_ptr->position.y = pt->y;
6458 vertex_ptr->position.z = 0;
6459 vertex_ptr->normal.x = 0;
6460 vertex_ptr->normal.y = 0;
6461 vertex_ptr->normal.z = 1;
6462 vertex_ptr++;
6463 }
6464 count = back_vertices - vertices;
6465 for (j = 0; j < glyphs[i].faces.count; j++)
6466 {
6467 face *f = &glyphs[i].faces.items[j];
6468 (*face_ptr)[0] = (*f)[0] + count;
6469 (*face_ptr)[1] = (*f)[1] + count;
6470 (*face_ptr)[2] = (*f)[2] + count;
6471 face_ptr++;
6472 }
6473
6474 /* front vertices and faces */
6475 j = count = vertex_ptr - back_vertices;
6476 while (j--)
6477 {
6478 vertex_ptr->position.x = back_vertices->position.x;
6479 vertex_ptr->position.y = back_vertices->position.y;
6480 vertex_ptr->position.z = -extrusion;
6481 vertex_ptr->normal.x = 0;
6482 vertex_ptr->normal.y = 0;
6483 vertex_ptr->normal.z = extrusion == 0.0f ? 1.0f : -1.0f;
6484 vertex_ptr++;
6485 back_vertices++;
6486 }
6487 j = face_ptr - back_faces;
6488 while (j--)
6489 {
6490 (*face_ptr)[0] = (*back_faces)[0] + count;
6491 (*face_ptr)[1] = (*back_faces)[f1] + count;
6492 (*face_ptr)[2] = (*back_faces)[f2] + count;
6493 face_ptr++;
6494 back_faces++;
6495 }
6496 }
6497
6498 *mesh_ptr = mesh;
6499 hr = D3D_OK;
6500error:
6501 if (mesh) {
6502 if (faces) mesh->lpVtbl->UnlockIndexBuffer(mesh);
6503 if (vertices) mesh->lpVtbl->UnlockVertexBuffer(mesh);
6504 if (hr != D3D_OK) mesh->lpVtbl->Release(mesh);
6505 }
6506 if (glyphs) {
6507 for (i = 0; i < textlen; i++)
6508 {
6509 int j;
6510 for (j = 0; j < glyphs[i].outlines.count; j++)
6511 free(glyphs[i].outlines.items[j].items);
6512 free(glyphs[i].outlines.items);
6513 free(glyphs[i].faces.items);
6514 free(glyphs[i].ordered_vertices.items);
6515 }
6516 free(glyphs);
6517 }
6518 if (triangulations.items) {
6519 int i;
6520 for (i = 0; i < triangulations.count; i++)
6521 free(triangulations.items[i].vertex_stack.items);
6522 free(triangulations.items);
6523 }
6524 free(raw_outline);
6525 if (oldfont) SelectObject(hdc, oldfont);
6526 if (font) DeleteObject(font);
6527
6528 return hr;
6529}
#define ERR(fmt,...)
Definition: precomp.h:57
static SIZE_T datasize
Definition: asm.c:30
#define E_NOTIMPL
Definition: ddrawi.h:99
D3DXVECTOR2 *WINAPI D3DXVec2Normalize(D3DXVECTOR2 *pout, const D3DXVECTOR2 *pv)
Definition: math.c:1659
static HRESULT create_outline(struct glyphinfo *glyph, void *raw_outline, int datasize, float max_deviation_sq, unsigned int emsquare, const struct cos_table *cos_table)
Definition: mesh.c:5671
static HRESULT triangulate(struct triangulation_array *triangulations)
Definition: mesh.c:5959
@ POINTTYPE_CURVE_END
Definition: mesh.c:5419
@ POINTTYPE_CURVE_START
Definition: mesh.c:5418
static D3DXVECTOR2 * get_ordered_vertex(struct glyphinfo *glyph, WORD index)
Definition: mesh.c:5839
#define lstrlenW
Definition: compat.h:750
#define pt(x, y)
Definition: drawing.c:79
#define D3DXToRadian(degree)
Definition: d3dx9math.h:33
FT_Vector * vec
Definition: ftbbox.c:469
pKey DeleteObject()
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLfloat f
Definition: glext.h:7540
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define S_OK
Definition: intsafe.h:52
#define debugstr_w
Definition: kernel32.h:32
#define error(str)
Definition: mkdosfs.c:1605
static float(__cdecl *square_half_float)(float x
int k
Definition: mpi.c:3369
Definition: mk_font.cpp:20
#define OBJ_FONT
Definition: objidl.idl:1019
#define calloc
Definition: rosglue.h:14
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
FLOAT x
Definition: d3dx9math.h:64
FLOAT y
Definition: d3dx9math.h:64
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78
LONG lfHeight
Definition: dimm.idl:59
LONG lfWidth
Definition: dimm.idl:60
long y
Definition: dcommon.idl:24
long x
Definition: dcommon.idl:24
FLOAT gmfBlackBoxX
Definition: wingdi.h:3172
POINTFLOAT gmfptGlyphOrigin
Definition: wingdi.h:3174
short gmCellIncX
Definition: wingdi.h:2891
UINT gmBlackBoxY
Definition: wingdi.h:2889
UINT gmBlackBoxX
Definition: wingdi.h:2888
short gmCellIncY
Definition: wingdi.h:2892
POINT gmptGlyphOrigin
Definition: wingdi.h:2890
Definition: wingdi.h:2918
FLOAT x
Definition: wingdi.h:3168
float offset_x
Definition: mesh.c:5472
struct point2d_index_array ordered_vertices
Definition: mesh.c:5471
struct face_array faces
Definition: mesh.c:5470
struct outline_array outlines
Definition: mesh.c:5469
Definition: mesh.c:5437
struct point2d * items
Definition: mesh.c:5439
int count
Definition: mesh.c:5438
Definition: mesh.c:5424
D3DXVECTOR2 pos
Definition: mesh.c:5425
enum pointtype corner
Definition: mesh.c:5426
struct triangulation * items
Definition: mesh.c:5494
struct glyphinfo * glyph
Definition: mesh.c:5496
D3DXVECTOR3 normal
Definition: mesh.c:4667
D3DXVECTOR3 position
Definition: mesh.c:4666
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:428
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
UINT WINAPI GetOutlineTextMetricsW(_In_ HDC hdc, _In_ UINT cjCopy, _Out_writes_bytes_opt_(cjCopy) LPOUTLINETEXTMETRICW potm)
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
#define GGO_NATIVE
Definition: wingdi.h:850
DWORD WINAPI GetGlyphOutlineW(_In_ HDC hdc, _In_ UINT uChar, _In_ UINT fuFormat, _Out_ LPGLYPHMETRICS lpgm, _In_ DWORD cjBuffer, _Out_writes_bytes_opt_(cjBuffer) LPVOID pvBuffer, _In_ CONST MAT2 *lpmat2)

Referenced by D3DXCreateTextA(), and D3DXCreateTextTest().

◆ D3DXCreateTorus()

HRESULT WINAPI D3DXCreateTorus ( struct IDirect3DDevice9 *  device,
float  innerradius,
float  outerradius,
UINT  sides,
UINT  rings,
struct ID3DXMesh **  mesh,
ID3DXBuffer **  adjacency 
)

Definition at line 5308 of file mesh.c.

5310{
5311 HRESULT hr;
5312 ID3DXMesh *torus;
5313 WORD (*faces)[3];
5314 struct vertex *vertices;
5315 float phi, phi_step, sin_phi, cos_phi;
5316 float theta, theta_step, sin_theta, cos_theta;
5317 unsigned int i, j, numvert, numfaces;
5318
5319 TRACE("device %p, innerradius %.8e, outerradius %.8e, sides %u, rings %u, mesh %p, adjacency %p.\n",
5320 device, innerradius, outerradius, sides, rings, mesh, adjacency);
5321
5322 numvert = sides * rings;
5323 numfaces = numvert * 2;
5324
5325 if (!device || innerradius < 0.0f || outerradius < 0.0f || sides < 3 || rings < 3 || !mesh)
5326 {
5327 WARN("Invalid arguments.\n");
5328 return D3DERR_INVALIDCALL;
5329 }
5330
5331 if (FAILED(hr = D3DXCreateMeshFVF(numfaces, numvert, D3DXMESH_MANAGED, D3DFVF_XYZ | D3DFVF_NORMAL, device, &torus)))
5332 return hr;
5333
5334 if (FAILED(hr = torus->lpVtbl->LockVertexBuffer(torus, 0, (void **)&vertices)))
5335 {
5336 torus->lpVtbl->Release(torus);
5337 return hr;
5338 }
5339
5340 if (FAILED(hr = torus->lpVtbl->LockIndexBuffer(torus, 0, (void **)&faces)))
5341 {
5342 torus->lpVtbl->UnlockVertexBuffer(torus);
5343 torus->lpVtbl->Release(torus);
5344 return hr;
5345 }
5346
5347 phi_step = D3DX_PI / sides * 2.0f;
5348 theta_step = D3DX_PI / rings * -2.0f;
5349
5350 theta = 0.0f;
5351
5352 for (i = 0; i < rings; ++i)
5353 {
5354 phi = 0.0f;
5355
5356 sin_theta = sinf(theta);
5357 cos_theta = cosf(theta);
5358
5359 for (j = 0; j < sides; ++j)
5360 {
5361 sin_phi = sinf(phi);
5362 cos_phi = cosf(phi);
5363
5364 vertices[i * sides + j].position.x = (innerradius * cos_phi + outerradius) * cos_theta;
5365 vertices[i * sides + j].position.y = (innerradius * cos_phi + outerradius) * sin_theta;
5366 vertices[i * sides + j].position.z = innerradius * sin_phi;
5367 vertices[i * sides + j].normal.x = cos_phi * cos_theta;
5368 vertices[i * sides + j].normal.y = cos_phi * sin_theta;
5369 vertices[i * sides + j].normal.z = sin_phi;
5370
5371 phi += phi_step;
5372 }
5373
5374 theta += theta_step;
5375 }
5376
5377 for (i = 0; i < numfaces - sides * 2; ++i)
5378 {
5379 faces[i][0] = i % 2 ? i / 2 + sides : i / 2;
5380 faces[i][1] = (i / 2 + 1) % sides ? i / 2 + 1 : i / 2 + 1 - sides;
5381 faces[i][2] = (i + 1) % (sides * 2) ? (i + 1) / 2 + sides : (i + 1) / 2;
5382 }
5383
5384 for (j = 0; i < numfaces; ++i, ++j)
5385 {
5386 faces[i][0] = i % 2 ? j / 2 : i / 2;
5387 faces[i][1] = (i / 2 + 1) % sides ? i / 2 + 1 : i / 2 + 1 - sides;
5388 faces[i][2] = i == numfaces - 1 ? 0 : (j + 1) / 2;
5389 }
5390
5391 torus->lpVtbl->UnlockIndexBuffer(torus);
5392 torus->lpVtbl->UnlockVertexBuffer(torus);
5393
5394 if (adjacency)
5395 {
5396 if (FAILED(hr = D3DXCreateBuffer(numfaces * sizeof(DWORD) * 3, adjacency)))
5397 {
5398 torus->lpVtbl->Release(torus);
5399 return hr;
5400 }
5401
5402 if (FAILED(hr = torus->lpVtbl->GenerateAdjacency(torus, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
5403 {
5404 (*adjacency)->lpVtbl->Release(*adjacency);
5405 torus->lpVtbl->Release(torus);
5406 return hr;
5407 }
5408 }
5409
5410 *mesh = torus;
5411
5412 return D3D_OK;
5413}
#define WARN(fmt,...)
Definition: precomp.h:61

Referenced by D3DXCreateTorusTest(), and test_torus().