Skip to content

Latest commit

 

History

History
208 lines (169 loc) · 4.9 KB

File metadata and controls

208 lines (169 loc) · 4.9 KB

Polygon-GameEngine-Study-Version-01

My first game engine 3D i'm developing A simple 3D game engine made using c++ and OpenGL following tutorials of Learn OpenGL

In this repository there are two Visual Studio, Engine and Game projects. Engine is the main design here, all engine functions are there, in the Game, there is example of how to use the engine. The engine is a static library (.lib), for use, link the library on your project, make sure the compiler is configured for 64x, add engine include folder and game include folder.

Create game window and default scene

First, in game project, add main.cpp file and youSceneScript.h for first game level. DefaultGameConfig is a initial game settings, window size, game name and more. DefaultLevelConfig is your first level, on create the game, the first level is created and loaded. Later, create the main game loop using DefaultGameConfig and DefaultLevelConfig.
#include <polygon/polygon.h>	// engine

#include <Level_0.h>		// sceneScript

int main() {

	DefaultGameConfig* gameConfig = new DefaultGameConfig("Polygon Engine", 980, 840);
	DefaultLevelConfig* levelConfig = new DefaultLevelConfig("level 0", new level_0());

	Core* game = new Core(gameConfig, levelConfig);
	game->UpdateGame();
	game->~Core();

	return 0;
}

Now, add logic on the first level.

#include <Level_0.h>

#include <iostream>

void level_0::OnStart() {

	scene->environment->backgroundColor = glm::vec3(0.9, 0.9, 1.0);

	scene->AddDefaultCamera(glm::vec3(), glm::vec3());
}

void level_0::OnUpdate(float delta) {

	std::cout << "game loop is running" << std::endl;
}

More detals of how to program your game using Polygon Engine below.

Used APIs:

  • GLAD for load OpenGL
  • GLM Mathematic API for OpenGL
  • GLFW used for create window and manage inputs
  • stb_image for load textures

Goals:

  • delta time
  • scene scripting
  • component system
  • material scripting
  • texture suport
  • import 3D models (.obj)
  • point lights
  • spot lights
  • sun light
  • lights specular reflection
  • load and unload scenes
  • environment settings
  • ImGui custom editor tools
  • file manager
  • global / local moviment
  • global / local rotation

Features:

  • Scene scripting

    class level_0 : public SceneScripting
    {
    public:
    
      void OnStart()
      {
        // start scene logic
      }
      
      void OnUpdate(float delta)
      {
        // update scene logic
      }
    };
    
    • Transformations:
    void OnStart()
    {
      ...
      player->transform->SetPos(glm::vec3(0, 0, 10);
      player->transform->SetRot(glm::vec3(0, 45, 0);
      ...
    }
    
    void OnUpdate(float delta)
    {
      ...
      player->transform->Move(player->transform->GetForward() * delta * speed);
      ...
    }
    
    • Components:
    void OnStart()
    {
      MeshRenderer* renderer = player->AddComponent<MeshRenderer>();
      renderer->SetMesh(primitives->CUBE);
      renderer->SetMaterial(new SampleMaterial());
    }
    
    • Custom Components:
    class PlayerController : public Component
    {
    public:
      
      float speed = 3.0f;
        
      void OnUpdate(float delta)
      { 
        if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) transform->Move(transform->GetForward() * delta * speed);
      }
    }
    
    • Draw Debug Lines:
    void OnUpdate(float delta)
    {
      glm::vec3 start = glm::vec3();
      glm::vec3 end = glm::vec3(1);
      glm::vec3 color = glm::vec3(1, 0, 0); // red
      gizmos->DrawLine(start, end, color);
    }
    
    • Custom Materials:
    class SampleMaterial : public MaterialScripting
    {
     public:
       
      glm::vec3 color = glm::vec3(0.1, 0.1, 1);
        
      void OnStart()
      {
        
        SetShader("shader.vert", "shader.frag");
        Use(); // start shader
          
        SetVec3("color", color);
      }
    }
    
    • Textures suport:
    bool useAlfa = true;
    material->SetTexture("texture.png", useAlfa);
    
    • Lights:
    void OnStart()
    {
      // suported lights : point and spot
      PointLight* l = AddComponent<PointLight>();
      l->color = glm::vec3(1);
      l->maxDistance = 5;
    }
    
    • Environment:
    void OnStart()
    {
      scene->environment->backgroundColor = glm::vec3(0.9, 0.9, 1.0);
        scene->environment->ambientColor = glm::vec3(0.4f);
      scene->sun->color = glm::vec3(1);
      scene->sun->intensity = 1.0f;
      scene->sun->SetRot(glm::vec3(-45, -45, 0));
    }
    
    • ImGui:
    void OnEditor() {
    
      ImGui::Begin("hello, window");
      ImGui::Text("hello");
      ImGui::End();
    }