cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
539 stars 59 forks source link

Incorrect Readme.md example #389

Closed Ristellise closed 5 years ago

Ristellise commented 5 years ago

Hello.

In the readme.md, it's stated that I can do the following:

auto shader1 = new Shader::fromFile(GL_VERTEX_SHADER, filename);
auto shader2 = new Shader::fromString(GL_FRAGMENT_SHADER, shaderSource);

Shader::globalReplace("#version 140", "#version 150"); // e.g., useful for OS X

shader1->setIncludePaths({ std::string("/data") });

shader2->compile();
std::cout << shader2->infoLog() << std::endl; // acess compile info log, although it's done automatically if there is a compile error

However, when I tried to use it, VS tells me it expects a type specifier.

Here's my code currently:

#include "ShaderManager.h"
#include <fstream>

#include <cassert>
#include <array>

#include <glm/vec2.hpp>

#include <glbinding/gl/enum.h>
#include <glbinding/gl/functions.h>

#include <globjects/base/StaticStringSource.h>
#include <globjects/base/AbstractStringSource.h>

#include <globjects/Program.h>
#include <globjects/VertexArray.h>
#include <globjects/Texture.h>
#include <globjects/VertexAttributeBinding.h>
#include <globjects/Buffer.h>
#include <globjects/Shader.h>

#include <globjects/base/StringTemplate.h>

using namespace gl;
using namespace globjects;

ShaderManager::ShaderManager()
{
}

ShaderManager::~ShaderManager()
{
}

bool ShaderManager::LoadShader(std::string vertexShaderFile, std::string fragmentShaderFile)
{
    std::fstream file(vertexShaderFile);
    std::fstream file2(fragmentShaderFile);
    std::string buff;
    if (!file.is_open())
    {
        globjects::fatal() << "VertexShader@" << vertexShaderFile.c_str() << " doesn't exist or can't be read. Aborting.";
        return false;
    }
    if (!file.is_open())
    {
        globjects::fatal() << "fragmentShader@" << fragmentShaderFile.c_str() << " doesn't exist or can't be read. Aborting.";
        return false;
    }
    /*auto aa = Shader::sourceFromFile(vertexShaderFile);
    aa.get();*/
    //auto shader1 = new Shader(GL_VERTEX_SHADER, vertexShaderFile);
    auto shader2 = new Shader::fromString(GL_FRAGMENT_SHADER, shaderSource); // <----------------------- HERE
    // prog->attach(fragmentShader.get());
    return false;
}

I'm guess im missing some .h include files. but I can't seem to figure out which ones are missing. Is it possible to have the #include files so that it compiles properly? thanks.

Ristellise commented 5 years ago

Alright. Found out that I have to include #include <globjects/base/File.h> and change the lines to:

auto shaderSource = globjects::Shader::sourceFromFile(vertexShaderFile);
auto shader2 = new Shader(GL_FRAGMENT_SHADER, shaderSource.get());