diff --git a/.gitignore b/.gitignore
index fdbb84d..ca32d89 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
xcuserdata
libs
+x64/
+.vs/
+engine.vcxproj.user
diff --git a/engine.sln b/engine.sln
new file mode 100644
index 0000000..58db23c
--- /dev/null
+++ b/engine.sln
@@ -0,0 +1,28 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "engine", "engine.vcxproj", "{6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x64.ActiveCfg = Debug|x64
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x64.Build.0 = Debug|x64
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x86.ActiveCfg = Debug|Win32
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Debug|x86.Build.0 = Debug|Win32
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x64.ActiveCfg = Release|x64
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x64.Build.0 = Release|x64
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x86.ActiveCfg = Release|Win32
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/engine.vcxproj b/engine.vcxproj
new file mode 100644
index 0000000..c5c5c86
--- /dev/null
+++ b/engine.vcxproj
@@ -0,0 +1,177 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ {6D5028CE-4D76-4B6A-A7C2-DE5A3268D433}
+ Win32Proj
+ engine
+ 8.1
+
+
+
+ Application
+ true
+ v140
+ Unicode
+
+
+ Application
+ false
+ v140
+ true
+ Unicode
+
+
+ Application
+ true
+ v140
+ Unicode
+
+
+ Application
+ false
+ v140
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ libs\glm;libs\glew-2.0.0\include;libs\stb;$(IncludePath)
+ libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)
+
+
+ true
+ libs\glm;libs\glew-2.0.0\include;libs\stb;$(IncludePath)
+ libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)
+
+
+ false
+ libs\glm;libs\glew-2.0.0\include;libs\stb;$(IncludePath)
+ libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)
+
+
+ false
+ libs\glm;libs\glew-2.0.0\include;libs\stb;$(IncludePath)
+ libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)
+
+
+
+ Use
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Console
+ true
+
+
+
+
+ Use
+ Level3
+ Disabled
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ Use
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ Use
+ MaxSpeed
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+ Create
+ Create
+ Create
+ Create
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/engine.vcxproj.filters b/engine.vcxproj.filters
new file mode 100644
index 0000000..4ab85ae
--- /dev/null
+++ b/engine.vcxproj.filters
@@ -0,0 +1,60 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/engine/app.cpp b/engine/app.cpp
index 6026137..e772e6d 100644
--- a/engine/app.cpp
+++ b/engine/app.cpp
@@ -58,7 +58,7 @@ void App::init()
circle.create<10>(25, Circle::kUVMapping::Tube);
circle2.create<10>(25, 12, Circle::kUVMapping::Tube);
rounded.create<3>(50, 50, 10);
- slice.create(50, 50, 10, .3);
+ slice.create(50, 50, 10, .3f);
if (!tex.load("data/uvs.jpg"))
printf("error loading image\n");
@@ -66,15 +66,15 @@ void App::init()
glEnable(GL_TEXTURE);
glDisable(GL_DEPTH_TEST);
glPointSize(5);
- glLineWidth(15);
+ glLineWidth(1);
- int n;
- glGetIntegerv(GL_NUM_EXTENSIONS, &n);
- for (int i = 0; i < n; i++)
- {
- const unsigned char* s = glGetStringi(GL_EXTENSIONS, i);
- printf("GL ext %03d: %s\n", i, s);
- }
+ //int n;
+ //glGetIntegerv(GL_NUM_EXTENSIONS, &n);
+ //for (int i = 0; i < n; i++)
+ //{
+ // const unsigned char* s = glGetStringi(GL_EXTENSIONS, i);
+ // printf("GL ext %03d: %s\n", i, s);
+ //}
printf("GL version: %s\n", glGetString(GL_VERSION));
printf("GL vendor: %s\n", glGetString(GL_VENDOR));
printf("GL renderer: %s\n", glGetString(GL_RENDERER));
@@ -94,7 +94,7 @@ void App::update(float dt)
// glm::mat4 model = glm::translate(glm::vec3(0, 0, 0));
// glm::mat4 view = glm::lookAt(glm::vec3(sinf(theta), 0, 1), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
- glm::mat4 proj = glm::ortho(0, width, height, 0, -1, 1);
+ glm::mat4 proj = glm::ortho(0.f, (float)width, (float)height, 0.f, -1.f, 1.f);
Shape* shapes[] = { &circle, &circle2, &plane, &rounded, &slice };
@@ -115,11 +115,11 @@ void App::update(float dt)
tex.unbind();
shader_color.use();
- shader.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 + 120 * 2, 75 + 120 * i, 0.f}) * s);
shader_color.u_vec4("col", {1, 1, 1, 1});
shapes[i]->draw_stroke();
- shader.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 + 120 * 0, 75 + 120 * i, 0.f}) * s);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
shapes[i]->draw_fill();
diff --git a/engine/main.cpp b/engine/main.cpp
index cf99d6e..bb3e403 100644
--- a/engine/main.cpp
+++ b/engine/main.cpp
@@ -5,6 +5,7 @@
#include "image.hpp"
#include "app.hpp"
+#ifdef __APPLE__
#include
#include
#include
@@ -189,3 +190,158 @@ int main(int argc, const char * argv[])
[app run];
return 0;
}
+#endif
+
+#ifdef _WIN32
+
+#pragma comment (lib, "opengl32.lib")
+#pragma comment (lib, "glew32.lib")
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
+HINSTANCE hInst;
+HWND hWnd;
+HDC hDC;
+HGLRC hRC;
+char *className;
+bool keys[256];
+
+int main()
+{
+ WNDCLASSA wc;
+ PIXELFORMATDESCRIPTOR pfd;
+
+ App::I.create();
+ RECT clientRect = { 0, 0, App::I.width, App::I.height };
+
+ // Inizialize data structures to zero
+ memset(&wc, 0, sizeof(wc));
+ memset(&keys, 0, sizeof(keys));
+ memset(&pfd, 0, sizeof(pfd));
+
+ // Create the main window
+
+ hInst = GetModuleHandle(NULL);
+ className = "DrosophilaMain";
+
+ wc.hInstance = hInst;
+ wc.lpfnWndProc = (WNDPROC)WndProc;
+ wc.lpszClassName = className;
+ wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
+
+ RegisterClassA(&wc);
+
+ AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false);
+ hWnd = CreateWindowA(wc.lpszClassName, "New Engine", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left,
+ clientRect.bottom - clientRect.top, 0, 0, hInst, 0);
+ ShowWindow(hWnd, SW_NORMAL);
+
+ // Setup GL Rendering Context
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 32;
+ pfd.cDepthBits = 16;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+
+ hDC = GetDC(hWnd);
+ int pxfmt = ChoosePixelFormat(hDC, &pfd);
+ SetPixelFormat(hDC, pxfmt, &pfd);
+ hRC = wglCreateContext(hDC); // Create OpenGL 2.1 or less
+ wglMakeCurrent(hDC, hRC);
+
+ // Initialize extensions
+ if (glewInit() != GLEW_OK)
+ return 0;
+
+ printf("GL version: %s\n", glGetString(GL_VERSION));
+ printf("GL vendor: %s\n", glGetString(GL_VENDOR));
+ printf("GL renderer: %s\n", glGetString(GL_RENDERER));
+
+ // If supported create a 3.1 context
+ if (wglewIsSupported("WGL_ARB_create_context"))
+ {
+ int attribs[] =
+ {
+ WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
+ WGL_CONTEXT_MINOR_VERSION_ARB, 1,
+ WGL_CONTEXT_FLAGS_ARB, 0,
+ 0
+ };
+ auto oldContext = hRC;
+ hRC = wglCreateContextAttribsARB(hDC, NULL, attribs);
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(oldContext);
+ wglMakeCurrent(hDC, hRC);
+ }
+ else
+ {
+ // If not supported, go fuck yourself we are not gonna use that shit
+ return -1; // A negative number because you are a negative one
+ }
+
+ App::I.init();
+
+ MSG msg;
+ bool running = true;
+ unsigned long t0 = GetTickCount();
+ unsigned long t1;
+ while (running)
+ {
+ // If there any message in the queue process it
+ if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+ {
+ running = !(msg.message == WM_QUIT/* || gl.keys[VK_ESCAPE]*/);
+ DispatchMessage(&msg);
+ TranslateMessage(&msg);
+ }
+ else // Otherwise render next frame
+ {
+ t1 = GetTickCount();
+ float dt = (float)(t1 - t0) / 1000.0f;
+ if (dt > 1.0f / 60.0f)
+ {
+ App::I.update((float)(t1 - t0) / 1000.0f);
+ t0 = t1;
+ SwapBuffers(hDC);
+ }
+ else
+ {
+ Sleep((DWORD)(1.0f / 60.0f * 1000.f));
+ }
+ }
+ }
+
+ // Clean up
+ DestroyWindow(hWnd);
+ UnregisterClassA(className, hInst);
+}
+
+LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg)
+ {
+ case WM_CLOSE:
+ PostQuitMessage(0);
+ break;
+ case WM_KEYDOWN:
+ keys[wp] = true;
+ break;
+ case WM_KEYUP:
+ keys[wp] = false;
+ break;
+ case WM_MOUSEMOVE:
+ //current->pointerMove(LOWORD(lp), HIWORD(lp));
+ break;
+ case WM_LBUTTONDOWN:
+ //current->pointerDown(LOWORD(lp), HIWORD(lp));
+ break;
+ case WM_LBUTTONUP:
+ //current->pointerUp(LOWORD(lp), HIWORD(lp));
+ break;
+ }
+ return DefWindowProc(hWnd, msg, wp, lp);
+}
+
+#endif
diff --git a/engine/pch.cpp b/engine/pch.cpp
new file mode 100644
index 0000000..1d9f38c
--- /dev/null
+++ b/engine/pch.cpp
@@ -0,0 +1 @@
+#include "pch.h"
diff --git a/engine/pch.h b/engine/pch.h
index b3dd34a..102ff13 100644
--- a/engine/pch.h
+++ b/engine/pch.h
@@ -1,17 +1,27 @@
-#ifndef pch_h
-#define pch_h
+#pragma once
-#include
-#include
+#ifdef __APPLE__
+ #include
+ #include
+#elif _WIN32
+ #define _USE_MATH_DEFINES
+ #include
+ #include
+ #include
+ #include
+#endif
+#include
+#include
+#include
#include
#define GLM_FORCE_RADIANS
-#define GLM_SWIZZLE
+#define GLM_FORCE_SWIZZLE
+#define GLM_FORCE_MESSAGES
+#define GLM_ENABLE_EXPERIMENTAL
#include
#include
#include
#include
#include
-
-#endif
diff --git a/engine/shape.cpp b/engine/shape.cpp
index 663039d..b951fe5 100644
--- a/engine/shape.cpp
+++ b/engine/shape.cpp
@@ -106,7 +106,7 @@ void Circle::create_impl(float radius, int div, GLushort* idx, vertex_t* vertice
for (int i = 0; i < div; i++)
{
vertex_t v;
- float theta = (float)i / div * M_PI * 2.f;
+ float theta = (float)i / div * (float)M_PI * 2.f;
glm::vec2 uv = { sinf(theta), cosf(theta) };
v.pos = glm::vec4(uv * radius, 0, 1);
v.uvs = (map == kUVMapping::Planar) ? (uv * 0.5f + 0.5f) : glm::vec2((float)i / div, 1.f);
@@ -134,7 +134,7 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
auto pidx2 = idx + count[0];
for (int i = 0; i < div; i++)
{
- float theta = (float)(i%(div-1)) / (div-1) * M_PI * 2.f;
+ float theta = (float)(i%(div-1)) / (div-1) * (float)M_PI * 2.f;
glm::vec2 uv = { sinf(theta), cosf(theta) };
if (map == kUVMapping::Planar)
{