From: Luke Lau Date: Sun, 30 Sep 2018 14:12:33 +0000 (+0100) Subject: Fix on Mojave X-Git-Tag: assignment-1 X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=commitdiff_plain;h=refs%2Ftags%2Fassignment-1 Fix on Mojave --- diff --git a/assignment1.cpp b/assignment1.cpp index b3049f0..887ffb0 100644 --- a/assignment1.cpp +++ b/assignment1.cpp @@ -17,6 +17,8 @@ using namespace std; GLuint* vaos; GLuint* progIds; +bool hasDrawn = false; + void display() { glClear(GL_COLOR_BUFFER_BIT); for (int i = 0; i < 2; i++) { @@ -25,6 +27,10 @@ void display() { glDrawArrays(GL_TRIANGLES, 0, 3); } glutSwapBuffers(); + if (!hasDrawn) { + glutPostRedisplay(); + hasDrawn = true; + } } void attachShader(GLuint progId, const char* filePath, GLenum type) { @@ -38,7 +44,8 @@ void attachShader(GLuint progId, const char* filePath, GLenum type) { ifstream file(filePath); stringstream buffer; buffer << file.rdbuf(); - const char* contents = buffer.str().c_str(); + string str = buffer.str(); + const char* contents = str.c_str(); glShaderSource(shader, 1, (const GLchar**)&contents, NULL); glCompileShader(shader); @@ -155,17 +162,23 @@ void init() { validateProgram(progId2); } +void keyboard(unsigned char key, int x, int y) { + glutPostRedisplay(); +} + int main(int argc, char** argv) { glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_3_2_CORE_PROFILE); + glutInitDisplayMode(GLUT_STENCIL|GLUT_SINGLE|GLUT_RGB|GLUT_3_2_CORE_PROFILE); glutInitWindowSize(800, 600); - glutCreateWindow("Hello Triangle"); + int win = glutCreateWindow("Hello Triangle"); glutDisplayFunc(display); glewInit(); init(); + glutKeyboardFunc(keyboard); + glutMainLoop(); return 0;