enable multi sampling in Windows, fix circle shape
This commit is contained in:
@@ -55,8 +55,10 @@ void App::init()
|
|||||||
shader_color.create(shader_color_v, shader_color_f);
|
shader_color.create(shader_color_v, shader_color_f);
|
||||||
shader_uv.create(shader_v, shader_uv_f);
|
shader_uv.create(shader_v, shader_uv_f);
|
||||||
plane.create<5>(50, 50);
|
plane.create<5>(50, 50);
|
||||||
circle.create<10>(25, Circle::kUVMapping::Tube);
|
circle.create<10>(25);
|
||||||
circle2.create<10>(25, 12, Circle::kUVMapping::Tube);
|
circle2.create<10>(25, Circle::kUVMapping::Tube);
|
||||||
|
circle3.create<10>(25, 12, Circle::kUVMapping::Tube);
|
||||||
|
circle4.create<10>(25, 12, Circle::kUVMapping::Planar);
|
||||||
rounded.create<3>(50, 50, 10);
|
rounded.create<3>(50, 50, 10);
|
||||||
slice.create(50, 50, 10, .3f);
|
slice.create(50, 50, 10, .3f);
|
||||||
if (!tex.load("data/uvs.jpg"))
|
if (!tex.load("data/uvs.jpg"))
|
||||||
@@ -96,13 +98,14 @@ void App::update(float dt)
|
|||||||
|
|
||||||
glm::mat4 proj = glm::ortho(0.f, (float)width, (float)height, 0.f, -1.f, 1.f);
|
glm::mat4 proj = glm::ortho(0.f, (float)width, (float)height, 0.f, -1.f, 1.f);
|
||||||
|
|
||||||
Shape* shapes[] = { &circle, &circle2, &plane, &rounded, &slice };
|
Shape* shapes[] = { &circle, &circle2, &circle3, &circle4, &plane, &rounded, &slice };
|
||||||
|
|
||||||
//glClearColor(red, 0, 0, 1);
|
//glClearColor(red, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
auto s = glm::scale(glm::vec3(2));
|
auto s = glm::scale(glm::vec3(1.5));
|
||||||
for (int i = 0; i < 5; i++)
|
int h = 100;
|
||||||
|
for (int i = 0; i < sizeof(shapes)/sizeof(Shape*); i++)
|
||||||
{
|
{
|
||||||
shader.use();
|
shader.use();
|
||||||
|
|
||||||
@@ -110,32 +113,45 @@ void App::update(float dt)
|
|||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
tex.bind();
|
tex.bind();
|
||||||
shader.u_int("tex", 0);
|
shader.u_int("tex", 0);
|
||||||
shader.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 1, 75 + 120 * i, 0.f}) * s);
|
shader.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + h * 1, 75 + h * i, 0.f}) * s);
|
||||||
shapes[i]->draw_fill();
|
shapes[i]->draw_fill();
|
||||||
tex.unbind();
|
tex.unbind();
|
||||||
|
|
||||||
shader_color.use();
|
shader_color.use();
|
||||||
shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 2, 75 + 120 * i, 0.f}) * s);
|
shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + h * 2, 75 + h * i, 0.f}) * s);
|
||||||
shader_color.u_vec4("col", {1, 1, 1, 1});
|
shader_color.u_vec4("col", {1, 1, 1, 1});
|
||||||
shapes[i]->draw_stroke();
|
shapes[i]->draw_stroke();
|
||||||
|
|
||||||
shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 0, 75 + 120 * i, 0.f}) * s);
|
shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + h * 0, 75 + h * i, 0.f}) * s);
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
shapes[i]->draw_fill();
|
shapes[i]->draw_fill();
|
||||||
|
|
||||||
shader_uv.use();
|
shader_uv.use();
|
||||||
shader_uv.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 3, 75 + 120 * i, 0.f}) * s);
|
shader_uv.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + h * 3, 75 + h * i, 0.f}) * s);
|
||||||
shader_uv.u_int("tex", 0);
|
shader_uv.u_int("tex", 0);
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
shapes[i]->draw_fill();
|
shapes[i]->draw_fill();
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
shader_uv.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 4, 75 + 120 * i, 0.f}) * s);
|
shader_uv.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + h * 4, 75 + h * i, 0.f}) * s);
|
||||||
shapes[i]->draw_fill();
|
shapes[i]->draw_fill();
|
||||||
tex.unbind();
|
tex.unbind();
|
||||||
}
|
}
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
// shader_color.use();
|
//shader_color.use();
|
||||||
// shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{width/2, height/2, 0.f}) * glm::scale(glm::vec3(8)));
|
//shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{width/2, height/2, 0.f}) * glm::scale(glm::vec3(8)));
|
||||||
// shader_color.u_vec4("col", {1, 1, 1, 1});
|
//shader_color.u_vec4("col", {1, 1, 1, 1});
|
||||||
// slice.draw_fill();
|
|
||||||
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
//tex.bind();
|
||||||
|
//shader.use();
|
||||||
|
//shader.u_mat4("mvp", proj * glm::translate(glm::vec3{ width / 2, height / 2, 0.f }) * glm::scale(glm::vec3(8)));
|
||||||
|
//shader.u_int("tex", 0);
|
||||||
|
//circle3.draw_fill();
|
||||||
|
|
||||||
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
//shader_color.use();
|
||||||
|
//shader_color.u_mat4("mvp", proj * glm::translate(glm::vec3{width/2, height/2, 0.f}) * glm::scale(glm::vec3(8)));
|
||||||
|
//shader_color.u_vec4("col", {1, 1, 1, 1});
|
||||||
|
//glLineWidth(2);
|
||||||
|
//circle3.draw_fill();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class App
|
|||||||
Shader shader_color;
|
Shader shader_color;
|
||||||
Shader shader_uv;
|
Shader shader_uv;
|
||||||
Plane plane;
|
Plane plane;
|
||||||
Circle circle, circle2;
|
Circle circle, circle2, circle3, circle4;
|
||||||
Rounded rounded;
|
Rounded rounded;
|
||||||
Slice9 slice;
|
Slice9 slice;
|
||||||
Texture2D tex;
|
Texture2D tex;
|
||||||
|
|||||||
@@ -202,12 +202,12 @@ HINSTANCE hInst;
|
|||||||
HWND hWnd;
|
HWND hWnd;
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
HGLRC hRC;
|
HGLRC hRC;
|
||||||
char *className;
|
wchar_t* className;
|
||||||
bool keys[256];
|
bool keys[256];
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
WNDCLASSA wc;
|
WNDCLASS wc;
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
|
|
||||||
App::I.create();
|
App::I.create();
|
||||||
@@ -221,20 +221,19 @@ int main()
|
|||||||
// Create the main window
|
// Create the main window
|
||||||
|
|
||||||
hInst = GetModuleHandle(NULL);
|
hInst = GetModuleHandle(NULL);
|
||||||
className = "DrosophilaMain";
|
className = L"EngineMain";
|
||||||
|
|
||||||
wc.hInstance = hInst;
|
wc.hInstance = hInst;
|
||||||
wc.lpfnWndProc = (WNDPROC)WndProc;
|
wc.lpfnWndProc = (WNDPROC)WndProc;
|
||||||
wc.lpszClassName = className;
|
wc.lpszClassName = className;
|
||||||
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
||||||
|
|
||||||
RegisterClassA(&wc);
|
RegisterClass(&wc);
|
||||||
|
|
||||||
AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false);
|
AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false);
|
||||||
hWnd = CreateWindowA(wc.lpszClassName, "New Engine", WS_OVERLAPPEDWINDOW,
|
hWnd = CreateWindow(wc.lpszClassName, L"New Engine", WS_OVERLAPPEDWINDOW,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left,
|
CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left,
|
||||||
clientRect.bottom - clientRect.top, 0, 0, hInst, 0);
|
clientRect.bottom - clientRect.top, 0, 0, hInst, 0);
|
||||||
ShowWindow(hWnd, SW_NORMAL);
|
|
||||||
|
|
||||||
// Setup GL Rendering Context
|
// Setup GL Rendering Context
|
||||||
pfd.nSize = sizeof(pfd);
|
pfd.nSize = sizeof(pfd);
|
||||||
@@ -262,17 +261,41 @@ int main()
|
|||||||
// If supported create a 3.1 context
|
// If supported create a 3.1 context
|
||||||
if (wglewIsSupported("WGL_ARB_create_context"))
|
if (wglewIsSupported("WGL_ARB_create_context"))
|
||||||
{
|
{
|
||||||
int attribs[] =
|
int contex_attribs[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
||||||
WGL_CONTEXT_FLAGS_ARB, 0,
|
WGL_CONTEXT_FLAGS_ARB, 0,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
auto oldContext = hRC;
|
int pixel_attribs[] =
|
||||||
hRC = wglCreateContextAttribsARB(hDC, NULL, attribs);
|
{
|
||||||
|
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
|
||||||
|
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
|
||||||
|
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
|
||||||
|
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
|
||||||
|
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
||||||
|
WGL_COLOR_BITS_ARB, 32,
|
||||||
|
WGL_DEPTH_BITS_ARB, 24,
|
||||||
|
WGL_STENCIL_BITS_ARB, 8,
|
||||||
|
WGL_SAMPLE_BUFFERS_ARB, 1, // Number of buffers (must be 1 at time of writing)
|
||||||
|
WGL_SAMPLES_ARB, 4, // Number of samples
|
||||||
|
0
|
||||||
|
};
|
||||||
|
UINT numFormat;
|
||||||
|
|
||||||
wglMakeCurrent(NULL, NULL);
|
wglMakeCurrent(NULL, NULL);
|
||||||
wglDeleteContext(oldContext);
|
wglDeleteContext(hRC);
|
||||||
|
DestroyWindow(hWnd);
|
||||||
|
|
||||||
|
hWnd = CreateWindow(wc.lpszClassName, L"New Engine", WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left,
|
||||||
|
clientRect.bottom - clientRect.top, 0, 0, hInst, 0);
|
||||||
|
|
||||||
|
hDC = GetDC(hWnd);
|
||||||
|
wglChoosePixelFormatARB(hDC, pixel_attribs, nullptr, 1, &pxfmt, &numFormat);
|
||||||
|
SetPixelFormat(hDC, pxfmt, &pfd);
|
||||||
|
hRC = wglCreateContextAttribsARB(hDC, NULL, contex_attribs);
|
||||||
wglMakeCurrent(hDC, hRC);
|
wglMakeCurrent(hDC, hRC);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -283,6 +306,8 @@ int main()
|
|||||||
|
|
||||||
App::I.init();
|
App::I.init();
|
||||||
|
|
||||||
|
ShowWindow(hWnd, SW_NORMAL);
|
||||||
|
|
||||||
MSG msg;
|
MSG msg;
|
||||||
bool running = true;
|
bool running = true;
|
||||||
unsigned long t0 = GetTickCount();
|
unsigned long t0 = GetTickCount();
|
||||||
@@ -315,7 +340,7 @@ int main()
|
|||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
DestroyWindow(hWnd);
|
DestroyWindow(hWnd);
|
||||||
UnregisterClassA(className, hInst);
|
UnregisterClass(className, hInst);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ void Circle::create_impl(float radius, int div, GLushort* idx, vertex_t* vertice
|
|||||||
|
|
||||||
void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* idx, vertex_t* vertices, kUVMapping map)
|
void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* idx, vertex_t* vertices, kUVMapping map)
|
||||||
{
|
{
|
||||||
count[0] = div * 6;
|
count[0] = div * (radius_in == 0.f ? 3 : 6);
|
||||||
count[1] = div * 4;
|
count[1] = div * 4;
|
||||||
ioff[0] = (GLvoid*)0;
|
ioff[0] = (GLvoid*)0;
|
||||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||||
@@ -143,8 +143,8 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vertices[i*2].uvs = { (float)i / div, 0.f };
|
vertices[i*2].uvs = { (float)i / div, 0.f }; // inner
|
||||||
vertices[i*2+1].uvs = { (float)i / div, 1.f};
|
vertices[i*2+1].uvs = { (float)i / div, 1.f};// outer
|
||||||
}
|
}
|
||||||
vertices[i*2].pos = glm::vec4(uv * radius_in, 0, 1);
|
vertices[i*2].pos = glm::vec4(uv * radius_in, 0, 1);
|
||||||
vertices[i*2+1].pos = glm::vec4(uv * radius_out, 0, 1);
|
vertices[i*2+1].pos = glm::vec4(uv * radius_out, 0, 1);
|
||||||
@@ -156,15 +156,15 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
|
|||||||
if (radius_in != 0.f)
|
if (radius_in != 0.f)
|
||||||
{
|
{
|
||||||
*pidx++ = i * 2; // A
|
*pidx++ = i * 2; // A
|
||||||
*pidx++ = ((i + 1) * 2 + 1) % (div * 2); // C
|
*pidx++ = ((i+1)*2+1) % (div*2); // C
|
||||||
*pidx++ = ((i + 1) * 2) % (div * 2); // D
|
*pidx++ = ((i+1)*2) % (div*2); // D
|
||||||
}
|
}
|
||||||
|
|
||||||
*pidx2++ = i*2; // A
|
*pidx2++ = i*2; // A
|
||||||
*pidx2++ = ((i+1)*2) % (div*2); // D
|
*pidx2++ = ((i+1)*2) % (div*2); // D
|
||||||
|
|
||||||
*pidx2++ = i*2+1; // B
|
*pidx2++ = i*2+1; // B
|
||||||
*pidx2++ = ((i+1)*2+1) % (div*2);// C
|
*pidx2++ = ((i+1)*2+1) % (div*2); // C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,15 +37,15 @@ public:
|
|||||||
{
|
{
|
||||||
static GLushort idx[div*3 + div*2];
|
static GLushort idx[div*3 + div*2];
|
||||||
static vertex_t vertices[div+1];
|
static vertex_t vertices[div+1];
|
||||||
create_impl(radius, div, idx, vertices, kUVMapping::Planar);
|
create_impl(radius, div, idx, vertices);
|
||||||
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
||||||
}
|
}
|
||||||
template<int div>
|
template<int div>
|
||||||
bool create(float radius, kUVMapping map)
|
bool create(float radius, kUVMapping map)
|
||||||
{
|
{
|
||||||
static GLushort idx[div*3 + div*2];
|
static GLushort idx[(div+1)*3 + (div+1)*4];
|
||||||
static vertex_t vertices[div*2];
|
static vertex_t vertices[(div+1)*2];
|
||||||
create_impl(radius, 0.f, div, idx, vertices, map);
|
create_impl(radius, 0.f, (div+1), idx, vertices, map);
|
||||||
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
||||||
}
|
}
|
||||||
template<int div>
|
template<int div>
|
||||||
|
|||||||
Reference in New Issue
Block a user