create visual studio project, add Windows initialization code

This commit is contained in:
2017-01-17 20:20:12 +00:00
parent f1e6fb7716
commit c93c1daecc
9 changed files with 456 additions and 21 deletions

View File

@@ -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<float>(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();

View File

@@ -5,6 +5,7 @@
#include "image.hpp"
#include "app.hpp"
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <Cocoa/Cocoa.h>
#include <CoreVideo/CoreVideo.h>
@@ -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

1
engine/pch.cpp Normal file
View File

@@ -0,0 +1 @@
#include "pch.h"

View File

@@ -1,17 +1,27 @@
#ifndef pch_h
#define pch_h
#pragma once
#include <OpenGL/gl.h>
#include <OpenGL/gl3.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/gl3.h>
#elif _WIN32
#define _USE_MATH_DEFINES
#include <windows.h>
#include <gl\glew.h>
#include <gl\wglew.h>
#include <gl\GL.h>
#endif
#include <cmath>
#include <memory>
#include <string>
#include <iostream>
#define GLM_FORCE_RADIANS
#define GLM_SWIZZLE
#define GLM_FORCE_SWIZZLE
#define GLM_FORCE_MESSAGES
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/euler_angles.hpp>
#endif

View File

@@ -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)
{