Initial setup.
Correctly linking glfw and spdlog... Linking could be improved by not needing the sandbox application to also be linked with glfw
This commit is contained in:
		@ -1,135 +0,0 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "glfw3.h"
 | 
			
		||||
//#include "spdlog.h"
 | 
			
		||||
GLFWwindow *  window;
 | 
			
		||||
 | 
			
		||||
int main (void) {
 | 
			
		||||
 | 
			
		||||
//	spdlog::info("Welcome to spdlog!");
 | 
			
		||||
 | 
			
		||||
	if ( !glfwInit()){
 | 
			
		||||
		puts("Failed to initialize GLFW!");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	window = glfwCreateWindow( 640 , 480, "BarinkEngine", NULL, NULL);
 | 
			
		||||
 | 
			
		||||
	if( !window){
 | 
			
		||||
		puts("Failed to create the window");
 | 
			
		||||
		glfwTerminate();
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	glfwMakeContextCurrent(window);
 | 
			
		||||
 | 
			
		||||
	if(glfwVulkanSupported()) 
 | 
			
		||||
	{
 | 
			
		||||
		puts("Vulkan is supported!");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	int width,height;
 | 
			
		||||
	glfwGetFramebufferSize(window, &width, &height);
 | 
			
		||||
	glViewport(0,0, width, height);
 | 
			
		||||
 | 
			
		||||
// SOURCE: https://learnopengl.com/Getting-started/Hello-Triangle
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	float vertices[] = {
 | 
			
		||||
		-0.5, -0.5f, 0.0f,
 | 
			
		||||
		0.5, -0.5f, 0.0f,
 | 
			
		||||
		0.5, 0.5f, 0.0f,
 | 
			
		||||
		
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	unsigned int VBO;
 | 
			
		||||
	glGenBuffers(1,&VBO);
 | 
			
		||||
 | 
			
		||||
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
 | 
			
		||||
 | 
			
		||||
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
 | 
			
		||||
 | 
			
		||||
	// Load the vertex shader program
 | 
			
		||||
	const char *vertexShaderSource = "#version 330 core\n"
 | 
			
		||||
    "layout (location = 0) in vec3 aPos;\n"
 | 
			
		||||
    "void main()\n"
 | 
			
		||||
    "{\n"
 | 
			
		||||
    "   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
 | 
			
		||||
    "}\0";
 | 
			
		||||
 | 
			
		||||
	unsigned int vertexShader;
 | 
			
		||||
	vertexShader = glCreateShader(GL_VERTEX_SHADER);
 | 
			
		||||
	glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
 | 
			
		||||
	glCompileShader(vertexShader);
 | 
			
		||||
 | 
			
		||||
	const char *fragmentShaderSource = "#version 330 core\n"
 | 
			
		||||
	"out vec4 FragColor;\n"
 | 
			
		||||
	"void main ()\n {\n"
 | 
			
		||||
	"FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); \n"
 | 
			
		||||
	"}\n";
 | 
			
		||||
 | 
			
		||||
	unsigned int fragmentShader ;
 | 
			
		||||
	fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
 | 
			
		||||
	glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
 | 
			
		||||
	glCompileShader(fragmentShader);
 | 
			
		||||
 | 
			
		||||
	unsigned int shaderProgram;
 | 
			
		||||
	shaderProgram = glCreateProgram();
 | 
			
		||||
 | 
			
		||||
	glAttachShader (shaderProgram, vertexShader);
 | 
			
		||||
	glAttachShader(shaderProgram, fragmentShader);
 | 
			
		||||
	glLinkProgram(shaderProgram);
 | 
			
		||||
 | 
			
		||||
	glUseProgram(shaderProgram);
 | 
			
		||||
 | 
			
		||||
	glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float), (void*)0);
 | 
			
		||||
	glEnableVertexAttribArray(0);
 | 
			
		||||
 | 
			
		||||
	// Copy our vertices array in a buffer for OpenGL to use
 | 
			
		||||
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
 | 
			
		||||
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
 | 
			
		||||
 | 
			
		||||
	// then set the vertex attributes pointers
 | 
			
		||||
	glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float), (void*)0);
 | 
			
		||||
	glEnableVertexAttribArray(0);
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	unsigned int VAO;
 | 
			
		||||
	glGenVertexArrays(1,&VAO);
 | 
			
		||||
 | 
			
		||||
	glBindVertexArray(VAO);
 | 
			
		||||
 | 
			
		||||
	// use our hader program when we want to render an object
 | 
			
		||||
	glUseProgram(shaderProgram);
 | 
			
		||||
	glBindVertexArray(VAO);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	while(!glfwWindowShouldClose(window)){
 | 
			
		||||
		/* Start rendering here */
 | 
			
		||||
		glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
 | 
			
		||||
		glClear(GL_COLOR_BUFFER_BIT);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		glDrawArrays(GL_TRIANGLES, 0, 3);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		/* Swap front and back buffers */
 | 
			
		||||
		glfwSwapBuffers(window);
 | 
			
		||||
 | 
			
		||||
		/* Poll for and process events */
 | 
			
		||||
		glfwPollEvents();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	glDeleteShader(vertexShader);
 | 
			
		||||
	glDeleteShader(fragmentShader);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	glfwTerminate();
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								MyGraphicsEngine/include/MyGraphicsEngine/Graphics.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								MyGraphicsEngine/include/MyGraphicsEngine/Graphics.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
#include "MyGraphicsEngine/window.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
inline void test (){
 | 
			
		||||
    spdlog::info("Linked correctly!");
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								MyGraphicsEngine/include/MyGraphicsEngine/window.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								MyGraphicsEngine/include/MyGraphicsEngine/window.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include <GLFW/glfw3.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BarinkWindow{
 | 
			
		||||
    private:
 | 
			
		||||
        GLFWwindow* window;
 | 
			
		||||
        bool FullScreen;
 | 
			
		||||
        bool VulkanSupported;
 | 
			
		||||
        int Width, Height;
 | 
			
		||||
 | 
			
		||||
        bool InitGLFW();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
        BarinkWindow(const int width, const int height);
 | 
			
		||||
        ~BarinkWindow();
 | 
			
		||||
 | 
			
		||||
        void EnterLoop();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										47
									
								
								MyGraphicsEngine/window.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								MyGraphicsEngine/window.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,47 @@
 | 
			
		||||
#include "MyGraphicsEngine/window.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool BarinkWindow::InitGLFW(){
 | 
			
		||||
	if(!glfwInit()){
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BarinkWindow::BarinkWindow(const int width, const int height) :
 | 
			
		||||
Width(width), Height(height), FullScreen(false){
 | 
			
		||||
	InitGLFW();
 | 
			
		||||
 | 
			
		||||
	window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
 | 
			
		||||
 | 
			
		||||
	if( !window){
 | 
			
		||||
		glfwTerminate();
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	glfwMakeContextCurrent(window);
 | 
			
		||||
 | 
			
		||||
	VulkanSupported = glfwVulkanSupported();
 | 
			
		||||
 | 
			
		||||
	glfwGetFramebufferSize(window, &Width, &Height);
 | 
			
		||||
	glViewport(0,0, Width, Height);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
BarinkWindow::~BarinkWindow(){
 | 
			
		||||
 | 
			
		||||
	glfwTerminate();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BarinkWindow::EnterLoop(){
 | 
			
		||||
	while(!glfwWindowShouldClose(window))
 | 
			
		||||
	{
 | 
			
		||||
		glClear(GL_COLOR_BUFFER_BIT);
 | 
			
		||||
 | 
			
		||||
		glfwSwapBuffers(window);
 | 
			
		||||
		glfwPollEvents();
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user