mirror of
https://github.com/guilhermewerner/opengl
synced 2025-06-15 13:04:17 +00:00
Update Application.cpp
This commit is contained in:
@ -6,12 +6,14 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
static std::string ParseShader(const std::string filePath)
|
using namespace std;
|
||||||
{
|
|
||||||
std::ifstream stream(filePath);
|
|
||||||
|
|
||||||
std::string line;
|
static string ParseShader(const string filePath)
|
||||||
std::stringstream ss;
|
{
|
||||||
|
ifstream stream(filePath);
|
||||||
|
|
||||||
|
string line;
|
||||||
|
stringstream ss;
|
||||||
|
|
||||||
while (getline(stream, line))
|
while (getline(stream, line))
|
||||||
{
|
{
|
||||||
@ -21,7 +23,7 @@ static std::string ParseShader(const std::string filePath)
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int CompileShader(unsigned int type, const std::string &source)
|
static unsigned int CompileShader(unsigned int type, const string &source)
|
||||||
{
|
{
|
||||||
unsigned int id = glCreateShader(type);
|
unsigned int id = glCreateShader(type);
|
||||||
const char *src = source.c_str();
|
const char *src = source.c_str();
|
||||||
@ -37,12 +39,12 @@ static unsigned int CompileShader(unsigned int type, const std::string &source)
|
|||||||
int lenght;
|
int lenght;
|
||||||
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &lenght);
|
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &lenght);
|
||||||
|
|
||||||
char *message = (char *)alloca(lenght + sizeof(char));
|
char *message = (char *)malloc(lenght + sizeof(char));
|
||||||
|
|
||||||
glGetShaderInfoLog(id, lenght, &lenght, message);
|
glGetShaderInfoLog(id, lenght, &lenght, message);
|
||||||
|
|
||||||
std::cout << "Failed to compile " << (type == GL_VERTEX_SHADER ? "vertex" : "fragment") << " shader!" << std::endl;
|
cout << "Failed to compile " << (type == GL_VERTEX_SHADER ? "vertex" : "fragment") << " shader!" << endl;
|
||||||
std::cout << message << std::endl;
|
cout << message << endl;
|
||||||
|
|
||||||
glDeleteShader(id);
|
glDeleteShader(id);
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ static unsigned int CompileShader(unsigned int type, const std::string &source)
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int CreateShader(const std::string &vertexShader, const std::string &fragmentShader)
|
static unsigned int CreateShader(const string &vertexShader, const string &fragmentShader)
|
||||||
{
|
{
|
||||||
unsigned int program = glCreateProgram();
|
unsigned int program = glCreateProgram();
|
||||||
|
|
||||||
@ -92,10 +94,10 @@ int main()
|
|||||||
|
|
||||||
if (glewInit() != GLEW_OK)
|
if (glewInit() != GLEW_OK)
|
||||||
{
|
{
|
||||||
std::cout << "Error!" << std::endl;
|
cout << "Error!" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << glGetString(GL_VERSION) << std::endl;
|
cout << glGetString(GL_VERSION) << endl;
|
||||||
|
|
||||||
float positions[6] = {
|
float positions[6] = {
|
||||||
-0.5f, -0.5f,
|
-0.5f, -0.5f,
|
||||||
@ -110,13 +112,13 @@ int main()
|
|||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
std::string vertexShader = ParseShader("Shaders/Vertex.glsl");
|
string vertexShader = ParseShader("Shaders/Vertex.glsl");
|
||||||
std::cout << "VERTEX:" << std::endl;
|
cout << "VERTEX:" << endl;
|
||||||
std::cout << vertexShader << std::endl;
|
cout << vertexShader << endl;
|
||||||
|
|
||||||
std::string fragmentShader = ParseShader("Shaders/Fragment.glsl");
|
string fragmentShader = ParseShader("Shaders/Fragment.glsl");
|
||||||
std::cout << "FRAGMENT:" << std::endl;
|
cout << "FRAGMENT:" << endl;
|
||||||
std::cout << fragmentShader << std::endl;
|
cout << fragmentShader << endl;
|
||||||
|
|
||||||
unsigned int shader = CreateShader(vertexShader, fragmentShader);
|
unsigned int shader = CreateShader(vertexShader, fragmentShader);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user