Added basic shading and support for up to 100 lights of any color; By default now, states with no lights are dark
This commit is contained in:
1 parent
dff0d86558
commit
5c10fdc1a4
35 files changed
+4037
-2664
No files matched your search
@@ -8,10 +8,10 @@ namespace nf {
|
||||
class Camera {
|
||||
public:
|
||||
enum class Type {
|
||||
NF_CAMERA_UI,
|
||||
NF_CAMERA_FIRST_PERSON,
|
||||
NF_CAMERA_ORBIT,
|
||||
NF_CAMERA_FIXED
|
||||
UI,
|
||||
FIRST_PERSON,
|
||||
ORBIT,
|
||||
FIXED
|
||||
};
|
||||
Camera(Application* app);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace nf {
|
||||
void moveLeft(double speed);
|
||||
void setPosition(double x, double y, double z);
|
||||
void setPosition(const Vec3& position);
|
||||
const Vec3& getPosition();
|
||||
|
||||
void bind(Shader* shader);
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "Utility.h"
|
||||
|
||||
namespace nf {
|
||||
class Shader;
|
||||
|
||||
class Light {
|
||||
public:
|
||||
enum class Type {
|
||||
DIRECTIONAL,
|
||||
POINT,
|
||||
SPOTLIGHT
|
||||
};
|
||||
Light();
|
||||
|
||||
void create(const Vec3& position, const Vec3& color, Type type = Type::POINT, float strength = 1.0f);
|
||||
bool isConstructed();
|
||||
void setPosition(const Vec3& position);
|
||||
void setColor(const Vec3& color);
|
||||
|
||||
void bind(Shader* shader, unsigned int lightNumber);
|
||||
|
||||
Type getType();
|
||||
const Vec3& getPosition();
|
||||
const Vec3& getColor();
|
||||
const float getStrength();
|
||||
|
||||
~Light();
|
||||
private:
|
||||
bool m_constructed;
|
||||
Type m_type;
|
||||
Vec3 m_position;
|
||||
Vec3 m_color;
|
||||
float m_strength;
|
||||
};
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace nf {
|
||||
public:
|
||||
Model();
|
||||
|
||||
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinates, size_t textureCoordinatesBufferSize, ATexture* texture);
|
||||
void create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const void* normalsBufferData, size_t normalsBufferSize, ATexture* texture);
|
||||
void bind() override;
|
||||
|
||||
~Model();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Utility.h"
|
||||
#include "IntroGamestate.h"
|
||||
#include "Assets.h"
|
||||
#include "Light.h"
|
||||
#include "Text.h"
|
||||
#include "UITexture.h"
|
||||
#include "Input.h"
|
||||
@@ -52,6 +53,7 @@ namespace nf {
|
||||
|
||||
void render(Entity& in);
|
||||
void render(UIElement& in);
|
||||
void render(Light& in);
|
||||
|
||||
void doFrame(Camera* camera);
|
||||
|
||||
@@ -62,12 +64,14 @@ namespace nf {
|
||||
HDC m_hdc;
|
||||
HGLRC m_hglrc;
|
||||
|
||||
AssetPack baseAP;
|
||||
AssetPack m_baseAP;
|
||||
|
||||
std::vector<Light*> m_lights;
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<UIElement*> m_lUI;
|
||||
Shader* m_entityShader;
|
||||
Shader* m_textShader;
|
||||
Shader* m_uiTextureShader;
|
||||
};
|
||||
|
||||
class Application {
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
#include <vector>
|
||||
#include <Windows.h>
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Camera.h"
|
||||
#include "Assets.h"
|
||||
|
||||
namespace nf {
|
||||
class Application;
|
||||
class Shader;
|
||||
class Entity;
|
||||
class UIElement;
|
||||
class Light;
|
||||
class Camera;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
@@ -15,7 +18,7 @@ namespace nf {
|
||||
|
||||
void render(Entity& in);
|
||||
void render(UIElement& in);
|
||||
//TODO: Create second render function for UIElements
|
||||
void render(Light& in);
|
||||
|
||||
void doFrame(Camera* camera);
|
||||
|
||||
@@ -26,8 +29,9 @@ namespace nf {
|
||||
HDC m_hdc;
|
||||
HGLRC m_hglrc;
|
||||
|
||||
AssetPack baseAP;
|
||||
AssetPack m_baseAP;
|
||||
|
||||
std::vector<Light*> m_lights;
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<UIElement*> m_lUI;
|
||||
Shader* m_entityShader;
|
||||
|
||||
@@ -9,14 +9,16 @@ namespace nf {
|
||||
Shader(const char* vertexSource, const char* fragmentSource);
|
||||
|
||||
void bind();
|
||||
void setUniform(const char* name, glm::mat4& data);
|
||||
void setUniform(const char* name, glm::vec3& data);
|
||||
void setUniform(const std::string& name, glm::mat4& data);
|
||||
void setUniform(const std::string& name, glm::vec3& data);
|
||||
void setUniform(const std::string& name, int data);
|
||||
void setUniform(const std::string& name, float data);
|
||||
|
||||
~Shader();
|
||||
private:
|
||||
void getUniformLocation(const char* uniformName);
|
||||
void getUniformLocation(const std::string& uniformName);
|
||||
|
||||
unsigned int m_id;
|
||||
std::unordered_map<const char*, unsigned int> m_uniformLocations;
|
||||
std::unordered_map<std::string, unsigned int> m_uniformLocations;
|
||||
};
|
||||
}
|
||||
@@ -14,10 +14,12 @@ namespace nf {
|
||||
void setPosition(float x, float y);
|
||||
void setPosition(const Vec2& position);
|
||||
void centered(bool x, bool y = false);
|
||||
bool isConstructed();
|
||||
virtual void render(Shader* shader, unsigned int windowWidth, unsigned int windowHeight);
|
||||
|
||||
~UIElement();
|
||||
protected:
|
||||
bool m_constructed;
|
||||
Vec2 m_position;
|
||||
bool m_centeredX;
|
||||
bool m_centeredY;
|
||||
|
||||
@@ -84,5 +84,5 @@ std::exit(-1);}
|
||||
void writeFile(const std::string& filename, const std::string& in, bool encrypted = false);
|
||||
std::string readFile(const std::string& filename);
|
||||
|
||||
void parseOBJ(std::string& in, std::vector<float>& vbOut, std::vector<unsigned int>& ibOut, size_t& ibCountOut, std::vector<float>& tcOut);
|
||||
void parseOBJ(std::string& in, std::vector<float>& vbOut, std::vector<unsigned int>& ibOut, size_t& ibCountOut, std::vector<float>& tcOut, std::vector<float>& vnOut);
|
||||
}
|
||||
Reference in new issue
Block a user