diff options
author | chai <chaifix@163.com> | 2019-05-02 21:42:09 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-05-02 21:42:09 +0800 |
commit | 59a0e32991b5b714b6bdba504b6fbacdcd4b907a (patch) | |
tree | 763d10da51491ea88416e159651e97c9193673d8 /source/tests/win32/01-window/03_sub_menu.cpp | |
parent | 866e00474be3bfe0e7dac73b720af0b9ebf7109a (diff) |
*misc
Diffstat (limited to 'source/tests/win32/01-window/03_sub_menu.cpp')
-rw-r--r-- | source/tests/win32/01-window/03_sub_menu.cpp | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index ba384cb..9ddc8d7 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -30,8 +30,8 @@ AEMath::Recti viewport; string vert = R"( -in vec2 asura_position; -in vec2 asura_texcoord0; +in vec2 position; +in vec2 uv; uniform mat4 asura_projection_matrix; uniform mat4 asura_model_matrix; @@ -41,23 +41,35 @@ out vec2 texCoord; void main() { - texCoord = asura_texcoord0; - gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1); + gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(position, 0, 1); + texCoord = uv; } )"; string frag = R"( in vec2 texCoord; uniform sampler2D img; +uniform vec4 color ; void main() { - gl_FragColor = texture2D(img, texCoord); + //gl_FragColor = color * texture2D(img, texCoord); + gl_FragColor = color; } )"; Shader* shader; VertexBuffer* vb; +struct +{ + int pos; + int tex; + int m; + int v; + int p; + int color; +} locs; + struct Vert { float x, y; // position @@ -118,8 +130,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, if (gl.Inited()) { RECT rect; - GetWindowRect(hwnd, &rect); - viewport.Set(0, 0, rect.right - rect.left, rect.bottom - rect.top); + GetClientRect(hwnd, &rect); + viewport.Set(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); gl.SetViewport(viewport); } } @@ -140,8 +152,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, glBindTexture(GL_TEXTURE_2D, tex); // + // Χ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + // ˲ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -154,11 +168,20 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, gl.LoadIdentity(); gl.Ortho(0, viewport.w, viewport.h, 0, -1, 1); gl.SetMatrixMode(MATRIX_MODE_MODEL); - gl.Translate(1, 0); - shader->SetBuiltInUniforms(); - shader->SetAttribPosition(vb, 0, 4); - shader->SetAttribTexcoord0(vb, 2, 4); - gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); + gl.LoadIdentity(); + gl.Translate(100, 100); + shader->SetUniformMatrix44(locs.m, gl.GetMatrix(MATRIX_MODE_MODEL)); + shader->SetUniformMatrix44(locs.v, gl.GetMatrix(MATRIX_MODE_VIEW)); + shader->SetUniformMatrix44(locs.p, gl.GetMatrix(MATRIX_MODE_PROJECTION)); + shader->SetAttribute(locs.pos, vb, 0, 4); + shader->SetAttribute(locs.tex, vb, 2, 4); + gl.SetDrawColor(1, 1, 0, 1); + shader->SetUniformColor(locs.color, gl.GetDrawColor()); + //glLineWidth(1); + gl.DrawArrays(GL_LINE_STRIP, 0, 5); + //gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4); + shader->DisableAttribute(locs.pos); + shader->DisableAttribute(locs.tex); gl.UnuseShader(); } glFlush(); @@ -216,15 +239,28 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, { int w = img->GetWidth(); int h = img->GetHeight(); + //Vert v[] = { + // { 0.5f, 0.5f, 0, 0 }, + //{ 0.5f, h + 0.5f, 0, 1 }, + //{ w + 0.5f, 0.5f, 1, 0 }, + //{ w + 0.5f, h + 0.5f, 1, 1 }, + //}; Vert v[] = { { 0.5f, 0.5f, 0, 0 }, - { 0.5f, h + 0.5f, 0, 1 }, - { w + 0.5f, 0.5f, 1, 0 }, + { 0.5f, h + 55.8f, 0, 1 }, { w + 0.5f, h + 0.5f, 1, 1 }, + { w + 0.5f, 0.5f, 1, 0 }, + { 0.5f, 0.5f, 0, 0 }, }; vb = new VertexBuffer(BUFFER_USAGE_STATIC, BUFFER_DATA_TYPE_FLOAT, sizeof(v)); vb->Fill(v, sizeof(v)); }; + 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"); break; |