source: opengl-game/graphics-pipeline_opengl.cpp@ 83b5b4b

feature/imgui-sdl points-test
Last change on this file since 83b5b4b was 3de31cf, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

Add and begin implementing an OpenGL version of the GraphicsPipeline class

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include "graphics-pipeline_opengl.hpp"
2
3#include <iostream>
4#include <fstream>
5
6using namespace std;
7
8GraphicsPipeline_OpenGL::GraphicsPipeline_OpenGL() {
9}
10
11GraphicsPipeline_OpenGL::~GraphicsPipeline_OpenGL() {
12}
13
14void GraphicsPipeline_OpenGL::createPipeline(string vertShaderFile, string fragShaderFile) {
15 shaderProgram = loadShaderProgram(vertShaderFile, fragShaderFile);
16
17 glGenVertexArrays(1, &vao);
18 numPoints = 0;
19}
20
21GLuint GraphicsPipeline_OpenGL::loadShaderProgram(string vertShaderFile, string fragShaderFile) {
22 GLuint vs = loadShader(GL_VERTEX_SHADER, vertShaderFile);
23 GLuint fs = loadShader(GL_FRAGMENT_SHADER, fragShaderFile);
24
25 GLuint shader_program = glCreateProgram();
26 glAttachShader(shader_program, vs);
27 glAttachShader(shader_program, fs);
28
29 glLinkProgram(shader_program);
30
31 return shader_program;
32}
33
34GLuint GraphicsPipeline_OpenGL::loadShader(GLenum type, string file) {
35 cout << "Loading shader from file " << file << endl;
36
37 ifstream shaderFile(file);
38 GLuint shaderId = 0;
39
40 if (shaderFile.is_open()) {
41 string line, shaderString;
42
43 while (getline(shaderFile, line)) {
44 shaderString += line + "\n";
45 }
46 shaderFile.close();
47 const char* shaderCString = shaderString.c_str();
48
49 shaderId = glCreateShader(type);
50 glShaderSource(shaderId, 1, &shaderCString, NULL);
51 glCompileShader(shaderId);
52
53 cout << "Loaded successfully" << endl;
54 }
55 else {
56 cout << "Failed to load the file" << endl;
57 }
58
59 return shaderId;
60}
Note: See TracBrowser for help on using the repository browser.