Okay, so new to C++, I have background in C#, Java, and Lua.
1.) I created a header file with some structs and objects defined in it. (Game.h
)
#pragma once
#include <iostream>
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#include <GL/GL.h>
#endif
#include <map>
#include <vector>
#include <string>
#include <glm/glm.hpp>
using namespace std;
using namespace glm;
//Tutorial found here; https://learnopengl.com/Model-Loading/Mesh
namespace GSGEngineCore
{
class Game
{
public:
void OnStart(); //Called when the game is initially created.
void OnUpdate(float delta); //Called immediately before the frame renders.
void OnRender(float delta); //Called immediately after the frame is updated.
void OnFixedUpdate(int updateProcessID, float deltaTime); //Called in fixed intervals.
void OnDestroy(); //Called when the game is terminated.
};
}
namespace GSGEngineGraphics
{
struct Vertex
{
public:
vec3 position;
vec3 normals;
vec2 texCoords;
};
struct Texture
{
public:
unsigned int id;
string type;
string tag;
};
struct Mesh
{
public:
vector<unsigned int> indices;
vector<Texture> textures;
vector<Vertex> vertices;
Mesh(vector<Vertex> vertices, vector<unsigned int> indices, vector<Texture> textures);
private:
unsigned int VAO, VBO, EBO;
void SetupMesh();
};
class Graphics
{
private:
public:
/// @brief Fetches a texture specified by the given tag.
/// @param key - The string value that represents the texture in the graphics engine.
/// @return A Texture specified by the tag value.
Texture GetTexture(string tag);
/// @brief If the texture specified by the tag exists, it is overwritten by the new texture, otherwise, it is added to the internal map<string, texture> object.
/// @param tag - The string representation of the given texture.
/// @param tex - The actual texture that we are accessing.
/// @return
void SetTexture(string tag, Texture tex);
};
};
2.) Next, I created the associated CPP file (Game.cpp
):
#pragma once
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#include <GL/GL.h>
#endif
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <glm/glm.hpp>
#include <Game.h>
using namespace std;
using namespace glm;
//No code yet, just proof of concept to demonstrate the issue.
3.) I am using the default build configuration for the project (i.e. I created the project, I went to the "headers" folder that placed in the newly generated project by Visual Studio on project creation, and I created my header there).
Some possibilities as to what's going on:
1.) There's some code that goes into creating headers that I'm not familiar with yet (i.e. is there a #header
compiler directive or something?). So, basically, a newbie fuck-up.
2.) The project somehow got corrupted at some point. Entirely possible. I'm not familiar enough with build systems conceptually and practically with whatever build system Visual Studio C++ uses out of the box to check for this.
3.) Visual Studio doesn't automatically define the <project>/Header Files/
folder as the location of headers. This is also possible, but I don't know why Visual Studio would waste energy building the Header Files folder if I have to manually tell the compiler to look for headers in the folder anyway. At that point, might as well just tell it to look for headers with the source files (which also doesn't work, by the way; moving Game.h
into the same folder as Game.cpp
does nothing to resolve the problem).
4.) I have to manually add every file to the default build-system (seems unintuitive, and Visual Studio is pretty intuitive, so this feels unlikely; if this is the case, why can't the project just automatically detect all headers in the main project directory? Why do we have to manually define them to the compiler? And how do we go about doing this?)
Project structure (ignore the GUI icon in RGame.h
- I created another header and moved all the code from the first one to the second one to test if it was a Visual Studio bug specifically relating to the Game.h
file):
Sources I used to understand headers: