Skip to content

Commit

Permalink
merged contents
Browse files Browse the repository at this point in the history
  • Loading branch information
EduApps-CDG committed Sep 21, 2023
1 parent 6380022 commit 555849a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 28 deletions.
32 changes: 32 additions & 0 deletions libs/opendx/opendx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ BOOL ShowWindow(HWND window, int nCmdShow) {
return r;
}

BOOL DestroyWindow(HWND window) {
gtk_window_destroy(GTK_WINDOW(window));
return true;
}

BOOL GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax) {
BOOL r = g_main_context_pending(NULL);


//i know this is wrong, but i need to get the sample working
if (r) {
g_main_context_iteration(NULL, true);
} else {
lpMsg->message = WM_QUIT;
}

return r;
}

BOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) {
BOOL r = g_main_context_pending(NULL);

//i know this is wrong, but i need to get the sample working
if (r) {
g_main_context_iteration(NULL, true);
} else {
lpMsg->message = WM_QUIT;
}

return r;
}

/*
* OpenDX utility class
*/
Expand Down
16 changes: 8 additions & 8 deletions prod_include/windef.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
#include <windows.h>

#define WINAPI __stdcall
#define HINSTANCE void*
#define LPSTR char*
#define LPCTSTR const char*
#define HWND GtkWidget
#define HMENU void*

#define DWORD unsigned long
/*
* ref: https://learn.microsoft.com/en-us/windows/win32/api/windef/ns-windef-point
*/
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT, *PPOINT, *NPPOINT, *LPPOINT;
12 changes: 9 additions & 3 deletions prod_include/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#if defined(__GNUC__)
#define __stdcall __attribute__((stdcall))
#endif
#define WINAPI __stdcall
#define __int64 long long

//windows types:
#define WCHAR wchar_t
Expand All @@ -25,18 +27,22 @@
#define LONG long
#define BOOL bool
#define BYTE unsigned char
#define LPCTSTR const char*
#define LPSTR char*
#define LPCSTR const char*
#define LPCTSTR const char*
#define LPCWSTR const char*

#include <stdarg.h>
#include <windef.h>
#include <winnt.h>
//#include <gtk/gtk.h>

#define LPCTSTR const char*
#define DWORD unsigned long
#define HWND void*
#define HWND GtkWidget*
#define HMENU void*
#define HINSTANCE void*
#define LPVOID void*

#define LONG_PTR __int64
#define LPARAM LONG_PTR
#define WPARAM unsigned __int64
24 changes: 24 additions & 0 deletions prod_include/winuser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
#pragma once
#include <windows.h>

/*
* MSG
* ref: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msg
*/
typedef struct tagMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
DWORD lPrivate;
} MSG, *PMSG, *NPMSG, *LPMSG;

#define WM_QUIT 0x0012

/**
* Extended Window Styles
* ref: https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
Expand Down Expand Up @@ -84,8 +100,14 @@ HWND CreateWindowExA(
);

BOOL ShowWindow(HWND window, int nCmdShow);
BOOL DestroyWindow(HWND window);

BOOL PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
#define CreateWindowExW CreateWindowExA
#define PeekMessageW PeekMessageA
#define PM_NOREMOVE 0x0000
#define PM_REMOVE 0x0001
#define PM_NOYIELD 0x0002

// https://www.codeproject.com/Answers/136442/Differences-Between-CreateWindow-and-CreateWindowE#answer3
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
Expand All @@ -96,6 +118,8 @@ CreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, h
//TODO: check if it's needed in a linux environment
#if UNICODE
#define CreateWindow CreateWindowW
#define PeekMessage PeekMessageW
#else
#define CreateWindow CreateWindowA
#define PeekMessage PeekMessageA
#endif
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Run dxdiag from build directory
cd build
./dxdiag
./tests/sample
28 changes: 12 additions & 16 deletions tests/basic_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,33 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
LPDIRECT3DDEVICE9 pDevice = NULL;
D3DPRESENT_PARAMETERS pp;


//wait 5 seconds (Linux):
sleep(5);

/*ZeroMemory(&pp, sizeof(pp));
//ZeroMemory(&pp, sizeof(pp));
pp.Windowed = TRUE;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice);
//pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &pDevice);

// Enter the message loop
MSG msg;
ZeroMemory(&msg, sizeof(msg));
//ZeroMemory(&msg, sizeof(msg));
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
//TranslateMessage(&msg);
//DispatchMessage(&msg);
} else {
// Render the scene
pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
/*pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
pDevice->BeginScene();
pDevice->EndScene();
pDevice->Present(NULL, NULL, NULL, NULL);
pDevice->Present(NULL, NULL, NULL, NULL);*/
}
}

sleep(5);
// Clean up
pDevice->Release();
pD3D->Release();
//pDevice->Release(); //causes a segfault
//pD3D->Release();
DestroyWindow(hWnd);
return msg.wParam;*/
//return msg.wParam;

return 0;
}
Expand Down

0 comments on commit 555849a

Please sign in to comment.