在上一篇文章中已经介绍了OpenGL窗口的创建。本文接着说如何用OpenGL绘制一个三角形。
1 . 添加头文件shader.h
,代码如下:
#pragma once
#include <string>
#include <GL\glew.h>
class Shader
{
public:
Shader(const std::string& fileName);
void Bind();
virtual ~Shader();
protected:
private:
static const unsigned int NUM_SHADERS = 2;
Shader(const Shader& other){}
void operator=(const Shader& other){}
GLuint m_program;
GLuint m_shaders[NUM_SHADERS];
};
2 . 添加类shader.cpp
,代码如下:
#include "shader.h"
#include <iostream>
#include <fstream>
static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
static std::string LoadShader(const std::string& fileName);
static GLuint CreateS