mirror of
https://github.com/guezoloic/LearnOpenGL.git
synced 2026-01-25 03:34:15 +00:00
feat(Game): re init Game class
This commit is contained in:
23
inc/game.hpp
Normal file
23
inc/game.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef GAME_HPP
|
||||
#define GAME_HPP
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Game
|
||||
{
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
const char *name;
|
||||
GLFWwindow *window;
|
||||
|
||||
public:
|
||||
Game(int width, int height, string name);
|
||||
~Game();
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif
|
||||
49
src/game.cpp
Normal file
49
src/game.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "GL/glew.h"
|
||||
#include "game.hpp"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
Game::Game(int width, int height, string name) :
|
||||
width(width),
|
||||
height(height),
|
||||
name(name.c_str())
|
||||
{
|
||||
if(glfwInit() == GLFW_FALSE)
|
||||
std::cerr << "error glfw" << std::endl;
|
||||
|
||||
this->window = glfwCreateWindow(
|
||||
this->width,
|
||||
this->height,
|
||||
this->name,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
|
||||
// OpenGL 3.3
|
||||
glfwWindowHint(GLFW_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_VERSION_MINOR, 3);
|
||||
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
glfwWindowHint(GLFW_DEPTH_BITS, 24);
|
||||
glfwWindowHint(GLFW_STENCIL_BITS, 8);
|
||||
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwMakeContextCurrent(this->window);
|
||||
|
||||
glewInit();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
void Game::run()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
glfwTerminate();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "game.hpp"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
#include "stb_image.h"
|
||||
|
||||
#include "game.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user