Add OpenGL and GLFW dependencies + example
This commit is contained in:
parent
8032f2efec
commit
dce2418762
@ -3,4 +3,11 @@ project(ecsgame)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
find_package(glfw3 REQUIRED)
|
||||||
|
|
||||||
add_executable(ecsgame main.cpp)
|
add_executable(ecsgame main.cpp)
|
||||||
|
|
||||||
|
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
target_link_libraries(ecsgame ${OPENGL_LIBRARY} glfw)
|
44
main.cpp
44
main.cpp
@ -1,11 +1,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "ECS.h"
|
#include "ECS.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
using namespace ECS;
|
using namespace ECS;
|
||||||
|
|
||||||
struct Position
|
struct Position {
|
||||||
{
|
|
||||||
Position(float x, float y, float z) : x(x), y(y), z(z) {}
|
Position(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||||
|
|
||||||
Position() : x(0.f), y(0.f), z(0.f) {}
|
Position() : x(0.f), y(0.f), z(0.f) {}
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
@ -13,18 +14,15 @@ struct Position
|
|||||||
float z;
|
float z;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GravitySystem : public EntitySystem
|
class GravitySystem : public EntitySystem {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
GravitySystem(float amount)
|
GravitySystem(float amount) {
|
||||||
{
|
|
||||||
gravityAmount = amount;
|
gravityAmount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~GravitySystem() {}
|
virtual ~GravitySystem() {}
|
||||||
|
|
||||||
virtual void tick(World* world, float deltaTime) override
|
virtual void tick(World *world, float deltaTime) override {
|
||||||
{
|
|
||||||
world->each<Position>([&](Entity *ent, ComponentHandle<Position> position) {
|
world->each<Position>([&](Entity *ent, ComponentHandle<Position> position) {
|
||||||
position->y += gravityAmount * deltaTime;
|
position->y += gravityAmount * deltaTime;
|
||||||
});
|
});
|
||||||
@ -46,5 +44,35 @@ int main() {
|
|||||||
ComponentHandle<Position> pos = ent->get<Position>();
|
ComponentHandle<Position> pos = ent->get<Position>();
|
||||||
|
|
||||||
std::cout << "y position after tick: " << pos->y << std::endl;
|
std::cout << "y position after tick: " << pos->y << std::endl;
|
||||||
|
|
||||||
|
GLFWwindow *window;
|
||||||
|
|
||||||
|
/* Initialize the library */
|
||||||
|
if (!glfwInit())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Create a windowed mode window and its OpenGL context */
|
||||||
|
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
|
||||||
|
if (!window) {
|
||||||
|
glfwTerminate();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make the window's context current */
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
/* Loop until the user closes the window */
|
||||||
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
/* Render here */
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
/* Swap front and back buffers */
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
|
||||||
|
/* Poll for and process events */
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user