Changes in / [772d8c7:c40990d] in opengl-game
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r772d8c7 rc40990d 6 6 #include <cstdio> 7 7 #include <iostream> 8 #include <fstream> 8 9 9 10 using namespace std; 10 11 11 const bool FULLSCREEN = true; 12 GLuint loadShader(GLenum type, string file); 13 14 const bool FULLSCREEN = false; 12 15 13 16 void glfw_error_callback(int error, const char* description) { … … 38 41 GLFWwindow* window = NULL; 39 42 43 int width = 640; 44 int height = 480; 45 40 46 if (FULLSCREEN) { 41 47 GLFWmonitor* mon = glfwGetPrimaryMonitor(); 42 48 const GLFWvidmode* vmode = glfwGetVideoMode(mon); 49 50 cout << "Fullscreen resolution " << vmode->width << "x" << vmode->height << endl; 43 51 window = glfwCreateWindow(vmode->width, vmode->height, "Extended GL Init", mon, NULL); 52 53 width = vmode->width; 54 height = vmode->height; 44 55 } else { 45 window = glfwCreateWindow( 640, 480, "Hello Triangle", NULL, NULL);56 window = glfwCreateWindow(width, height, "Hello Triangle", NULL, NULL); 46 57 } 47 58 … … 54 65 glewExperimental = GL_TRUE; 55 66 glewInit(); 67 68 // glViewport(0, 0, width*2, height*2); 56 69 57 70 const GLubyte* renderer = glGetString(GL_RENDERER); … … 80 93 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); 81 94 82 const char* vertex_shader = 83 "#version 410\n" 84 "in vec3 vp;" 85 "void main() {" 86 " gl_Position = vec4(vp, 1.0);" 87 "}"; 95 //string vertexShaderString = loadShader(); 88 96 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); 97 GLuint vs = loadShader(GL_VERTEX_SHADER, "./test.vert"); 98 GLuint fs = loadShader(GL_FRAGMENT_SHADER, "./test.frag"); 103 99 104 100 GLuint shader_program = glCreateProgram(); … … 124 120 return 0; 125 121 } 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.