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 | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 41023ea..e532658 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -33,13 +33,15 @@ string vert = R"( in vec2 position; in vec2 uv; -uniform mat4 asura_mvp; +uniform mat4 asura_projection_matrix; +uniform mat4 asura_model_matrix; +uniform mat4 asura_view_matrix; out vec2 texCoord; void main() { - gl_Position = asura_mvp * vec4(position, 0, 1); + gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(position, 0, 1); texCoord = uv; } )"; @@ -62,7 +64,9 @@ struct { int pos; int tex; - int mvp; + int m; + int v; + int p; int color; } locs; @@ -123,16 +127,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, case WM_SIZE: { - if (gl.Inited()) + if (gfx.Inited()) { RECT rect; GetClientRect(hwnd, &rect); viewport.Set(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); - gl.SetViewport(viewport); + gfx.SetViewport(viewport); } } case WM_PAINT: - if (!gl.Inited()) + if (!gfx.Inited()) break; glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); @@ -157,27 +161,28 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, { int imgLoc = shader->GetUniformLocation("img"); - int code = gl.GetError(); - gl.UseShader(shader); + int code = gfx.GetError(); + gfx.UseShader(shader); shader->SetUniformTexture(imgLoc, *img); - gl.SetMatrixMode(MATRIX_MODE_PROJECTION); - gl.LoadIdentity(); - gl.Ortho(0, viewport.w, viewport.h, 0, -1, 1); - gl.SetMatrixMode(MATRIX_MODE_MODEL); - gl.LoadIdentity(); - gl.Translate(100, 100); - gl.SetDrawColor(1, 1, 1, 1); - shader->SetBuiltInMVPMatrix(locs.mvp); - shader->SetBuiltInDrawColor(locs.color); + gfx.SetMatrixMode(MATRIX_MODE_PROJECTION); + gfx.LoadIdentity(); + gfx.Ortho(0, viewport.w, viewport.h, 0, -1, 1); + gfx.SetMatrixMode(MATRIX_MODE_MODEL); + gfx.LoadIdentity(); + gfx.Translate(100, 100); + shader->SetUniformMatrix44(locs.m, gfx.GetMatrix(MATRIX_MODE_MODEL)); + shader->SetUniformMatrix44(locs.v, gfx.GetMatrix(MATRIX_MODE_VIEW)); + shader->SetUniformMatrix44(locs.p, gfx.GetMatrix(MATRIX_MODE_PROJECTION)); shader->SetAttribute(locs.pos, vb, 0, 4); shader->SetAttribute(locs.tex, vb, 2, 4); - + gfx.SetDrawColor(1, 1, 0, 1); + shader->SetUniformColor(locs.color, gfx.GetDrawColor()); //glLineWidth(1); - gl.DrawArrays(GL_LINE_STRIP, 0, 5); - //gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); + gfx.DrawArrays(GL_LINE_STRIP, 0, 5); + //gfx.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); shader->DisableAttribute(locs.pos); shader->DisableAttribute(locs.tex); - gl.UnuseShader(); + gfx.UnuseShader(); } glFlush(); BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); @@ -211,9 +216,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, wglMakeCurrent(hdc, glc); RECT rect; - GetClientRect(hwnd, &rect); + GetWindowRect(hwnd, &rect); viewport.Set(0, 0, rect.right - rect.left, rect.bottom - rect.top); - if (!gl.Init(viewport)) + if (!gfx.Init(viewport)) return 0; imgdata->Decode(db); @@ -227,7 +232,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, imgdata->Decode(db); img->Load(imgdata, {50, 100}); imgdata->Release(); - + // shader shader = new Shader(); shader->Load(vert, frag); @@ -250,7 +255,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, vb = new VertexBuffer(BUFFER_USAGE_STATIC, BUFFER_DATA_TYPE_FLOAT, sizeof(v)); vb->Fill(v, sizeof(v)); }; - locs.mvp = shader->GetUniformLocation("asura_mvp"); + locs.m = shader->GetUniformLocation("asura_model_matrix"); + locs.v = shader->GetUniformLocation("asura_view_matrix"); + locs.p = shader->GetUniformLocation("asura_projection_matrix"); locs.color = shader->GetUniformLocation("color"); locs.pos = shader->GetAttributeLocation("position"); locs.tex = shader->GetAttributeLocation("uv"); |