Skip to content

Commit

Permalink
changes in boilerplate code
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriousSamV committed Feb 24, 2017
1 parent 97d5e82 commit 3c0998a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 66 deletions.
5 changes: 5 additions & 0 deletions lib/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ class CameraController
}
};

#if _WIN32
__declspec(selectany) double CameraController::sxoffset = 0;
__declspec(selectany) double CameraController::syoffset = 0;
#else
double CameraController::sxoffset = 0;
double CameraController::syoffset = 0;
#endif

} // namespace mylib

Expand Down
73 changes: 7 additions & 66 deletions lib/mylib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@

#include "./shader.hpp"

#define ML_BUFFER_OFFSET(idx) \
static_cast<const GLvoid*>(static_cast<char*>(0) + (idx))

namespace mylib
{

#define ML_BUFFER_OFFSET(idx) \
static_cast<const GLvoid*>(static_cast<char*>(0) + (idx))
inline const GLvoid* BUFFER_OFFSET(const std::size_t& idx)
{
return
static_cast<const GLvoid*>(static_cast<char*>(0) + (idx));
}

class Window
{
Expand Down Expand Up @@ -180,70 +185,6 @@ class App

};

GLuint compileShader(const char *filepath, const GLenum &SHADER_TYPE)
{
GLuint shader = glCreateShader(SHADER_TYPE);
std::ifstream fs(filepath);
std::stringstream srcs;
std::string src;

if (fs.is_open()) {
std::string tmp;
while (fs) {
std::getline(fs, tmp);
src += tmp + "\n";
tmp.clear();
}
}
else {
throw std::runtime_error("mylib::compileShader(): can't open shaderSrc file");
}
#ifndef _NDEBUG
std::clog << "mylib::compileShader(): src: \n" << src << std::endl;
#endif
const GLchar* srcptr = src.c_str();
glShaderSource(shader, 1, &srcptr, NULL);
glCompileShader(shader);

GLint success;
GLchar infoLog[512];
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(shader, 512, NULL, infoLog);
std::cerr << "ERROR Compiling shader src: \n" << infoLog << std::endl;
throw std::runtime_error(
"mylib::compileShader(): glCompileShader error"
);
}

return shader;
}

GLuint linkShaderProgram(std::vector<GLuint> shaders)
{
GLuint program = glCreateProgram();
for (const GLuint& shader: shaders) {
glAttachShader(program, shader);
}
glLinkProgram(program);

GLint success;
GLchar infoLog[512];
glGetShaderiv(program, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(program, 512, NULL, infoLog);
std::cerr << "ERROR Compiling shader src: \n" << infoLog << std::endl;
throw std::runtime_error(
"mylib::compileShader(): glCompileShader error"
);
}

for (const auto& shader: shaders) {
glDeleteShader(shader);
}
return program;
}

};

#endif
64 changes: 64 additions & 0 deletions super/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifdef _DEBUG
#undef _NDEBUG
#undef NDEBUG
#else
#define _NDEBUG
#define NDEBUG
#endif

#include "stdafx.h"

#include "../lib/mylib.hpp"
#include "../lib/camera.hpp"

#include <epoxy/gl.h>
#ifdef _WIN32
#include <epoxy/wgl.h>
#else
#include <epoxy/glx.h>
#endif

#include <SOIL.h>

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/string_cast.hpp>

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cassert>

int main(int argc, char **argv)
{
try
{
mylib::Window window;

start:
std::cout << "(1) MultiLightApp \n"
<< std::endl;
unsigned int option{ 0 };
std::cin >> option;

switch (option)
{
default:
std::cout << "select any one of the option please." << std::endl;
goto start;
break;
}
}
catch (const std::exception& e)
{
throw e;
}

std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get();
std::exit(EXIT_SUCCESS);
}

0 comments on commit 3c0998a

Please sign in to comment.