mirror of
https://github.com/Team-Resurgent/Nuklear-XboxOG.git
synced 2026-08-15 20:18:05 -07:00
Initial Commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nuklear-XboxOG", "Nuklear-XboxOG\Nuklear-XboxOG.vcproj", "{5837B221-F405-4877-88B8-E6A5A594E59E}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
Profile = Profile
|
||||
Profile_FastCap = Profile_FastCap
|
||||
Release = Release
|
||||
Release_LTCG = Release_LTCG
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Debug.ActiveCfg = Debug|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Debug.Build.0 = Debug|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Profile.ActiveCfg = Profile|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Profile.Build.0 = Profile|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Profile_FastCap.ActiveCfg = Profile_FastCap|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Profile_FastCap.Build.0 = Profile_FastCap|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Release.ActiveCfg = Release|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Release.Build.0 = Release|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Release_LTCG.ActiveCfg = Release_LTCG|Xbox
|
||||
{5837B221-F405-4877-88B8-E6A5A594E59E}.Release_LTCG.Build.0 = Release_LTCG|Xbox
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,335 @@
|
||||
// NuklearOG.cpp : Defines the entry point for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "graphics.h"
|
||||
|
||||
#define NK_PRIVATE
|
||||
#define NK_INCLUDE_STANDARD_IO
|
||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||
#define NK_INCLUDE_FONT_BAKING
|
||||
#define NK_INCLUDE_DEFAULT_FONT
|
||||
#define NK_IMPLEMENTATION
|
||||
#include "nuklear.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
/* macros */
|
||||
#define WINDOW_WIDTH 1200
|
||||
#define WINDOW_HEIGHT 800
|
||||
|
||||
#define MAX_VERTEX_MEMORY 512 * 1024
|
||||
#define MAX_ELEMENT_MEMORY 128 * 1024
|
||||
|
||||
#define UNUSED(a) (void)a
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
#define LEN(a) (sizeof(a)/sizeof(a)[0])
|
||||
|
||||
struct nk_glfw_vertex {
|
||||
float position[3];
|
||||
nk_byte col[4];
|
||||
float uv[2];
|
||||
};
|
||||
|
||||
struct device {
|
||||
struct nk_buffer cmds;
|
||||
struct nk_draw_null_texture tex_null;
|
||||
|
||||
//IDirect3DVertexBuffer8 *vbo;
|
||||
//IDirect3DIndexBuffer8 *ebo;
|
||||
D3DTexture* font_tex;
|
||||
};
|
||||
|
||||
static void
|
||||
device_init(struct device *dev)
|
||||
{
|
||||
graphics::createDevice();
|
||||
|
||||
nk_buffer_init_default(&dev->cmds);
|
||||
|
||||
// HRESULT hr = graphics::getDevice()->CreateVertexBuffer(MAX_VERTEX_MEMORY, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &dev->vbo);
|
||||
//if (FAILED(hr)) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
// hr = graphics::getDevice()->CreateIndexBuffer(MAX_ELEMENT_MEMORY, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &dev->ebo);
|
||||
// if (FAILED(hr)) {
|
||||
// return;
|
||||
//}
|
||||
//{
|
||||
// /* buffer setup */
|
||||
// GLsizei vs = sizeof(struct nk_glfw_vertex);
|
||||
// size_t vp = offsetof(struct nk_glfw_vertex, position);
|
||||
// size_t vt = offsetof(struct nk_glfw_vertex, uv);
|
||||
// size_t vc = offsetof(struct nk_glfw_vertex, col);
|
||||
|
||||
// glGenBuffers(1, &dev->vbo);
|
||||
// glGenBuffers(1, &dev->ebo);
|
||||
// glGenVertexArrays(1, &dev->vao);
|
||||
|
||||
// glBindVertexArray(dev->vao);
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
|
||||
|
||||
// glEnableVertexAttribArray((GLuint)dev->attrib_pos);
|
||||
// glEnableVertexAttribArray((GLuint)dev->attrib_uv);
|
||||
// glEnableVertexAttribArray((GLuint)dev->attrib_col);
|
||||
|
||||
// glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp);
|
||||
// glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt);
|
||||
// glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc);
|
||||
//}
|
||||
|
||||
//glBindTexture(GL_TEXTURE_2D, 0);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
//glBindVertexArray(0);
|
||||
}
|
||||
|
||||
static void
|
||||
device_upload_atlas(struct device *dev, const void *image, int width, int height)
|
||||
{
|
||||
D3DTexture* texture = graphics::createImage((uint8_t*)image, D3DFMT_A8R8G8B8, width, height);
|
||||
dev->font_tex = texture;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
device_draw(struct device *dev, struct nk_context *ctx, int width, int height,
|
||||
enum nk_anti_aliasing AA)
|
||||
{
|
||||
|
||||
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
const struct nk_draw_command *cmd;
|
||||
const nk_draw_index *offset = NULL;
|
||||
UINT vertex_count;
|
||||
|
||||
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_B8G8R8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_glfw_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
|
||||
config.tex_null = dev->tex_null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* convert shapes into vertexes */
|
||||
nk_buffer_init_default(&vbuf);
|
||||
nk_buffer_init_default(&ebuf);
|
||||
nk_convert(ctx, &dev->cmds, &vbuf, &ebuf, &config);
|
||||
|
||||
offset = (const nk_draw_index *)nk_buffer_memory_const(&ebuf);
|
||||
vertex_count = (UINT)vbuf.needed / sizeof(struct nk_glfw_vertex);
|
||||
|
||||
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, ctx, &dev->cmds)
|
||||
{
|
||||
if (!cmd->elem_count) continue;
|
||||
//glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
|
||||
//glScissor(
|
||||
// (GLint)(cmd->clip_rect.x),
|
||||
// (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h))),
|
||||
// (GLint)(cmd->clip_rect.w),
|
||||
// (GLint)(cmd->clip_rect.h));
|
||||
//glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
|
||||
|
||||
graphics::getDevice()->SetTexture(0, (D3DTexture*)cmd->texture.ptr);
|
||||
|
||||
const struct nk_rect null_rect = nk_get_null_rect();
|
||||
bool isNullRect = memcmp(&null_rect, &cmd->clip_rect, sizeof(struct nk_rect)) == 0;
|
||||
if (isNullRect)
|
||||
{
|
||||
D3DVIEWPORT8 vp = { 0, 0, graphics::getWidth(), graphics::getHeight(), 0.0f, 1.0f };
|
||||
graphics::getDevice()->SetViewport(&vp);
|
||||
}
|
||||
else
|
||||
{
|
||||
D3DVIEWPORT8 vp = { cmd->clip_rect.x, cmd->clip_rect.y, cmd->clip_rect.w, cmd->clip_rect.h, 0.0f, 1.0f };
|
||||
graphics::getDevice()->SetViewport(&vp);
|
||||
}
|
||||
|
||||
graphics::getDevice()->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,
|
||||
0, vertex_count, cmd->elem_count/3, offset, D3DFMT_INDEX16,
|
||||
nk_buffer_memory_const(&vbuf), sizeof(struct nk_glfw_vertex));
|
||||
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
|
||||
nk_buffer_free(&vbuf);
|
||||
nk_buffer_free(&ebuf);
|
||||
|
||||
nk_clear(ctx);
|
||||
nk_buffer_clear(&dev->cmds);
|
||||
|
||||
|
||||
/* default OpenGL state */
|
||||
//glUseProgram(0);
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
//glBindVertexArray(0);
|
||||
//glDisable(GL_BLEND);
|
||||
//glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
static void
|
||||
pump_input(struct nk_context *ctx /*GLFWwindow *win*/)
|
||||
{
|
||||
/*double x, y;
|
||||
nk_input_begin(ctx);
|
||||
glfwPollEvents();
|
||||
|
||||
nk_input_key(ctx, NK_KEY_DEL, glfwGetKey(win, GLFW_KEY_DELETE) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_ENTER, glfwGetKey(win, GLFW_KEY_ENTER) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_TAB, glfwGetKey(win, GLFW_KEY_TAB) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_BACKSPACE, glfwGetKey(win, GLFW_KEY_BACKSPACE) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_LEFT, glfwGetKey(win, GLFW_KEY_LEFT) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_RIGHT, glfwGetKey(win, GLFW_KEY_RIGHT) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_UP, glfwGetKey(win, GLFW_KEY_UP) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_DOWN, glfwGetKey(win, GLFW_KEY_DOWN) == GLFW_PRESS);
|
||||
|
||||
if (glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
|
||||
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) {
|
||||
nk_input_key(ctx, NK_KEY_COPY, glfwGetKey(win, GLFW_KEY_C) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_PASTE, glfwGetKey(win, GLFW_KEY_P) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_CUT, glfwGetKey(win, GLFW_KEY_X) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_CUT, glfwGetKey(win, GLFW_KEY_E) == GLFW_PRESS);
|
||||
nk_input_key(ctx, NK_KEY_SHIFT, 1);
|
||||
} else {
|
||||
nk_input_key(ctx, NK_KEY_COPY, 0);
|
||||
nk_input_key(ctx, NK_KEY_PASTE, 0);
|
||||
nk_input_key(ctx, NK_KEY_CUT, 0);
|
||||
nk_input_key(ctx, NK_KEY_SHIFT, 0);
|
||||
}
|
||||
|
||||
glfwGetCursorPos(win, &x, &y);
|
||||
nk_input_motion(ctx, (int)x, (int)y);
|
||||
nk_input_button(ctx, NK_BUTTON_LEFT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS);
|
||||
nk_input_button(ctx, NK_BUTTON_MIDDLE, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS);
|
||||
nk_input_button(ctx, NK_BUTTON_RIGHT, (int)x, (int)y, glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS);
|
||||
nk_input_end(ctx);*/
|
||||
}
|
||||
|
||||
struct nk_canvas {
|
||||
struct nk_command_buffer *painter;
|
||||
struct nk_vec2 item_spacing;
|
||||
struct nk_vec2 panel_padding;
|
||||
struct nk_style_item window_background;
|
||||
};
|
||||
|
||||
static void
|
||||
canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags,
|
||||
int x, int y, int width, int height, struct nk_color background_color)
|
||||
{
|
||||
/* save style properties which will be overwritten */
|
||||
canvas->panel_padding = ctx->style.window.padding;
|
||||
canvas->item_spacing = ctx->style.window.spacing;
|
||||
canvas->window_background = ctx->style.window.fixed_background;
|
||||
|
||||
/* use the complete window space and set background */
|
||||
ctx->style.window.spacing = nk_vec2(0,0);
|
||||
ctx->style.window.padding = nk_vec2(0,0);
|
||||
ctx->style.window.fixed_background = nk_style_item_color(background_color);
|
||||
|
||||
/* create/update window and set position + size */
|
||||
flags = flags & ~NK_WINDOW_DYNAMIC;
|
||||
nk_window_set_bounds(ctx, "Window", nk_rect(x, y, width, height));
|
||||
nk_begin(ctx, "Window", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags);
|
||||
|
||||
/* allocate the complete window space for drawing */
|
||||
{struct nk_rect total_space;
|
||||
total_space = nk_window_get_content_region(ctx);
|
||||
nk_layout_row_dynamic(ctx, total_space.h, 1);
|
||||
nk_widget(&total_space, ctx);
|
||||
canvas->painter = nk_window_get_canvas(ctx);}
|
||||
}
|
||||
|
||||
static void
|
||||
canvas_end(struct nk_context *ctx, struct nk_canvas *canvas)
|
||||
{
|
||||
nk_end(ctx);
|
||||
ctx->style.window.spacing = canvas->panel_padding;
|
||||
ctx->style.window.padding = canvas->item_spacing;
|
||||
ctx->style.window.fixed_background = canvas->window_background;
|
||||
}
|
||||
|
||||
void __cdecl main()
|
||||
{
|
||||
/* GUI */
|
||||
struct device device;
|
||||
struct nk_font_atlas atlas;
|
||||
struct nk_context ctx;
|
||||
|
||||
/* GUI */
|
||||
{device_init(&device);
|
||||
{const void *image; int w, h;
|
||||
struct nk_font *font;
|
||||
nk_font_atlas_init_default(&atlas);
|
||||
nk_font_atlas_begin(&atlas);
|
||||
font = nk_font_atlas_add_default(&atlas, 13, 0);
|
||||
image = nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
|
||||
device_upload_atlas(&device, image, w, h);
|
||||
nk_font_atlas_end(&atlas, nk_handle_ptr(device.font_tex), &device.tex_null);
|
||||
nk_init_default(&ctx, &font->handle);
|
||||
|
||||
int width = graphics::getWidth();
|
||||
int height = graphics::getHeight();
|
||||
|
||||
while (true)
|
||||
{
|
||||
pump_input(&ctx/*, win*/);
|
||||
|
||||
/* draw */
|
||||
{struct nk_canvas canvas;
|
||||
canvas_begin(&ctx, &canvas, 0, 0, 0, width, height, nk_rgb(250,250,250));
|
||||
{
|
||||
nk_fill_rect(canvas.painter, nk_rect(15,15,210,210), 5, nk_rgb(247, 230, 154));
|
||||
nk_fill_rect(canvas.painter, nk_rect(20,20,200,200), 5, nk_rgb(188, 174, 118));
|
||||
nk_draw_text(canvas.painter, nk_rect(30, 30, 150, 20), "Text to draw", 12, &font->handle, nk_rgb(188,174,118), nk_rgb(0,0,0));
|
||||
nk_fill_rect(canvas.painter, nk_rect(250,20,100,100), 0, nk_rgb(0,0,255));
|
||||
nk_fill_circle(canvas.painter, nk_rect(20,250,100,100), nk_rgb(255,0,0));
|
||||
nk_fill_triangle(canvas.painter, 250, 250, 350, 250, 300, 350, nk_rgb(0,255,0));
|
||||
nk_fill_arc(canvas.painter, 300, 180, 50, 0, 3.141592654f * 3.0f / 4.0f, nk_rgb(255,255,0));
|
||||
|
||||
{float points[12];
|
||||
points[0] = 200; points[1] = 250;
|
||||
points[2] = 250; points[3] = 350;
|
||||
points[4] = 225; points[5] = 350;
|
||||
points[6] = 200; points[7] = 300;
|
||||
points[8] = 175; points[9] = 350;
|
||||
points[10] = 150; points[11] = 350;
|
||||
nk_fill_polygon(canvas.painter, points, 6, nk_rgb(0,0,0));}
|
||||
|
||||
nk_stroke_line(canvas.painter, 15, 10, 200, 10, 2.0f, nk_rgb(189,45,75));
|
||||
nk_stroke_rect(canvas.painter, nk_rect(370, 20, 100, 100), 10, 3, nk_rgb(0,0,255));
|
||||
nk_stroke_curve(canvas.painter, 380, 200, 405, 270, 455, 120, 480, 200, 2, nk_rgb(0,150,220));
|
||||
nk_stroke_circle(canvas.painter, nk_rect(20, 370, 100, 100), 5, nk_rgb(0,255,120));
|
||||
nk_stroke_triangle(canvas.painter, 370, 250, 470, 250, 420, 350, 6, nk_rgb(255,0,143));
|
||||
}
|
||||
canvas_end(&ctx, &canvas);}
|
||||
|
||||
/* Draw */
|
||||
graphics::getDevice()->BeginScene();
|
||||
graphics::getDevice()->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff333333, 1.0f, 0L);
|
||||
device_draw(&device, &ctx, width, height, NK_ANTI_ALIASING_ON);
|
||||
graphics::getDevice()->EndScene();
|
||||
graphics::getDevice()->Present(NULL, NULL, NULL, NULL);
|
||||
}}}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="NuklearOG"
|
||||
ProjectGUID="{5837B221-F405-4877-88B8-E6A5A594E59E}"
|
||||
Keyword="XboxProj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Xbox"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Xbox"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
OptimizeForProcessor="2"
|
||||
PreprocessorDefinitions="_DEBUG;_XBOX"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
EnableEnhancedInstructionSet="1"
|
||||
UsePrecompiledHeader="3"
|
||||
PrecompiledHeaderFile="$(OutDir)/$(ProjectName).pch"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xactengd.lib xsndtrkd.lib xvoiced.lib xonlined.lib xboxkrnl.lib xbdm.lib"
|
||||
OutputFile="$(OutDir)/$(ProjectName).exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeForWindows98="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="XboxDeploymentTool"/>
|
||||
<Tool
|
||||
Name="XboxImageTool"
|
||||
StackSize="65536"
|
||||
IncludeDebugInfo="TRUE"
|
||||
NoLibWarn="TRUE"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Profile|Xbox"
|
||||
OutputDirectory="Profile"
|
||||
IntermediateDirectory="Profile"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="2"
|
||||
PreprocessorDefinitions="NDEBUG;_XBOX;PROFILE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="TRUE"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
EnableEnhancedInstructionSet="1"
|
||||
UsePrecompiledHeader="3"
|
||||
PrecompiledHeaderFile="$(OutDir)/$(ProjectName).pch"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="xapilib.lib d3d8i.lib d3dx8.lib xgraphics.lib dsound.lib dmusici.lib xactengi.lib xsndtrk.lib xvoice.lib xonlines.lib xboxkrnl.lib xbdm.lib xperf.lib"
|
||||
OutputFile="$(OutDir)/$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
SetChecksum="TRUE"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="XboxDeploymentTool"/>
|
||||
<Tool
|
||||
Name="XboxImageTool"
|
||||
StackSize="65536"
|
||||
IncludeDebugInfo="TRUE"
|
||||
NoLibWarn="TRUE"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Profile_FastCap|Xbox"
|
||||
OutputDirectory="Profile_FastCap"
|
||||
IntermediateDirectory="Profile_FastCap"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="2"
|
||||
PreprocessorDefinitions="NDEBUG;_XBOX;PROFILE;FASTCAP"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="TRUE"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
EnableEnhancedInstructionSet="1"
|
||||
UsePrecompiledHeader="3"
|
||||
PrecompiledHeaderFile="$(OutDir)/$(ProjectName).pch"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="3"
|
||||
FastCAP="TRUE"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="xapilib.lib d3d8i.lib d3dx8.lib xgraphics.lib dsound.lib dmusici.lib xactengi.lib xsndtrk.lib xvoice.lib xonlines.lib xboxkrnl.lib xbdm.lib xperf.lib"
|
||||
OutputFile="$(OutDir)/$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
SetChecksum="TRUE"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="XboxDeploymentTool"/>
|
||||
<Tool
|
||||
Name="XboxImageTool"
|
||||
StackSize="65536"
|
||||
IncludeDebugInfo="TRUE"
|
||||
NoLibWarn="TRUE"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Xbox"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="2"
|
||||
PreprocessorDefinitions="NDEBUG;_XBOX"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="TRUE"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
EnableEnhancedInstructionSet="1"
|
||||
UsePrecompiledHeader="3"
|
||||
PrecompiledHeaderFile="$(OutDir)/$(ProjectName).pch"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="xapilib.lib d3d8.lib d3dx8.lib xgraphics.lib dsound.lib dmusic.lib xacteng.lib xsndtrk.lib xvoice.lib xonlines.lib xboxkrnl.lib"
|
||||
OutputFile="$(OutDir)/$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
SetChecksum="TRUE"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="XboxDeploymentTool"/>
|
||||
<Tool
|
||||
Name="XboxImageTool"
|
||||
StackSize="65536"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release_LTCG|Xbox"
|
||||
OutputDirectory="Release_LTCG"
|
||||
IntermediateDirectory="Release_LTCG"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="2"
|
||||
PreprocessorDefinitions="NDEBUG;_XBOX;LTCG"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="TRUE"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
EnableEnhancedInstructionSet="1"
|
||||
UsePrecompiledHeader="3"
|
||||
PrecompiledHeaderFile="$(OutDir)/$(ProjectName).pch"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="xapilib.lib d3d8ltcg.lib d3dx8.lib xgraphicsltcg.lib dsound.lib dmusicltcg.lib xactengltcg.lib xsndtrk.lib xvoice.lib xonlines.lib xboxkrnl.lib"
|
||||
OutputFile="$(OutDir)/$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
SetChecksum="TRUE"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="XboxDeploymentTool"/>
|
||||
<Tool
|
||||
Name="XboxImageTool"
|
||||
StackSize="65536"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath=".\graphics.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\NuklearOG.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Xbox">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Profile|Xbox">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Profile_FastCap|Xbox">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Xbox">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release_LTCG|Xbox">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdint.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath=".\graphics.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\nuklear.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stb_image.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt">
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,32 @@
|
||||
========================================================================
|
||||
Xbox APPLICATION : NuklearOG Project Overview
|
||||
========================================================================
|
||||
|
||||
AppWizard has created this NuklearOG application for you.
|
||||
This file contains a summary of what you will find in each of the files that
|
||||
make up your NuklearOG application.
|
||||
|
||||
|
||||
NuklearOG.vcproj
|
||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the version of Visual C++ that generated the file, and
|
||||
information about the platforms, configurations, and project features selected with the
|
||||
Application Wizard.
|
||||
|
||||
NuklearOG.cpp
|
||||
This is the main application source file.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other standard files:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
These files are used to build a precompiled header (PCH) file
|
||||
named NuklearOG.pch and a precompiled types file named StdAfx.obj.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other notes:
|
||||
|
||||
AppWizard uses "TODO:" comments to indicate parts of the source code you
|
||||
should add to or customize.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -0,0 +1,307 @@
|
||||
#include "StdAfx.h"
|
||||
#include ".\graphics.h"
|
||||
#include "stdint.h"
|
||||
|
||||
static int mWidth;
|
||||
static int mHeight;
|
||||
static LPDIRECT3DDEVICE8 mD3dDevice;
|
||||
|
||||
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
|
||||
|
||||
DISPLAY_MODE displayModes[] =
|
||||
{
|
||||
//{ 720, 480, TRUE, TRUE, 60 }, // 720x480 progressive 16x9
|
||||
//{ 720, 480, TRUE, FALSE, 60 }, // 720x480 progressive 4x3
|
||||
//{ 720, 480, FALSE, TRUE, 50 }, // 720x480 interlaced 16x9 50Hz
|
||||
//{ 720, 480, FALSE, FALSE, 50 }, // 720x480 interlaced 4x3 50Hz
|
||||
//{ 720, 480, FALSE, TRUE, 60 }, // 720x480 interlaced 16x9
|
||||
//{ 720, 480, FALSE, FALSE, 60 }, // 720x480 interlaced 4x3
|
||||
|
||||
|
||||
// Width Height Progressive Widescreen
|
||||
|
||||
// HDTV Progressive Modes
|
||||
{ 1280, 720, TRUE, TRUE, 60 }, // 1280x720 progressive 16x9
|
||||
|
||||
// EDTV Progressive Modes
|
||||
{ 720, 480, TRUE, TRUE, 60 }, // 720x480 progressive 16x9
|
||||
{ 640, 480, TRUE, TRUE, 60 }, // 640x480 progressive 16x9
|
||||
{ 720, 480, TRUE, FALSE, 60 }, // 720x480 progressive 4x3
|
||||
{ 640, 480, TRUE, FALSE, 60 }, // 640x480 progressive 4x3
|
||||
|
||||
// HDTV Interlaced Modes
|
||||
// { 1920, 1080, FALSE, TRUE, 60 }, // 1920x1080 interlaced 16x9
|
||||
|
||||
// SDTV PAL-50 Interlaced Modes
|
||||
{ 720, 480, FALSE, TRUE, 50 }, // 720x480 interlaced 16x9 50Hz
|
||||
{ 640, 480, FALSE, TRUE, 50 }, // 640x480 interlaced 16x9 50Hz
|
||||
{ 720, 480, FALSE, FALSE, 50 }, // 720x480 interlaced 4x3 50Hz
|
||||
{ 640, 480, FALSE, FALSE, 50 }, // 640x480 interlaced 4x3 50Hz
|
||||
|
||||
// SDTV NTSC / PAL-60 Interlaced Modes
|
||||
{ 720, 480, FALSE, TRUE, 60 }, // 720x480 interlaced 16x9
|
||||
{ 640, 480, FALSE, TRUE, 60 }, // 640x480 interlaced 16x9
|
||||
{ 720, 480, FALSE, FALSE, 60 }, // 720x480 interlaced 4x3
|
||||
{ 640, 480, FALSE, FALSE, 60 }, // 640x480 interlaced 4x3
|
||||
};
|
||||
|
||||
#define NUM_MODES (sizeof(displayModes) / sizeof(displayModes[0]))
|
||||
|
||||
bool graphics::supportsMode(DISPLAY_MODE mode, DWORD dwVideoStandard, DWORD dwVideoFlags)
|
||||
{
|
||||
if (mode.dwFreq == 60 && !(dwVideoFlags & XC_VIDEO_FLAGS_PAL_60Hz) && (dwVideoStandard == XC_VIDEO_STANDARD_PAL_I))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mode.dwFreq == 50 && (dwVideoStandard != XC_VIDEO_STANDARD_PAL_I))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mode.dwHeight == 480 && mode.fWideScreen && !(dwVideoFlags & XC_VIDEO_FLAGS_WIDESCREEN ))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mode.dwHeight == 480 && mode.fProgressive && !(dwVideoFlags & XC_VIDEO_FLAGS_HDTV_480p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mode.dwHeight == 720 && !(dwVideoFlags & XC_VIDEO_FLAGS_HDTV_720p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mode.dwHeight == 1080 && !(dwVideoFlags & XC_VIDEO_FLAGS_HDTV_1080i))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool graphics::createDevice()
|
||||
{
|
||||
uint32_t videoFlags = XGetVideoFlags();
|
||||
uint32_t videoStandard = XGetVideoStandard();
|
||||
uint32_t currentMode;
|
||||
for (currentMode = 0; currentMode < NUM_MODES-1; currentMode++)
|
||||
{
|
||||
if (supportsMode(displayModes[currentMode], videoStandard, videoFlags))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LPDIRECT3D8 d3d = Direct3DCreate8(D3D_SDK_VERSION);
|
||||
if(d3d == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
D3DPRESENT_PARAMETERS params;
|
||||
ZeroMemory(¶ms, sizeof(params));
|
||||
params.BackBufferWidth = displayModes[currentMode].dwWidth;
|
||||
params.BackBufferHeight = displayModes[currentMode].dwHeight;
|
||||
params.Flags = displayModes[currentMode].fProgressive ? D3DPRESENTFLAG_PROGRESSIVE : D3DPRESENTFLAG_INTERLACED;
|
||||
params.Flags |= displayModes[currentMode].fWideScreen ? D3DPRESENTFLAG_WIDESCREEN : 0;
|
||||
params.FullScreen_RefreshRateInHz = displayModes[currentMode].dwFreq;
|
||||
params.BackBufferFormat = D3DFMT_X8R8G8B8;
|
||||
params.BackBufferCount = 1;
|
||||
params.EnableAutoDepthStencil = TRUE;
|
||||
params.AutoDepthStencilFormat = D3DFMT_D24S8;
|
||||
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
params.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
|
||||
|
||||
mWidth = displayModes[currentMode].dwWidth;
|
||||
mHeight = displayModes[currentMode].dwHeight;
|
||||
|
||||
LPDIRECT3DDEVICE8 d3dDevice;
|
||||
if (FAILED(d3d->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, ¶ms, &d3dDevice)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
mD3dDevice = d3dDevice;
|
||||
|
||||
D3DXMATRIX matProjection;
|
||||
|
||||
const float L = 0.5f;
|
||||
const float R = (float)mWidth + 0.5f;
|
||||
const float T = 0.5f;
|
||||
const float B = (float)mHeight + 0.5f;
|
||||
float matrix[4][4] = {
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
};
|
||||
matrix[0][0] = 2.0f / (R - L);
|
||||
matrix[1][1] = 2.0f / (T - B);
|
||||
matrix[3][0] = (R + L) / (L - R);
|
||||
matrix[3][1] = (T + B) / (B - T);
|
||||
memcpy(matProjection, matrix, sizeof(matrix));
|
||||
|
||||
//D3DXMatrixOrthoOffCenterRH(&matrix, 0, (float)mWidth, 0, (float)mHeight, 1.0f, 100.0f);
|
||||
mD3dDevice->SetTransform(D3DTS_PROJECTION, &matProjection);
|
||||
|
||||
D3DXMATRIX matView;
|
||||
D3DXMatrixIdentity(&matView);
|
||||
mD3dDevice->SetTransform( D3DTS_VIEW, &matView);
|
||||
|
||||
D3DXMATRIX matWorld;
|
||||
D3DXMatrixIdentity(&matWorld);
|
||||
mD3dDevice->SetTransform( D3DTS_WORLD, &matWorld);
|
||||
|
||||
// mD3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
|
||||
// mD3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
||||
|
||||
//mD3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
|
||||
//mD3dDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
|
||||
//mD3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
||||
//mD3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
//mD3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
|
||||
//mD3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
||||
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
// mD3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
|
||||
//mD3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
//mD3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
//mD3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
//mD3dDevice->BeginScene();
|
||||
//mD3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L);
|
||||
//mD3dDevice->EndScene();
|
||||
//mD3dDevice->Present(NULL, NULL, NULL, NULL);
|
||||
graphics::getDevice()->SetVertexShader(D3DFVF_XYZ + D3DFVF_DIFFUSE + D3DFVF_TEX1);
|
||||
|
||||
/* blend state */
|
||||
|
||||
|
||||
mD3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
mD3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
mD3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
||||
mD3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
|
||||
|
||||
/* render state */
|
||||
mD3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
|
||||
mD3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
|
||||
mD3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
||||
mD3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
|
||||
/* sampler state */
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
/* texture stage state */
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
mD3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
LPDIRECT3DDEVICE8 graphics::getDevice()
|
||||
{
|
||||
return mD3dDevice;
|
||||
}
|
||||
|
||||
|
||||
void graphics::swizzle(const void *src, const uint32_t& depth, const uint32_t& width, const uint32_t& height, void *dest)
|
||||
{
|
||||
for (UINT y = 0; y < height; y++)
|
||||
{
|
||||
UINT sy = 0;
|
||||
if (y < width)
|
||||
{
|
||||
for (int bit = 0; bit < 16; bit++)
|
||||
sy |= ((y >> bit) & 1) << (2*bit);
|
||||
sy <<= 1; // y counts twice
|
||||
}
|
||||
else
|
||||
{
|
||||
UINT y_mask = y % width;
|
||||
for (int bit = 0; bit < 16; bit++)
|
||||
sy |= ((y_mask >> bit) & 1) << (2*bit);
|
||||
sy <<= 1; // y counts twice
|
||||
sy += (y / width) * width * width;
|
||||
}
|
||||
BYTE *s = (BYTE *)src + y * width * depth;
|
||||
for (UINT x = 0; x < width; x++)
|
||||
{
|
||||
UINT sx = 0;
|
||||
if (x < height * 2)
|
||||
{
|
||||
for (int bit = 0; bit < 16; bit++)
|
||||
sx |= ((x >> bit) & 1) << (2*bit);
|
||||
}
|
||||
else
|
||||
{
|
||||
int x_mask = x % (2*height);
|
||||
for (int bit = 0; bit < 16; bit++)
|
||||
sx |= ((x_mask >> bit) & 1) << (2*bit);
|
||||
sx += (x / (2 * height)) * 2 * height * height;
|
||||
}
|
||||
BYTE *d = (BYTE *)dest + (sx + sy)*depth;
|
||||
for (unsigned int i = 0; i < depth; ++i)
|
||||
*d++ = *s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
D3DTexture* graphics::createImage(uint8_t* imageData, D3DFORMAT format, int width, int height)
|
||||
{
|
||||
D3DTexture *texture;
|
||||
if (FAILED(D3DXCreateTexture(mD3dDevice, width, height, 1, 0, format, D3DPOOL_DEFAULT, &texture)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
D3DSURFACE_DESC surfaceDesc;
|
||||
texture->GetLevelDesc(0, &surfaceDesc);
|
||||
|
||||
//imageToAdd->uvRect = math::rectF(0, 0, imageToAdd->width / (float)surfaceDesc.Width, imageToAdd->height / (float)surfaceDesc.Height);
|
||||
|
||||
D3DLOCKED_RECT lockedRect;
|
||||
if (SUCCEEDED(texture->LockRect(0, &lockedRect, NULL, 0)))
|
||||
{
|
||||
uint8_t* tempBuffer = (uint8_t*)malloc(surfaceDesc.Size);
|
||||
memset(tempBuffer, 0, surfaceDesc.Size);
|
||||
uint8_t* src = imageData;
|
||||
uint8_t* dst = tempBuffer;
|
||||
for (int32_t y = 0; y < height; y++)
|
||||
{
|
||||
memcpy(dst, src, width * 4);
|
||||
src += width * 4;
|
||||
dst += surfaceDesc.Width * 4;
|
||||
}
|
||||
swizzle(tempBuffer, 4, surfaceDesc.Width, surfaceDesc.Height, lockedRect.pBits);
|
||||
free(tempBuffer);
|
||||
|
||||
//for (int y = 0; y < height; y++) {
|
||||
// void *src = (char *)imageData + y * width * 4;
|
||||
// void *dst = (char *)lockedRect.pBits + y * lockedRect.Pitch;
|
||||
// memcpy(dst, src, width * 4);
|
||||
//}
|
||||
|
||||
texture->UnlockRect(0);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
int graphics::getWidth()
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
int graphics::getHeight()
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <xtl.h>
|
||||
#include "stdint.h"
|
||||
|
||||
typedef struct {
|
||||
DWORD dwWidth;
|
||||
DWORD dwHeight;
|
||||
BOOL fProgressive;
|
||||
BOOL fWideScreen;
|
||||
DWORD dwFreq;
|
||||
} DISPLAY_MODE;
|
||||
|
||||
class graphics
|
||||
{
|
||||
public:
|
||||
static bool supportsMode(DISPLAY_MODE mode, DWORD dwVideoStandard, DWORD dwVideoFlags);
|
||||
static bool createDevice();
|
||||
static LPDIRECT3DDEVICE8 getDevice();
|
||||
static void swizzle(const void *src, const uint32_t& depth, const uint32_t& width, const uint32_t& height, void *dest);
|
||||
static D3DTexture* createImage(uint8_t* imageData, D3DFORMAT format, int width, int height);
|
||||
static int getWidth();
|
||||
static int getHeight();
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// NuklearOG.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
@@ -0,0 +1,10 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xtl.h>
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef long int32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
Reference in New Issue
Block a user