partially restructure project

This commit is contained in:
Zack Buhman 2026-01-05 18:12:02 -06:00
parent c5ed512b73
commit b35f6af638
24 changed files with 162 additions and 41194 deletions

View File

@ -9,13 +9,14 @@ all: $(BUILD_TYPE)/d3d10.exe
$(BUILD_TYPE)/%.res: %.rc main.fxo
rc.exe /d "_UNICODE" /d "UNICODE" /fo $@ $<
$(BUILD_TYPE)/%.obj: %.cpp
$(BUILD_TYPE)/%.obj: src/%.cpp
cl.exe /Fo"$@" /Fd"$(BUILD_TYPE)\vc80.pdb" @"compile_$(BUILD_TYPE).rsp" $<
#$(BUILD_TYPE)/cesium_man.obj
OBJS = \
$(BUILD_TYPE)/robot_player.obj \
$(BUILD_TYPE)/main.obj \
$(BUILD_TYPE)/print.obj \
$(BUILD_TYPE)/render_state.obj \
$(BUILD_TYPE)/main.res
$(BUILD_TYPE)/d3d10.exe: $(OBJS)

View File

@ -1,24 +0,0 @@
fxc /Od /Zi /T fx_4_0 /nologo /Fo main.fxo main.fx
@if %errorlevel% neq 0 exit /b %errorlevel%
rem build main resource
rc.exe /d "_UNICODE" /d "UNICODE" /fo"Debug\main.res" ".\main.rc"
@if %errorlevel% neq 0 exit /b %errorlevel%
rem compile
cl.exe @"compile.rsp" "main.cpp"
@if %errorlevel% neq 0 exit /b %errorlevel%
rem link
link.exe @"link.rsp" /NOLOGO /ERRORREPORT:PROMPT
@if %errorlevel% neq 0 exit /b %errorlevel%
mt.exe -manifest d3d10.exe.debug.manifest -outputresource:Debug\d3d10.exe;1
@if %errorlevel% neq 0 exit /b %errorlevel%
Debug\d3d10.exe

View File

@ -1,24 +0,0 @@
fxc /Od /Zi /T fx_4_0 /nologo /Fo main.fxo main.fx
@if %errorlevel% neq 0 exit /b %errorlevel%
rem build main resource
rc.exe /d "_UNICODE" /d "UNICODE" /fo"Release\main.res" ".\main.rc"
@if %errorlevel% neq 0 exit /b %errorlevel%
rem compile
cl.exe @"compile_release.rsp" "main.cpp"
@if %errorlevel% neq 0 exit /b %errorlevel%
rem link
link.exe @"link_release.rsp" /NOLOGO /ERRORREPORT:PROMPT
@if %errorlevel% neq 0 exit /b %errorlevel%
mt.exe -manifest d3d10.exe.release.manifest -outputresource:Release\d3d10.exe;1
@if %errorlevel% neq 0 exit /b %errorlevel%
Release\d3d10.exe

File diff suppressed because it is too large Load Diff

View File

@ -1,445 +0,0 @@
const int skin_0__joints__length = 19;
extern const DWORD accessor_0[];
const int accessor_0__length = 14016;
const int accessor_0__size = (sizeof (DWORD)) * 14016;
extern const D3DXVECTOR4 accessor_1[];
const int accessor_1__length = 3273;
const int accessor_1__size = (sizeof (D3DXVECTOR4)) * 3273;
extern const D3DXVECTOR3 accessor_2[];
const int accessor_2__length = 3273;
const int accessor_2__size = (sizeof (D3DXVECTOR3)) * 3273;
extern const D3DXVECTOR3 accessor_3[];
const int accessor_3__length = 3273;
const int accessor_3__size = (sizeof (D3DXVECTOR3)) * 3273;
extern const D3DXVECTOR2 accessor_4[];
const int accessor_4__length = 3273;
const int accessor_4__size = (sizeof (D3DXVECTOR2)) * 3273;
extern const D3DXVECTOR4 accessor_5[];
const int accessor_5__length = 3273;
const int accessor_5__size = (sizeof (D3DXVECTOR4)) * 3273;
extern const float accessor_6[];
const int accessor_6__length = 48;
const int accessor_6__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_7[];
const int accessor_7__length = 48;
const int accessor_7__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_8[];
const int accessor_8__length = 48;
const int accessor_8__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_9[];
const int accessor_9__length = 48;
const int accessor_9__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_10[];
const int accessor_10__length = 48;
const int accessor_10__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_11[];
const int accessor_11__length = 48;
const int accessor_11__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_12[];
const int accessor_12__length = 48;
const int accessor_12__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_13[];
const int accessor_13__length = 48;
const int accessor_13__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_14[];
const int accessor_14__length = 48;
const int accessor_14__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_15[];
const int accessor_15__length = 48;
const int accessor_15__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_16[];
const int accessor_16__length = 48;
const int accessor_16__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_17[];
const int accessor_17__length = 48;
const int accessor_17__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_18[];
const int accessor_18__length = 48;
const int accessor_18__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_19[];
const int accessor_19__length = 48;
const int accessor_19__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_20[];
const int accessor_20__length = 48;
const int accessor_20__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_21[];
const int accessor_21__length = 48;
const int accessor_21__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_22[];
const int accessor_22__length = 48;
const int accessor_22__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_23[];
const int accessor_23__length = 48;
const int accessor_23__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_24[];
const int accessor_24__length = 48;
const int accessor_24__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_25[];
const int accessor_25__length = 48;
const int accessor_25__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_26[];
const int accessor_26__length = 48;
const int accessor_26__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_27[];
const int accessor_27__length = 48;
const int accessor_27__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_28[];
const int accessor_28__length = 48;
const int accessor_28__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_29[];
const int accessor_29__length = 48;
const int accessor_29__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_30[];
const int accessor_30__length = 48;
const int accessor_30__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_31[];
const int accessor_31__length = 48;
const int accessor_31__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_32[];
const int accessor_32__length = 48;
const int accessor_32__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_33[];
const int accessor_33__length = 48;
const int accessor_33__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_34[];
const int accessor_34__length = 48;
const int accessor_34__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_35[];
const int accessor_35__length = 48;
const int accessor_35__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_36[];
const int accessor_36__length = 48;
const int accessor_36__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_37[];
const int accessor_37__length = 48;
const int accessor_37__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_38[];
const int accessor_38__length = 48;
const int accessor_38__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_39[];
const int accessor_39__length = 48;
const int accessor_39__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_40[];
const int accessor_40__length = 48;
const int accessor_40__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_41[];
const int accessor_41__length = 48;
const int accessor_41__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_42[];
const int accessor_42__length = 48;
const int accessor_42__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_43[];
const int accessor_43__length = 48;
const int accessor_43__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_44[];
const int accessor_44__length = 48;
const int accessor_44__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_45[];
const int accessor_45__length = 48;
const int accessor_45__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_46[];
const int accessor_46__length = 48;
const int accessor_46__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_47[];
const int accessor_47__length = 48;
const int accessor_47__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_48[];
const int accessor_48__length = 48;
const int accessor_48__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_49[];
const int accessor_49__length = 48;
const int accessor_49__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_50[];
const int accessor_50__length = 48;
const int accessor_50__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_51[];
const int accessor_51__length = 48;
const int accessor_51__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_52[];
const int accessor_52__length = 48;
const int accessor_52__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_53[];
const int accessor_53__length = 48;
const int accessor_53__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_54[];
const int accessor_54__length = 48;
const int accessor_54__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_55[];
const int accessor_55__length = 48;
const int accessor_55__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_56[];
const int accessor_56__length = 48;
const int accessor_56__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_57[];
const int accessor_57__length = 48;
const int accessor_57__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_58[];
const int accessor_58__length = 48;
const int accessor_58__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_59[];
const int accessor_59__length = 48;
const int accessor_59__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_60[];
const int accessor_60__length = 48;
const int accessor_60__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_61[];
const int accessor_61__length = 48;
const int accessor_61__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_62[];
const int accessor_62__length = 48;
const int accessor_62__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_63[];
const int accessor_63__length = 48;
const int accessor_63__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_64[];
const int accessor_64__length = 48;
const int accessor_64__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_65[];
const int accessor_65__length = 48;
const int accessor_65__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_66[];
const int accessor_66__length = 48;
const int accessor_66__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_67[];
const int accessor_67__length = 48;
const int accessor_67__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_68[];
const int accessor_68__length = 48;
const int accessor_68__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_69[];
const int accessor_69__length = 48;
const int accessor_69__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_70[];
const int accessor_70__length = 48;
const int accessor_70__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_71[];
const int accessor_71__length = 48;
const int accessor_71__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_72[];
const int accessor_72__length = 48;
const int accessor_72__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_73[];
const int accessor_73__length = 48;
const int accessor_73__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_74[];
const int accessor_74__length = 48;
const int accessor_74__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_75[];
const int accessor_75__length = 48;
const int accessor_75__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_76[];
const int accessor_76__length = 48;
const int accessor_76__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_77[];
const int accessor_77__length = 48;
const int accessor_77__size = (sizeof (D3DXVECTOR3)) * 48;
extern const float accessor_78[];
const int accessor_78__length = 48;
const int accessor_78__size = (sizeof (float)) * 48;
extern const D3DXVECTOR3 accessor_79[];
const int accessor_79__length = 48;
const int accessor_79__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXVECTOR4 accessor_80[];
const int accessor_80__length = 48;
const int accessor_80__size = (sizeof (D3DXVECTOR4)) * 48;
extern const D3DXVECTOR3 accessor_81[];
const int accessor_81__length = 48;
const int accessor_81__size = (sizeof (D3DXVECTOR3)) * 48;
extern const D3DXMATRIX accessor_82[];
const int accessor_82__length = 19;
const int accessor_82__size = (sizeof (D3DXMATRIX)) * 19;
extern const Node node_0;
extern const Node node_1;
extern const Node node_2;
extern const Node node_3;
extern const Node node_4;
extern const Node node_5;
extern const Node node_6;
extern const Node node_7;
extern const Node node_8;
extern const Node node_9;
extern const Node node_10;
extern const Node node_11;
extern const Node node_12;
extern const Node node_13;
extern const Node node_14;
extern const Node node_15;
extern const Node node_16;
extern const Node node_17;
extern const Node node_18;
extern const Node node_19;
extern const Node node_20;
extern const Node node_21;
extern const Node * nodes[];
const int nodes__length = 22;
extern const AnimationChannel animation_0__channels[];
const int animation_0__channels__length = 57;

View File

@ -4,6 +4,8 @@
/D "_WINDOWS"
/D "_UNICODE"
/D "UNICODE"
/D "_WIN32_WINNT=0x0501"
/I ".\include"
/Gm
/EHsc
/RTC1

View File

@ -5,6 +5,8 @@
/D "_WINDOWS"
/D "_UNICODE"
/D "UNICODE"
/D "_WIN32_WINNT=0x0501"
/I ".\include"
/FD
/EHsc
/MT

Binary file not shown.

8
include/globals.hpp Normal file
View File

@ -0,0 +1,8 @@
#ifndef _GLOBALS_HPP_
#define _GLOBALS_HPP_
extern HINSTANCE g_hInstance;
extern HWND g_hWnd;
extern ID3D10Device * g_pd3dDevice;
#endif _GLOBALS_HPP_

7
include/print.hpp Normal file
View File

@ -0,0 +1,7 @@
#ifndef _PRINT_HPP_
#define _PRINT_HPP_
void print(LPCSTR fmt, ...);
void printW(LPCWSTR fmt, ...);
#endif _PRINT_HPP_

9
include/render_state.hpp Normal file
View File

@ -0,0 +1,9 @@
#ifndef _RENDER_STATE_HPP_
#define _RENDER_STATE_HPP_
HRESULT LoadTexture(const wchar_t * resourceName,
const int width,
const int height,
ID3D10ShaderResourceView ** pTextureShaderResourceView);
#endif _RENDER_STATE_HPP_

View File

@ -1,3 +1,2 @@
RES_MAIN_FXO RCDATA "main.fxo"
RES_SEAFLOOR RCDATA "seafloor.data"
RES_ROBOT_PLAYER RCDATA "robot_player.data"

View File

Before

Width:  |  Height:  |  Size: 542 B

After

Width:  |  Height:  |  Size: 542 B

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,22 +1,15 @@
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <d3d10.h>
#include <d3dx10.h>
#include <strsafe.h>
#include <assert.h>
#include "globals.hpp"
#include "print.hpp"
#include "render_state.hpp"
#include "gltf.hpp"
#include "gltf_instance.hpp"
//#include "rigged_simple.hpp"
//#define ROOT_MESH_NODE node_2
//#include "rigged_figure.hpp"
//#define ROOT_MESH_NODE node_1
//#include "cesium_man.hpp"
//#define ROOT_MESH_NODE node_2
#include "robot_player.hpp"
#define ROOT_MESH_NODE node_39
@ -34,7 +27,6 @@ ID3D10InputLayout * g_pVertexLayout = NULL;
//ID3D10Buffer * g_pVertexBuffer = NULL;
ID3D10Buffer * g_pIndexBuffer = NULL;
ID3D10Texture2D * g_pTexture = NULL;
ID3D10ShaderResourceView * g_pTextureShaderResourceView = NULL;
ID3D10EffectMatrixVariable * g_pWorldVariable = NULL;
@ -64,29 +56,6 @@ struct WindowSize {
WindowSize g_ViewportSize;
void print(LPCSTR fmt, ...)
{
va_list args;
va_start(args, fmt);
char buf[512];
STRSAFE_LPSTR end;
StringCbVPrintfExA(buf,
(sizeof (buf)),
&end,
NULL,
STRSAFE_NULL_ON_FAILURE,
fmt,
args);
va_end(args);
size_t length = end - &buf[0];
#ifdef _DEBUG
OutputDebugStringA(buf);
#endif
//HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
//WriteConsoleA(hOutput, buf, (DWORD)length, NULL, NULL);
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
//FreeConsole();
@ -320,47 +289,10 @@ HRESULT InitDirect3DDevice()
InitDirect3DViews();
// texture
HRSRC hRobotPlayerRes = FindResource(NULL, L"RES_ROBOT_PLAYER", RT_RCDATA);
if (hRobotPlayerRes == NULL) {
print("FindResource\n");
return -1;
}
DWORD dwRobotPlayerResSize = SizeofResource(NULL, hRobotPlayerRes);
HGLOBAL hRobotPlayerData = LoadResource(NULL, hRobotPlayerRes);
D3D10_SUBRESOURCE_DATA initRobotPlayerData;
initRobotPlayerData.pSysMem = LockResource(hRobotPlayerData);
initRobotPlayerData.SysMemPitch = 64 * 4;
D3D10_TEXTURE2D_DESC descTexture;
descTexture.Width = 64;
descTexture.Height = 64;
descTexture.MipLevels = 1;
descTexture.ArraySize = 1;
descTexture.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
descTexture.SampleDesc.Count = 1;
descTexture.SampleDesc.Quality = 0;
descTexture.Usage = D3D10_USAGE_DEFAULT;
descTexture.BindFlags = D3D10_BIND_SHADER_RESOURCE;
descTexture.CPUAccessFlags = 0;
descTexture.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D(&descTexture, &initRobotPlayerData, &g_pTexture);
if (FAILED(hr)) {
print("CreateTexture2D\n");
return hr;
}
D3D10_SHADER_RESOURCE_VIEW_DESC descSRV;
descSRV.Format = descTexture.Format;
descSRV.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
descSRV.Texture2D.MostDetailedMip = 0;
descSRV.Texture2D.MipLevels = 1;
hr = g_pd3dDevice->CreateShaderResourceView(g_pTexture, &descSRV, &g_pTextureShaderResourceView);
if (FAILED(hr)) {
print("CreateShaderResourceView\n");
return hr;
}
//////////////////////////////////////////////////////////////////////
// effect
//////////////////////////////////////////////////////////////////////
HRSRC hRes = FindResource(NULL, L"RES_MAIN_FXO", RT_RCDATA);
if (hRes == NULL) {
print("FindResource\n");
@ -394,7 +326,10 @@ HRESULT InitDirect3DDevice()
g_pOutputColorVariable = g_pEffect->GetVariableByName("vOutputColor")->AsVector();
g_pDiffuseVariable = g_pEffect->GetVariableByName("txDiffuse")->AsShaderResource();
//////////////////////////////////////////////////////////////////////
// input layout
//////////////////////////////////////////////////////////////////////
D3D10_INPUT_ELEMENT_DESC layout[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
@ -526,9 +461,20 @@ HRESULT InitDirect3DDevice()
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
//////////////////////////////////////////////////////////////////////
// textures
//////////////////////////////////////////////////////////////////////
hr = LoadTexture(L"RES_ROBOT_PLAYER", 64, 64, &g_pTextureShaderResourceView);
if (FAILED(hr)) {
print("LoadTexture\n");
return hr;
}
//////////////////////////////////////////////////////////////////////
// transform matrices
//////////////////////////////////////////////////////////////////////
D3DXMatrixIdentity(&g_World1);
D3DXMatrixIdentity(&g_World2);
@ -746,7 +692,7 @@ void Render()
for (int i = 0; i < joints_length; i++) {
D3DXMatrixIdentity(&mJoints[i]);
}
Animate(t);
//Animate(t);
// first cube

45
src/print.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <windows.h>
#include <strsafe.h>
#include "print.hpp"
void print(LPCSTR fmt, ...)
{
va_list args;
va_start(args, fmt);
char buf[512];
STRSAFE_LPSTR end;
StringCbVPrintfExA(buf,
(sizeof (buf)),
&end,
NULL,
STRSAFE_NULL_ON_FAILURE,
fmt,
args);
va_end(args);
size_t length = end - &buf[0];
#ifdef _DEBUG
OutputDebugStringA(buf);
#endif
//HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
//WriteConsoleA(hOutput, buf, (DWORD)length, NULL, NULL);
}
void printW(LPCWSTR fmt, ...)
{
va_list args;
va_start(args, fmt);
WCHAR buf[512];
StringCbVPrintfExW(buf,
(sizeof (buf)),
NULL,
NULL,
STRSAFE_NULL_ON_FAILURE,
fmt,
args);
va_end(args);
#ifdef _DEBUG
OutputDebugStringW(buf);
#endif
}

64
src/render_state.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <windows.h>
#include <assert.h>
#include <d3d10.h>
#include <d3dx10.h>
#include "globals.hpp"
#include "print.hpp"
#include "render_state.hpp"
HRESULT LoadTexture(const wchar_t * resourceName,
const int width,
const int height,
ID3D10ShaderResourceView ** pTextureShaderResourceView)
{
HRESULT hr;
// texture
HRSRC hRobotPlayerRes = FindResource(NULL, resourceName, RT_RCDATA);
if (hRobotPlayerRes == NULL) {
print("FindResource %s\n");
return -1;
}
DWORD dwResourceSize = SizeofResource(NULL, hRobotPlayerRes);
assert(width * height * 4 == dwResourceSize);
HGLOBAL hRobotPlayerData = LoadResource(NULL, hRobotPlayerRes);
D3D10_SUBRESOURCE_DATA subresourceData;
subresourceData.pSysMem = LockResource(hRobotPlayerData);
subresourceData.SysMemPitch = width * 4;
D3D10_TEXTURE2D_DESC textureDesc;
textureDesc.Width = width;
textureDesc.Height = height;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D10_USAGE_DEFAULT;
textureDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = 0;
ID3D10Texture2D * pTexture;
hr = g_pd3dDevice->CreateTexture2D(&textureDesc, &subresourceData, &pTexture);
if (FAILED(hr)) {
print("CreateTexture2D\n");
return hr;
}
D3D10_SHADER_RESOURCE_VIEW_DESC descSRV;
descSRV.Format = textureDesc.Format;
descSRV.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
descSRV.Texture2D.MostDetailedMip = 0;
descSRV.Texture2D.MipLevels = 1;
hr = g_pd3dDevice->CreateShaderResourceView(pTexture, &descSRV, pTextureShaderResourceView);
if (FAILED(hr)) {
print("CreateShaderResourceView\n");
return hr;
}
return S_OK;
}