Changes in / [c40990d:772d8c7] in opengl-game
- Files:
-
- 2 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rc40990d r772d8c7 6 6 #include <cstdio> 7 7 #include <iostream> 8 #include <fstream>9 8 10 9 using namespace std; 11 10 12 GLuint loadShader(GLenum type, string file); 13 14 const bool FULLSCREEN = false; 11 const bool FULLSCREEN = true; 15 12 16 13 void glfw_error_callback(int error, const char* description) { … … 41 38 GLFWwindow* window = NULL; 42 39 43 int width = 640;44 int height = 480;45 46 40 if (FULLSCREEN) { 47 41 GLFWmonitor* mon = glfwGetPrimaryMonitor(); 48 42 const GLFWvidmode* vmode = glfwGetVideoMode(mon); 49 50 cout << "Fullscreen resolution " << vmode->width << "x" << vmode->height << endl;51 43 window = glfwCreateWindow(vmode->width, vmode->height, "Extended GL Init", mon, NULL); 52 53 width = vmode->width;54 height = vmode->height;55 44 } else { 56 window = glfwCreateWindow( width, height, "Hello Triangle", NULL, NULL);45 window = glfwCreateWindow(640, 480, "Hello Triangle", NULL, NULL); 57 46 } 58 47 … … 65 54 glewExperimental = GL_TRUE; 66 55 glewInit(); 67 68 // glViewport(0, 0, width*2, height*2);69 56 70 57 const GLubyte* renderer = glGetString(GL_RENDERER); … … 93 80 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 94 81 95 //string vertexShaderString = loadShader(); 82 const char* vertex_shader = 83 "#version 410\n" 84 "in vec3 vp;" 85 "void main() {" 86 " gl_Position = vec4(vp, 1.0);" 87 "}"; 96 88 97 GLuint vs = loadShader(GL_VERTEX_SHADER, "./test.vert"); 98 GLuint fs = loadShader(GL_FRAGMENT_SHADER, "./test.frag"); 89 GLuint vs = glCreateShader(GL_VERTEX_SHADER); 90 glShaderSource(vs, 1, &vertex_shader, NULL); 91 glCompileShader(vs); 92 93 const char* fragment_shader = 94 "#version 410\n" 95 "out vec4 frag_color;" 96 "void main() {" 97 " frag_color = vec4(0.5, 0.0, 0.5, 1.0);" 98 "}"; 99 100 GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); 101 glShaderSource(fs, 1, &fragment_shader, NULL); 102 glCompileShader(fs); 99 103 100 104 GLuint shader_program = glCreateProgram(); … … 120 124 return 0; 121 125 } 122 123 GLuint loadShader(GLenum type, string file) {124 cout << "Loading shader from file " << file << endl;125 126 ifstream shaderFile(file);127 GLuint shaderId = 0;128 129 if (shaderFile.is_open()) {130 string line, shaderString;131 132 while(getline(shaderFile, line)) {133 shaderString += line + "\n";134 }135 shaderFile.close();136 const char* shaderCString = shaderString.c_str();137 138 shaderId = glCreateShader(type);139 glShaderSource(shaderId, 1, &shaderCString, NULL);140 glCompileShader(shaderId);141 142 cout << "Loaded successfully" << endl;143 } else {144 cout << "Failed to loade the file" << endl;145 }146 147 return shaderId;148 }
Note:
See TracChangeset
for help on using the changeset viewer.