diff options
Diffstat (limited to 'source/tests/win32/01-window/03_sub_menu.cpp')
-rw-r--r-- | source/tests/win32/01-window/03_sub_menu.cpp | 91 |
1 files changed, 67 insertions, 24 deletions
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 848c82e..bd3f7b6 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -1,9 +1,14 @@ #include "config.h" #if _run_app == _sub_menu -#include <windows.h> -#include <GL/gl.h> -#include <GL/glu.h> +#include <asura-utils/io/file_system.h> +#include <asura-utils/io/data_buffer.h> +#include <asura-core/graphics/image.h> +#include <asura-core/image/image_data.h> +#include <SDL2/SDL.h> + +using namespace AEIO; +using namespace AEGraphics; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void AddMenus(HWND); @@ -16,9 +21,10 @@ void AddMenus(HWND); #define IDM_ASSET 20 -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - PWSTR lpCmdLine, int nCmdShow) { +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) +{ + AEIO::Filesystem::Get()->Init("D:\Asura\bin\win64"); MSG msg; WNDCLASSW wc = { 0 }; wc.lpszClassName = L"Submenu"; @@ -28,9 +34,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wc.hCursor = LoadCursor(0, IDC_ARROW); RegisterClassW(&wc); - CreateWindowW(wc.lpszClassName, L"The Incredible Asura", + CreateWindowW(wc.lpszClassName, L"Asura v0.1", WS_OVERLAPPEDWINDOW | WS_VISIBLE, - 100, 100, 350, 250, 0, 0, hInstance, 0); + 200, 200, 550, 450, 0, 0, hInstance, 0); while (GetMessage(&msg, NULL, 0, 0)) { @@ -51,6 +57,11 @@ HPEN hPen; HPEN hOldPen; PIXELFORMATDESCRIPTOR pfd; int pf; +File* file; +DataBuffer db(102400); +AEIO::Filesystem* fs; +ImageData* imgdata = new ImageData(); +Image* img; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -61,8 +72,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, AddMenus(hwnd); hdc = GetDC(hwnd); - glc = wglCreateContext(hdc); - memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; @@ -73,10 +82,28 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, pf = ChoosePixelFormat(hdc, &pfd); SetPixelFormat(hdc, pf, &pfd); DescribePixelFormat(hdc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - ReleaseDC(hwnd, hdc); + //ReleaseDC(hwnd, hdc); + //glc = wglCreateContext(hdc); glc = wglCreateContext(hdc); + + // ͼƬ + fs = AEIO::Filesystem::Get(); + fs->Mount(".", "root"); + file = new File("root/img.png"); + file->Open(File::FILE_MODE_READ); + file->ReadAll(&db); + wglMakeCurrent(hdc, glc); + if (!gladLoadGL()) + { + return 0; + } + + imgdata->Decode(db); + img = new Image(); + img->Refresh(imgdata); + break; case WM_COMMAND: @@ -102,22 +129,38 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, case WM_PAINT: - //hdc = BeginPaint(hwnd, &ps); - //hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); - //hOldPen = (HPEN)SelectObject(hdc, hPen); - //hBrush = CreateSolidBrush(RGB(0, 0, 255)); - //hOldBrush = (HBRUSH)SelectObject(hdc, hBrush); - //Rectangle(hdc, 100, 100, 200, 170); - //EndPaint(hwnd, &ps); - hdc = GetDC(hwnd); - glc = wglCreateContext(hdc); - wglMakeCurrent(hdc, glc); + //hdc = GetDC(hwnd); + //glc = wglCreateContext(hdc); glClearColor(0.16, 0.16, 0.16, 1); - glClear(GL_COLOR_BUFFER_BIT); glColor4f(0.219, 0.219, 0.219, 1); - glRectf(-0.5f, -0.5f, 0.5f, 0.5f); //ƾ - glFlush(); //ִOpenGLָбеָ - wglMakeCurrent(NULL, NULL); + //glRectf(-0.5f, -0.5f, 0.5f, 0.5f); + glColor4f( 1, 1, 1, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + GLint tex = img->GetGLTextureHandle(); + + glBindTexture(GL_TEXTURE_2D, tex); // + glEnable(GL_TEXTURE_2D); //2Dӳ + + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //Sͼ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //Tͼ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //Ŵ˷ʽ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //С˷ʽ + + + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 0.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(0.5f, -0.5f, 0.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 0.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-0.5f, 0.5f, 0.0f); + glEnd(); + + glFlush(); BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; } |