base setup for osx in place
This commit is contained in:
102
engine/app.cpp
Normal file
102
engine/app.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "pch.h"
|
||||
#include "app.hpp"
|
||||
|
||||
App App::I; // singleton
|
||||
|
||||
void App::create()
|
||||
{
|
||||
width = 800;
|
||||
height = 600;
|
||||
}
|
||||
|
||||
void App::init()
|
||||
{
|
||||
static const char* shader_v =
|
||||
"#version 150\n"
|
||||
"uniform mat4 mvp;"
|
||||
"in vec4 pos;"
|
||||
"in vec2 uvs;"
|
||||
"out vec2 uv;"
|
||||
"void main(){"
|
||||
" gl_Position = mvp * pos;"
|
||||
" uv = uvs;"
|
||||
"}";
|
||||
static const char* shader_f =
|
||||
"#version 150\n"
|
||||
"uniform sampler2D tex;"
|
||||
"in vec2 uv;"
|
||||
"out vec4 frag;"
|
||||
"void main(){"
|
||||
" frag = texture(tex, uv, 0.0);"
|
||||
"}";
|
||||
static const char* shader_color_v =
|
||||
"#version 150\n"
|
||||
"uniform mat4 mvp;"
|
||||
"in vec4 pos;"
|
||||
"void main(){"
|
||||
" gl_Position = mvp * pos;"
|
||||
"}";
|
||||
static const char* shader_color_f =
|
||||
"#version 150\n"
|
||||
"uniform vec4 col;"
|
||||
"out vec4 frag;"
|
||||
"void main(){"
|
||||
" frag = col;"
|
||||
"}";
|
||||
shader.create(shader_v, shader_f);
|
||||
shader_color.create(shader_color_v, shader_color_f);
|
||||
plane.create<15>(.5f, .5f);
|
||||
longPlane.create<1>(.3, .05f);
|
||||
circle.create<6>(.5f);
|
||||
if (!tex.load("data/image.png"))
|
||||
printf("error loading image\n");
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
glEnable(GL_TEXTURE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glPointSize(5);
|
||||
glLineWidth(15);
|
||||
|
||||
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));
|
||||
|
||||
GLfloat width_range[2];
|
||||
glGetFloatv(GL_LINE_WIDTH_RANGE, width_range);
|
||||
printf("GL line range: %f - %f\n", width_range[0], width_range[1]);
|
||||
}
|
||||
|
||||
void App::update(float dt)
|
||||
{
|
||||
static float theta = 0;
|
||||
theta += M_PI * 0.5f * dt;
|
||||
float red = fabsf(sinf(theta));
|
||||
|
||||
glm::mat4 proj = glm::perspective(glm::radians(85.f), 1.f, .1f, 100.f);
|
||||
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));
|
||||
auto mvp = proj * view * model;
|
||||
|
||||
glClearColor(red, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
shader.use();
|
||||
shader.u_mat4("mvp", glm::mat4());
|
||||
shader.u_int("tex", 0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
tex.bind();
|
||||
//circle.draw_fill();
|
||||
tex.unbind();
|
||||
|
||||
shader_color.use();
|
||||
shader_color.u_mat4("mvp", glm::mat4());
|
||||
shader_color.u_vec4("col", {1, 1, 1, 1});
|
||||
circle.draw_stroke();
|
||||
}
|
||||
Reference in New Issue
Block a user