First steps
Rendering a blue background using DirectX9
This commit is contained in:
@@ -7,7 +7,7 @@ project "LearnDirectX"
|
||||
targetdir "bin/%{cfg.buildcfg}"
|
||||
architecture "x64"
|
||||
|
||||
links {"glfw3"}
|
||||
links {"glfw3", "d3d9"}
|
||||
|
||||
libdirs{ "vendor/GLFW/lib"}
|
||||
includedirs {"vendor/GLFW/include"}
|
||||
|
||||
58
src/main.cpp
58
src/main.cpp
@@ -1,5 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <Windows.h>
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "GLFW/glfw3native.h"
|
||||
#include <d3d9.h>
|
||||
LPDIRECT3D9 d3d; // pointer to our Direct3D interface
|
||||
LPDIRECT3DDEVICE9 d3ddev; // pointer to the device class
|
||||
|
||||
void initD3D(HWND hWnd) {
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface
|
||||
|
||||
D3DPRESENT_PARAMETERS d3dpp; // create the strcut to hold device info
|
||||
|
||||
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear the struct
|
||||
d3dpp.Windowed = TRUE;
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
d3dpp.hDeviceWindow = hWnd;
|
||||
|
||||
// create a device class using the information gathered
|
||||
d3d->CreateDevice(D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
hWnd,
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
||||
&d3dpp,
|
||||
&d3ddev);
|
||||
}
|
||||
|
||||
|
||||
void render_frame() {
|
||||
d3ddev->Clear(0, nullptr, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
|
||||
d3ddev->BeginScene();
|
||||
// do 3D rendering
|
||||
d3ddev->EndScene();
|
||||
|
||||
d3ddev->Present(NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void cleanD3D() {
|
||||
d3ddev->Release();
|
||||
d3d->Release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void error_callback(int code , const char* description) {
|
||||
std::cerr << description << std::endl;
|
||||
@@ -19,20 +61,28 @@ int main ( int argc , char** argv){
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
|
||||
window = glfwCreateWindow(640, 480, "LearnDirectX", nullptr, nullptr);
|
||||
|
||||
|
||||
|
||||
if (!window) {
|
||||
std::cout << "Failed to create window!" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
HWND NativeWindowHandle = glfwGetWin32Window(window);
|
||||
|
||||
|
||||
initD3D(NativeWindowHandle);
|
||||
|
||||
|
||||
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
|
||||
render_frame();
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
cleanD3D();
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user