Exemple #1
1
void MainComponent::start() {
  if (isRunning) {
    return;
  }

  static const float vertices[] =
  {
       0.25, -0.25, 0.5, 1.0,
      -0.25, -0.25, 0.5, 1.0,
       0.25,  0.25, 0.5, 1.0
  };

  Shader shader = Shader();
  glUseProgram(shader._program);

  GLuint vbo;

  glCreateBuffers(1, &vbo);
  glCreateVertexArrays(1, &_vao);

  glBindVertexArray(_vao);

  glNamedBufferStorage(vbo, sizeof(vertices), vertices, 0);
  glBindBuffer(GL_ARRAY_BUFFER, vbo);

  glVertexArrayVertexBuffer(_vao, 0, vbo, 0, 16);
  glVertexArrayAttribFormat(_vao, 0, 4, GL_FLOAT, GL_FALSE, 0);
  glVertexArrayAttribBinding(_vao, 0, 0);
  glEnableVertexArrayAttrib(_vao, 0);
  glEnableVertexAttribArray(0);

  run();
}
std::vector<Shader> MaterialShellRenderer::GetShaderList()
{
   std::vector<Shader> shader_list;
   shader_list.push_back(Shader(material_shell_object_VS_vert, GL_VERTEX_SHADER, "material_shell_object_VS"));
   shader_list.push_back(Shader(material_shell_object_FS_frag, GL_FRAGMENT_SHADER, "material_shell_object_FS"));
   return shader_list;
}
Exemple #3
0
Framebuffer::Framebuffer(){
    this->window = Window::getInstance();

    // Create frame buffer
    glGenFramebuffers(1, &framebuffer);

    setupFramebufferTexture(GL_RGBA, 1);

    setupDepthStencilBuffer();

    Shader framebuffer_shader;
    // Load framebuffer shader
    if (Profile::getInstance()->getFxaaLevel()){
        framebuffer_shader = Shader("shaders/flat_drawable_noflip.vs",
            "shaders/framebuffer_fxaa.fs");
    } else {
        framebuffer_shader = Shader("shaders/flat_drawable_noflip.vs",
            "shaders/flat_drawable.fs");
    }

    addShaderPass(framebuffer_shader);

    // Create the window to draw the framebuffer onto
    framebuffer_window = new FlatDrawable(framebuffer_shader, 1.0, 1.0, glm::vec2(0.0, 0.0));
    framebuffer_window->attachTexture(framebuffer_texture);

}
/*static*/
Material* 
EngineHelper::MakeDebugMaterial(){
	Material *debug = new Material("Default material");
	Shader debugVertShader =   Shader("vertex_shader.txt",ShaderTypes::VERTEX_SHADER);
	Shader debugFragShader =   Shader("fragment_shader.txt",ShaderTypes::FRAGMENT_SHADER);
	
	debug->AddShader(debugVertShader);
	debug->AddShader(debugFragShader);
	debug->Compile();
	return debug;
}
/*static*/
Material* 
EngineHelper::MakeDefaultMaterial(){
	Material *defaultMaterial = new Material("Default material");
	Shader vertShader =   Shader("vertex_position_shader.txt",ShaderTypes::VERTEX_SHADER);
	Shader fragShader =   Shader("fragment_shader.txt",ShaderTypes::FRAGMENT_SHADER);
	
	defaultMaterial->AddShader(vertShader);
	defaultMaterial->AddShader(fragShader);
	defaultMaterial->Compile();
	return defaultMaterial;
}
Exemple #6
0
//-----------------------------------------------------------------------------
//       Class:  Context
//      Method:  setup
// Description:  Before the rendering is started, we need to setup the different
//               parameters.
//-----------------------------------------------------------------------------
    void
Context::setup ()
{
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
        std::cerr << "Couldn't initialize SDL.\n";
        exit(1);
    }
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
    mainWindow_ = SDL_SetVideoMode(w_, h_, 32, SDL_OPENGL | SDL_RESIZABLE);
    if ( mainWindow_ == NULL ) {
        std::cerr << "Error setting videomode.\n";
        exit(1);
    }

    SDL_WM_SetCaption(windowName_.c_str(), NULL);

    // Catch error
    GLenum res = glewInit();
    if ( res != GLEW_OK ) {
        std::cerr << "Error: " << glewGetErrorString(res) << "\n";
        exit(1);
    }
    // Set the different options for the objects.
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_3D);

    // Add shaders to shaderlist
    shaders["default"] = Shader();
    shaders["default"].add("shaders/default.vs", GL_VERTEX_SHADER);
    shaders["default"].add("shaders/default.fs", GL_FRAGMENT_SHADER);
    shaders["default"].link();
    shaders["default"].setUniformLocation("vMVP");
    shaders["default"].setUniformLocation("texTransform");
    shaders["default"].setUniformLocation("gSampler");

    shaders["terrain"] = Shader();
    shaders["terrain"].add("shaders/terrain.vs", GL_VERTEX_SHADER);
    shaders["terrain"].add("shaders/terrain.fs", GL_FRAGMENT_SHADER);
    shaders["terrain"].link();
    shaders["terrain"].setUniformLocation("vMVP");
}		// -----  end of method Context::setup  -----
Exemple #7
0
Shader::Shader(const char* fragmentShaderFile, const char* vertexShaderFile){
	_id = glCreateProgram();	//Opprett shaderprogram i OpenGL, lagre indeks for fremtidig bruk
	Window::ExitOnGLError("create the shader program");

	Shader fragmentShader = Shader(fragmentShaderFile, GL_FRAGMENT_SHADER);	
	Window::ExitOnGLError("create the fragment shader");
	Shader vertexShader = Shader(vertexShaderFile, GL_VERTEX_SHADER);
	Window::ExitOnGLError("create the vertex shader");

	fragmentShader.Attach(_id);	//Fest fragment shader til hovedprogrammet
	Window::ExitOnGLError("attach the fragment shader");
	vertexShader.Attach(_id);	//Fest vertex shader til hovedprogrammet
	Window::ExitOnGLError("attach the vertex shader");
}
Exemple #8
0
//
//  Initialize
//
void Ex04opengl::initializeGL()
{
   if (init) return;
   init = true;

   //  Load shaders
   Shader(1,"",":/ex04a.frag");
   Shader(2,":/ex04b.vert",":/ex04b.frag");
   Shader(3,":/ex04c.vert",":/ex04c.frag");
   Shader(4,":/ex04d.vert",":/ex04d.frag");
   Shader(5,":/ex04e.vert",":/ex04e.frag");

   // Cube
   Cube* cube = new Cube();
   cube->texture(":/crate.png");
   objects.push_back(cube);

   // Teapot
   Teapot* pot = new Teapot(8);
   pot->scale(0.5);
   pot->texture(":/pi.png");
   objects.push_back(pot);

   // Cruiser
   WaveOBJ* cruiser=0;
   try
   {
      cruiser = new WaveOBJ("cruiser.obj",":/");
   }
   catch (QString err)
   {
      Fatal("Error loading object\n"+err);
   }
   if (cruiser)
   {
      cruiser->color(1,1,0);
      objects.push_back(cruiser);
   }

   //  Set initial object
   obj = objects[0];

   //  Start 100 fps timer connected to updateGL
   move = true;
   timer.setInterval(10);
   connect(&timer,SIGNAL(timeout()),this,SLOT(updateGL()));
   timer.start();
   time.start();
}
Exemple #9
0
Shader Shader::FromFile(const char * shaderPath, ShaderType type){
	std::ifstream is (shaderPath,std::ios::in);
	std::stringstream buffer;
	buffer<<is.rdbuf();
	std::string shaderstring=buffer.str();
	return Shader(shaderstring.c_str(),type);
}
Exemple #10
0
Shader Shader::New( const std::string& vertexShader,
                    const std::string& fragmentShader,
                    ShaderHints hints )
{
  Internal::ShaderPtr renderer = Internal::Shader::New( vertexShader, fragmentShader, hints );
  return Shader( renderer.Get() );
}
Exemple #11
0
	//----------------------------------------------------------------------
	// ● シェーダの作成
	//----------------------------------------------------------------------
    LNRESULT GraphicsDevice::createShader( IShader** obj_, const void* data_, lnU32 size_, lnSharingKey key_ )
    {
#if 0
        LNRESULT lr;
        *obj_ = NULL;

        // キャッシュを検索
        *obj_ = ShaderCache::findCacheAddRef( key_ );
        if ( *obj_ )
        {
            return LN_OK;
        }
        
        // 新しく作る
        Shader* shader = LN_NEW Shader( this );
        LN_CALL_R( shader->initialize( static_cast< const char* >( data_ ) ) );

        // キャッシュ管理クラスに追加
        ShaderCache::registerCachedObject( key_, shader );

        mShaderList.push_back( shader );
        
        *obj_ = shader;
        return LN_OK;
#endif
        LN_PRINT_NOT_IMPL_FUNCTION;
        return LN_OK;
    }
Exemple #12
0
//
//  Initialize
//
void Ex07opengl::initializeGL()
{
    if (init) return;
    init = true;

    // Texture
    QPixmap crate(":/crate.png");
    tex = bindTexture(crate,GL_TEXTURE_2D);

    //  Load shaders
    Shader(shader,":/ex07.vert",":/ex07.frag");

    //  Start 100 fps timer connected to updateGL
    move = true;
    timer.setInterval(10);
    connect(&timer,SIGNAL(timeout()),this,SLOT(updateGL()));
    timer.start();
    time.start();

    //  Cube vertex buffer object
    //  Copy data to vertex buffer object
    cube_buffer.create();
    cube_buffer.bind();
    cube_buffer.setUsagePattern(QGLBuffer::StaticDraw);
    cube_buffer.allocate(sizeof(cube_data));
    cube_buffer.write(0,cube_data,sizeof(cube_data));
    //  Unbind this buffer
    cube_buffer.release();
}
Exemple #13
0
GLint init()
{
	glfwInit();

	/* Create a GLFW window */
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	window = glfwCreateWindow(screenWidth, screenHeight, "Learning OpenGL", nullptr, nullptr);
	if (window == nullptr)
	{
		std::cout << "Failed to create GLFW window" << std::endl;
		glfwTerminate();
		return -1;
	}

	glfwMakeContextCurrent(window);

	/* Initialize GLEW */
	glewExperimental = GL_TRUE;
	if (glewInit() != GLEW_OK)
	{
		std::cout << "Failed to initialize GLEW" << std::endl;
		return -1;
	}

	glViewport(0, 0, 800, 600);

	/* Input */
	glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
	glfwSetKeyCallback(window, key_callback);
	glfwSetCursorPosCallback(window, mouse_callback);

	glEnable(GL_DEPTH_TEST);

	cubeShader = Shader("cube.vert", "cube.frag");
	lightShader = Shader("light.vert", "light.frag");
	viewCamera = Camera(	glm::vec3(0.0f, 0.0f, 3.0f), 
				  							glm::vec3(0.0f, 0.0f,-1.0f), 
				  							glm::vec3(0.0f, 1.0f, 0.0f),
				  							5.0f 	);


	return 0;
}
Exemple #14
0
void Program::setupGLSL(){
//* configuracoes de buffer
    
    
    //Define vertices que serao desenhados
    GLfloat vertices[] = {
        // Posicoes 	// Cores
        0.5f, 0.5f,     1.0f, 0.0f, 0.0f, //vermelho
        0.5f, -0.5f,	0.0f, 1.0f, 0.0f, //verde
       -0.5f, -0.5f,    0.0f, 0.0f, 1.0f, //azul
        -0.5, 0.5,      1.0f, 1.0f, 1.0f //branco
    };

    
    GLuint indices[] = {
        0, 1, 3,
        1, 2, 3
    };
    
    
    //Cria um objeto de array de vertices
    glGenVertexArrays(1,&VAO);
    GLuint VBO, EBO;
    //Cria um objeto de buffer de vértices
	glGenBuffers(1, &VBO);
    
    //Liga o array de objetos de vertice
    glBindVertexArray(VAO);
    
    //Copia o buffer para o objeto de buffer a ser usado pelo OpenGL
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    //Copia os dados de vertices definidos para o objeto de buffer, e configura como será desenhado
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    glGenBuffers(1, &EBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
    
    //Envia informacoes ao OpenGL de como será os atributos dos vertices passados ao shader
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE,
                          5 * sizeof(GLfloat), (GLvoid*)0);
    //Ativa os atributos configuradoz
    glEnableVertexAttribArray(0);
    //Similar ao acima, mas relacionado a cor
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
                          5 * sizeof(GLfloat), (GLvoid*)(2 * sizeof(GLfloat)));
    glEnableVertexAttribArray(1);
    
    //Desliga array de objetos de vertice
    glBindVertexArray(0);

//
    const char* vertexPath = "/Users/thiagoTMB/Documents/Repositories/Tutorials/OpenGLTutorial/OpenGLTutorial/OpenGLTutorial/vertex.glsl";
    const char* fragmentPath = "/Users/thiagoTMB/Documents/Repositories/Tutorials/OpenGLTutorial/OpenGLTutorial/OpenGLTutorial/fragment.glsl";
    newShader = Shader();
    newShader.initShader(vertexPath, fragmentPath);
    

}
Exemple #15
0
Emitter::Emitter(const Json::Value& emitter_json) {
    glm::vec3 pos;
    pos.x = emitter_json["position"]["x"].asFloat();
    pos.y = emitter_json["position"]["y"].asFloat();
    pos.z = emitter_json["position"]["z"].asFloat();

    initialize(Shader("shaders/particle.vs", "shaders/particle.fs"), pos);

}
Exemple #16
0
void GLProgram::addShader(std::string fileName, GLenum type)
{
	shaders.push_back(Shader(type));
	if (!shaders.back().compile(fileName))
		shaders.pop_back();
	else
		glAttachShader(ID,shaders.back().getID());
	
}
Exemple #17
0
	static Shader shaderFromFile(const std::string &file, GLenum type) {
		std::ifstream f;
		f.open(file.c_str(), std::ios::in | std::ios::binary);
		if (!f.is_open())
			errorHandle(std::string("Failed to open ") + file);
		std::stringstream buf;
		buf << f.rdbuf();
		return Shader(buf.str(), type);
	}
Exemple #18
0
template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationProjectionMatrixUniform(0), colorUniform(1) {
    Corrade::Utility::Resource rs("MagnumShaders");

    #ifndef MAGNUM_TARGET_GLES
    Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210});
    #else
    Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200});
    #endif

    AbstractShaderProgram::attachShader(Shader(v, Shader::Type::Vertex)
        .addSource(rs.get("compatibility.glsl"))
        .addSource(rs.get(vertexShaderName<dimensions>())));

    AbstractShaderProgram::attachShader(Shader(v, Shader::Type::Fragment)
        .addSource(rs.get("compatibility.glsl"))
        .addSource(rs.get("Vector.frag")));

    #ifndef MAGNUM_TARGET_GLES
    if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() ||
        Context::current()->version() == Version::GL210)
    #else
    if(!Context::current()->isVersionSupported(Version::GLES300))
    #endif
    {
        AbstractShaderProgram::bindAttributeLocation(AbstractVector<dimensions>::Position::Location, "position");
        AbstractShaderProgram::bindAttributeLocation(AbstractVector<dimensions>::TextureCoordinates::Location, "textureCoordinates");
    }

    AbstractShaderProgram::link();

    #ifndef MAGNUM_TARGET_GLES
    if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>())
    #endif
    {
        transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
        colorUniform = AbstractShaderProgram::uniformLocation("color");
    }

    #ifndef MAGNUM_TARGET_GLES
    if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::shading_language_420pack>())
        AbstractShaderProgram::setUniform(AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVector<dimensions>::VectorTextureLayer);
    #endif
}
 Shader loadShaderFile(const QString & shaderPath) {
   if (shaderPath.endsWith(".xml", Qt::CaseInsensitive)) {
     return shadertoy::loadShaderXml(shaderPath);
   } else if (shaderPath.endsWith(".json", Qt::CaseInsensitive)) {
     return shadertoy::loadShaderJson(shaderPath);
   } else {
     qWarning() << "Don't know how to parse path " << shaderPath;
   }
   return Shader();
 }
Exemple #20
0
//Initialize the game
GAME_DLL GAME_INIT(Game_Init)
{
	GLenum error = glGetError();
	SetTexture(&test.MeshTexture, "resources\\textures\\tile2.png");
	error = glGetError();
	//the mesh i will use
	CreateSprite(&test, vec2(50, 50), vec3(0, 0, 0), &test.MeshTexture, &Color(1, 1, 1, 1), 1);
	error = glGetError();
	//Use older shaders with old GLSL
#if GLSL_VERSION == ANCIENT_VERSION
	shader = Shader("resources\\shaders\\vertex shader 120.vert", "resources\\shaders\\fragment shader 120.frag");
	error = glGetError();
#elif GLSL_VERSION == MODERN_VERSION	//Use modern shaders with modern GLSL
	shader = Shader("resources\\shaders\\vertex shader.vert", "resources\\shaders\\fragment shader.frag");
#endif

	//CalculatePerspectiveProjection(&Cam, 80.0f, screenWidth, screenHeight, -0.1f, 500.0f);
	CalculateOrthoProjectionMatrix(&Cam, screenWidth, screenHeight, -0.1f, 500.0f);
}
SpotLight::SpotLight(const Vector3f& color, float intensity, const Attenuation& attenuation, float viewAngle, 
                     int shadowMapSizeAsPowerOf2, float shadowSoftness, float lightBleedReductionAmount, float minVariance) :
	PointLight(color, intensity, attenuation, Shader("forward-spot")),
	m_cutoff(cos(viewAngle/2))
{
	if(shadowMapSizeAsPowerOf2 != 0)
	{
		SetShadowInfo(ShadowInfo(Matrix4f().InitPerspective(viewAngle, 1.0, 0.1, GetRange()), false, shadowMapSizeAsPowerOf2,
		                             shadowSoftness, lightBleedReductionAmount, minVariance));
	}
}
Exemple #22
0
Drawable::Ptr StockResources::UnitAxes() {
  GeometryResource::Ptr geom = GetOrMakeGeometry("geom:sv_unit_axes",
      UnitAxesData, resources_);

  MaterialResource::Ptr material =
    resources_->GetMaterial("mat:sv_unit_axes");
  if (!material) {
    material = resources_->MakeMaterial(Shader(kPerVertexColorLighting));
  }
  return Drawable::Create(geom, material);
}
Exemple #23
0
void ShaderResource::release() {

    if (m_loaded) {

        glDeleteShader(m_shader.getVertexShader());
        glDeleteShader(m_shader.getFragmentShader());
        glDeleteProgram(m_shader.getProgram());
        m_shader = Shader();
        m_loaded = false;
    }
}
Exemple #24
0
	void Shaderman::init()
	{
		std::vector<std::string> attr;
		
		// block shader
		attr.push_back("in_vertex");
		attr.push_back("in_normal");
		attr.push_back("in_color");
		
		shaders[Shaderman::BLOCK_SHADER] = Shader("shaders/block.glsl", attr);
		
	}
DirectionalLight::DirectionalLight(const Vector3f& color, float intensity, int shadowMapSizeAsPowerOf2, 
	                 float shadowArea, float shadowSoftness, float lightBleedReductionAmount, float minVariance) :
	BaseLight(color, intensity, Shader("forward-directional")),
	m_halfShadowArea(shadowArea / 2.0f)
{
	if(shadowMapSizeAsPowerOf2 != 0)
	{
		SetShadowInfo(ShadowInfo(Matrix4f().InitOrthographic(-m_halfShadowArea, m_halfShadowArea, -m_halfShadowArea, 
		                                                      m_halfShadowArea, -m_halfShadowArea, m_halfShadowArea), 
								 true, shadowMapSizeAsPowerOf2, shadowSoftness, lightBleedReductionAmount, minVariance));
	}
}
Exemple #26
0
Shader* Shader::get(const std::string& name) {
  if (Shaders.count(name) > 0) {
    return &Shaders[name];
  }
  initDefaultPrograms();
  if ((defaultVertexPrograms.count(name) > 0) &&
      (defaultFragmentPrograms.count(name) > 0)) {
    Shaders[name] = Shader(name);
    return &Shaders[name];
  }
  fprintf(stderr, "No shader for %s\n", name.c_str());
  return NULL;
}
Exemple #27
0
void Renderer::initialize()
{
    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK) {
        std::cerr << "Failed to initialize GLEW." << std::endl;
        exit(-1);
    }
    glEnable(GL_DEPTH_TEST);
    _shader = Shader(_vertexPath.c_str(), _geometryPath.c_str(), _fragmentPath.c_str());
    _depthShader = std::make_shared<Shader>(_shadowVertexPath.c_str(),
           _shadowGeometryPath.c_str(), _shadowFragmentPath.c_str());
    glGenFramebuffers(1, &_depthMapFBO);
}
	void Shaderman::init()
	{
		// load and initialize all shaders
		std::vector<std::string> linkstage;
		
		// fullscreen shader
		shaders[FULLSCREEN_SHADER] = Shader("shaders/screenspace.glsl", linkstage);
		
		// standard 2d shader
		shaders[STANDARD_SHADER] = Shader("shaders/standard.glsl", linkstage);
		
		linkstage.push_back( "in_vertex" );
		linkstage.push_back( "in_texture" );
		linkstage.push_back( "in_color" );
		
		// extended 2d array shader
		shaders[TILESET_SHADER] = Shader("shaders/tileset.glsl", linkstage);
		
		shaders[PLAYER_SHADER] = Shader("shaders/player.glsl", linkstage);
		
		// return state to fixed pipeline
		Shader::unbind();
	}
Exemple #29
0
static void init_graphics(int argc, char** argv) {
    glutInit(&argc,argv);
    glutCreateWindow("GLEW Test");
    Shader minimal = Shader("shaders/minimal.vert", "shaders/minimal.frag");

    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        /* Problem: glewInit failed, something is seriously wrong. */
        std::cerr << "Error: " << glewGetErrorString(err) << std::endl;
    }
    std::cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
    std::cout << "Status: Using GL " << glGetString(GL_VERSION) << std::endl;
}
Exemple #30
0
Graphics::Shader Graphics::createProgram(const std::list<GLuint>& shaders)
{
    GLuint program = glCreateProgram();
    
    for (auto& shader: shaders)
        glAttachShader(program, shader);

    glLinkProgram(program);

    GLint linked;
    glGetProgramiv(program, GL_LINK_STATUS, &linked);
    if (!linked)
    {// Message handled by debug layer
        GLint length;
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
        std::vector<GLchar> message(length + 1);
        glGetProgramInfoLog(program, length, nullptr, message.data());
        fprintf(stderr, "%s\n", message.data());
        glDeleteProgram(program);
        return std::move(Shader());
    }
    printf("Created program %u\n", program);
    return std::move(Shader(program));
}