Mac OpenGL window movement required to show somethingOpenGL - Triangle with a shader isn't showingOpening a fullscreen OpenGL windowPyOpenGL - passing transformation matrix into shaderSimple glfw draw point with opengl shows nothingOpenGL/OSX/GLFW: nothing except the window colorcrazy flashing window OpenGL GLFWUse OpenGL without a windowNothing is showing up in OpenGLHow to increase depth of window in OpenGL?OpenGL Corrupt Shader on MAC

In Avengers 1, why does Thanos need Loki?

Why wasn't the Night King naked in S08E03?

How adjust and align properly different equations

I have a unique character that I'm having a problem writing. He's a virus!

How important is people skills in academic career and applications?

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

How to calculate the node voltages for this circuit using the voltage divider rule

Does a card have a keyword if it has the same effect as said keyword?

Would glacier 'trees' be plausible?

Out of scope work duties and resignation

Why isn't nylon as strong as kevlar?

Distribution normality check

How wide is a neg symbol, how to get the width for alignment?

Why Isn’t SQL More Refactorable?

What does a spell range of "25 ft. + 5 ft./2 levels" mean?

Is it possible to know which is the correct temperature range and speed for any model?

Shantae Dance Matching

Is it possible to convert Map<Object, List<Object>> to Map<Id, List<SomeConcreteSObject>> without a loop?

Double or Take game

How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?

Why do only some White Walkers shatter into ice chips?

Has a commercial or military jet bi-plane ever been manufactured?

As matter approaches a black hole, does it speed up?

Can a nothic's Weird Insight action discover secrets about a player character that the character doesn't know about themselves?



Mac OpenGL window movement required to show something


OpenGL - Triangle with a shader isn't showingOpening a fullscreen OpenGL windowPyOpenGL - passing transformation matrix into shaderSimple glfw draw point with opengl shows nothingOpenGL/OSX/GLFW: nothing except the window colorcrazy flashing window OpenGL GLFWUse OpenGL without a windowNothing is showing up in OpenGLHow to increase depth of window in OpenGL?OpenGL Corrupt Shader on MAC






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm starting OpenGL with C, so I started up a CLion project and got started. For reference, I'm on a Mac 10.14.



This is my CMakeLists.txt:



cmake_minimum_required(VERSION 3.10)
project(GLMC C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH /usr/local/lib/cmake)
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/glfw3)

find_package (PkgConfig REQUIRED)
find_package (OpenGL REQUIRED)
find_package (glfw3 REQUIRED)

include_directories(/usr/local/include glad)
include_directories($GLFW_INCLUDE_DIRS)

find_library(COCOA_LIBRARY Cocoa REQUIRED)
find_library(IOKIT_LIBRARY IOKit REQUIRED)
find_library(COREVID_LIBRARY CoreVideo REQUIRED)

set(CMAKE_C_STANDARD 99)

add_executable(GLMC main.c glad.c)
target_link_libraries (GLMC
$OPENGL_LIBRARIES
$COCOA_LIBRARY
$COREVID_LIBRARY
$IOKIT_LIBRARY
$GLFW3_LIBRARY glfw)


And this is my main.c:



#include "glad.h"
#include <GLFW/glfw3.h>
#include "linmath.h"
#include <stdlib.h>
#include <stdio.h>
static const struct

float x, y;
float r, g, b;
vertices[3] =

-0.6f, -0.4f, 1.f, 0.f, 0.f ,
0.6f, -0.4f, 0.f, 1.f, 0.f ,
0.f, 0.6f, 0.f, 0.f, 1.f
;
static const char* vertex_shader_text =
"uniform mat4 MVP;n"
"attribute vec3 vCol;n"
"attribute vec2 vPos;n"
"varying vec3 color;n"
"void main()n"
"n"
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);n"
" color = vCol;n"
"n";
static const char* fragment_shader_text =
"varying vec3 color;n"
"void main()n"
"n"
" gl_FragColor = vec4(color, 1.0);n"
"n";
static void error_callback(int error, const char* description)

fprintf(stderr, "Error: %sn", description);

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)

if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);

int main(void)

GLFWwindow* window;
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
GLint mvp_location, vpos_location, vcol_location;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)

glfwTerminate();
exit(EXIT_FAILURE);

glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval(1);
// NOTE: OpenGL error checks have been omitted for brevity
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);
glCompileShader(vertex_shader);
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL);
glCompileShader(fragment_shader);
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
mvp_location = glGetUniformLocation(program, "MVP");
vpos_location = glGetAttribLocation(program, "vPos");
vcol_location = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(vpos_location);
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) 0);
glEnableVertexAttribArray(vcol_location);
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) (sizeof(float) * 2));
while (!glfwWindowShouldClose(window))

float ratio;
int width, height;
mat4x4 m, p, mvp;
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
mat4x4_identity(m);
mat4x4_rotate_Z(m, m, (float) glfwGetTime());
mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f);
mat4x4_mul(mvp, p, m);
glUseProgram(program);
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();

glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);




This is the sample code on their website.
I have this basic GLFW/GLAD code. The latest versions of glad.h, glad.c and khrplatform.h are properly referenced.



I have installed glfw3 through brew properly, and succesfully referenced it through C++ and XCode, but I wanted to do it in C and CLion.



The window is entirely black, until it is moved by dragging the title bar, which causes everything to work perfectly.










share|improve this question
























  • The program both compiles and runs, and it apparently calls at least some OpenGL functions successfully. I see no reason at all to conclude that there is any link issue. There could be a "my OpenGL library is broken" issue, but most likely the issue is that your OpenGL calls don't mean what you think they mean. Even if I knew what you were expecting to see, however, I'm not enough of an OpenGL person to easily recognize what you might be doing wrong.

    – John Bollinger
    Mar 22 at 21:56












  • I'm experienced in OpenGL with other languages like Java, so this should be clearing the window to white. But it doesn't.

    – mackycheese21
    Mar 22 at 21:57











  • Sorry! I figured it out. Mostly. Basically, it was working just fine, but only after the window had been dragged around.

    – mackycheese21
    Mar 22 at 23:56

















1















I'm starting OpenGL with C, so I started up a CLion project and got started. For reference, I'm on a Mac 10.14.



This is my CMakeLists.txt:



cmake_minimum_required(VERSION 3.10)
project(GLMC C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH /usr/local/lib/cmake)
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/glfw3)

find_package (PkgConfig REQUIRED)
find_package (OpenGL REQUIRED)
find_package (glfw3 REQUIRED)

include_directories(/usr/local/include glad)
include_directories($GLFW_INCLUDE_DIRS)

find_library(COCOA_LIBRARY Cocoa REQUIRED)
find_library(IOKIT_LIBRARY IOKit REQUIRED)
find_library(COREVID_LIBRARY CoreVideo REQUIRED)

set(CMAKE_C_STANDARD 99)

add_executable(GLMC main.c glad.c)
target_link_libraries (GLMC
$OPENGL_LIBRARIES
$COCOA_LIBRARY
$COREVID_LIBRARY
$IOKIT_LIBRARY
$GLFW3_LIBRARY glfw)


And this is my main.c:



#include "glad.h"
#include <GLFW/glfw3.h>
#include "linmath.h"
#include <stdlib.h>
#include <stdio.h>
static const struct

float x, y;
float r, g, b;
vertices[3] =

-0.6f, -0.4f, 1.f, 0.f, 0.f ,
0.6f, -0.4f, 0.f, 1.f, 0.f ,
0.f, 0.6f, 0.f, 0.f, 1.f
;
static const char* vertex_shader_text =
"uniform mat4 MVP;n"
"attribute vec3 vCol;n"
"attribute vec2 vPos;n"
"varying vec3 color;n"
"void main()n"
"n"
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);n"
" color = vCol;n"
"n";
static const char* fragment_shader_text =
"varying vec3 color;n"
"void main()n"
"n"
" gl_FragColor = vec4(color, 1.0);n"
"n";
static void error_callback(int error, const char* description)

fprintf(stderr, "Error: %sn", description);

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)

if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);

int main(void)

GLFWwindow* window;
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
GLint mvp_location, vpos_location, vcol_location;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)

glfwTerminate();
exit(EXIT_FAILURE);

glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval(1);
// NOTE: OpenGL error checks have been omitted for brevity
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);
glCompileShader(vertex_shader);
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL);
glCompileShader(fragment_shader);
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
mvp_location = glGetUniformLocation(program, "MVP");
vpos_location = glGetAttribLocation(program, "vPos");
vcol_location = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(vpos_location);
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) 0);
glEnableVertexAttribArray(vcol_location);
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) (sizeof(float) * 2));
while (!glfwWindowShouldClose(window))

float ratio;
int width, height;
mat4x4 m, p, mvp;
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
mat4x4_identity(m);
mat4x4_rotate_Z(m, m, (float) glfwGetTime());
mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f);
mat4x4_mul(mvp, p, m);
glUseProgram(program);
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();

glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);




This is the sample code on their website.
I have this basic GLFW/GLAD code. The latest versions of glad.h, glad.c and khrplatform.h are properly referenced.



I have installed glfw3 through brew properly, and succesfully referenced it through C++ and XCode, but I wanted to do it in C and CLion.



The window is entirely black, until it is moved by dragging the title bar, which causes everything to work perfectly.










share|improve this question
























  • The program both compiles and runs, and it apparently calls at least some OpenGL functions successfully. I see no reason at all to conclude that there is any link issue. There could be a "my OpenGL library is broken" issue, but most likely the issue is that your OpenGL calls don't mean what you think they mean. Even if I knew what you were expecting to see, however, I'm not enough of an OpenGL person to easily recognize what you might be doing wrong.

    – John Bollinger
    Mar 22 at 21:56












  • I'm experienced in OpenGL with other languages like Java, so this should be clearing the window to white. But it doesn't.

    – mackycheese21
    Mar 22 at 21:57











  • Sorry! I figured it out. Mostly. Basically, it was working just fine, but only after the window had been dragged around.

    – mackycheese21
    Mar 22 at 23:56













1












1








1








I'm starting OpenGL with C, so I started up a CLion project and got started. For reference, I'm on a Mac 10.14.



This is my CMakeLists.txt:



cmake_minimum_required(VERSION 3.10)
project(GLMC C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH /usr/local/lib/cmake)
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/glfw3)

find_package (PkgConfig REQUIRED)
find_package (OpenGL REQUIRED)
find_package (glfw3 REQUIRED)

include_directories(/usr/local/include glad)
include_directories($GLFW_INCLUDE_DIRS)

find_library(COCOA_LIBRARY Cocoa REQUIRED)
find_library(IOKIT_LIBRARY IOKit REQUIRED)
find_library(COREVID_LIBRARY CoreVideo REQUIRED)

set(CMAKE_C_STANDARD 99)

add_executable(GLMC main.c glad.c)
target_link_libraries (GLMC
$OPENGL_LIBRARIES
$COCOA_LIBRARY
$COREVID_LIBRARY
$IOKIT_LIBRARY
$GLFW3_LIBRARY glfw)


And this is my main.c:



#include "glad.h"
#include <GLFW/glfw3.h>
#include "linmath.h"
#include <stdlib.h>
#include <stdio.h>
static const struct

float x, y;
float r, g, b;
vertices[3] =

-0.6f, -0.4f, 1.f, 0.f, 0.f ,
0.6f, -0.4f, 0.f, 1.f, 0.f ,
0.f, 0.6f, 0.f, 0.f, 1.f
;
static const char* vertex_shader_text =
"uniform mat4 MVP;n"
"attribute vec3 vCol;n"
"attribute vec2 vPos;n"
"varying vec3 color;n"
"void main()n"
"n"
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);n"
" color = vCol;n"
"n";
static const char* fragment_shader_text =
"varying vec3 color;n"
"void main()n"
"n"
" gl_FragColor = vec4(color, 1.0);n"
"n";
static void error_callback(int error, const char* description)

fprintf(stderr, "Error: %sn", description);

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)

if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);

int main(void)

GLFWwindow* window;
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
GLint mvp_location, vpos_location, vcol_location;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)

glfwTerminate();
exit(EXIT_FAILURE);

glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval(1);
// NOTE: OpenGL error checks have been omitted for brevity
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);
glCompileShader(vertex_shader);
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL);
glCompileShader(fragment_shader);
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
mvp_location = glGetUniformLocation(program, "MVP");
vpos_location = glGetAttribLocation(program, "vPos");
vcol_location = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(vpos_location);
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) 0);
glEnableVertexAttribArray(vcol_location);
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) (sizeof(float) * 2));
while (!glfwWindowShouldClose(window))

float ratio;
int width, height;
mat4x4 m, p, mvp;
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
mat4x4_identity(m);
mat4x4_rotate_Z(m, m, (float) glfwGetTime());
mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f);
mat4x4_mul(mvp, p, m);
glUseProgram(program);
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();

glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);




This is the sample code on their website.
I have this basic GLFW/GLAD code. The latest versions of glad.h, glad.c and khrplatform.h are properly referenced.



I have installed glfw3 through brew properly, and succesfully referenced it through C++ and XCode, but I wanted to do it in C and CLion.



The window is entirely black, until it is moved by dragging the title bar, which causes everything to work perfectly.










share|improve this question
















I'm starting OpenGL with C, so I started up a CLion project and got started. For reference, I'm on a Mac 10.14.



This is my CMakeLists.txt:



cmake_minimum_required(VERSION 3.10)
project(GLMC C)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH /usr/local/lib/cmake)
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/glfw3)

find_package (PkgConfig REQUIRED)
find_package (OpenGL REQUIRED)
find_package (glfw3 REQUIRED)

include_directories(/usr/local/include glad)
include_directories($GLFW_INCLUDE_DIRS)

find_library(COCOA_LIBRARY Cocoa REQUIRED)
find_library(IOKIT_LIBRARY IOKit REQUIRED)
find_library(COREVID_LIBRARY CoreVideo REQUIRED)

set(CMAKE_C_STANDARD 99)

add_executable(GLMC main.c glad.c)
target_link_libraries (GLMC
$OPENGL_LIBRARIES
$COCOA_LIBRARY
$COREVID_LIBRARY
$IOKIT_LIBRARY
$GLFW3_LIBRARY glfw)


And this is my main.c:



#include "glad.h"
#include <GLFW/glfw3.h>
#include "linmath.h"
#include <stdlib.h>
#include <stdio.h>
static const struct

float x, y;
float r, g, b;
vertices[3] =

-0.6f, -0.4f, 1.f, 0.f, 0.f ,
0.6f, -0.4f, 0.f, 1.f, 0.f ,
0.f, 0.6f, 0.f, 0.f, 1.f
;
static const char* vertex_shader_text =
"uniform mat4 MVP;n"
"attribute vec3 vCol;n"
"attribute vec2 vPos;n"
"varying vec3 color;n"
"void main()n"
"n"
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);n"
" color = vCol;n"
"n";
static const char* fragment_shader_text =
"varying vec3 color;n"
"void main()n"
"n"
" gl_FragColor = vec4(color, 1.0);n"
"n";
static void error_callback(int error, const char* description)

fprintf(stderr, "Error: %sn", description);

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)

if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);

int main(void)

GLFWwindow* window;
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
GLint mvp_location, vpos_location, vcol_location;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)

glfwTerminate();
exit(EXIT_FAILURE);

glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval(1);
// NOTE: OpenGL error checks have been omitted for brevity
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);
glCompileShader(vertex_shader);
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL);
glCompileShader(fragment_shader);
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
mvp_location = glGetUniformLocation(program, "MVP");
vpos_location = glGetAttribLocation(program, "vPos");
vcol_location = glGetAttribLocation(program, "vCol");
glEnableVertexAttribArray(vpos_location);
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) 0);
glEnableVertexAttribArray(vcol_location);
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
sizeof(float) * 5, (void*) (sizeof(float) * 2));
while (!glfwWindowShouldClose(window))

float ratio;
int width, height;
mat4x4 m, p, mvp;
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
mat4x4_identity(m);
mat4x4_rotate_Z(m, m, (float) glfwGetTime());
mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f);
mat4x4_mul(mvp, p, m);
glUseProgram(program);
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();

glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);




This is the sample code on their website.
I have this basic GLFW/GLAD code. The latest versions of glad.h, glad.c and khrplatform.h are properly referenced.



I have installed glfw3 through brew properly, and succesfully referenced it through C++ and XCode, but I wanted to do it in C and CLion.



The window is entirely black, until it is moved by dragging the title bar, which causes everything to work perfectly.







c opengl cmake glfw






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 23:56







mackycheese21

















asked Mar 22 at 21:16









mackycheese21mackycheese21

568416




568416












  • The program both compiles and runs, and it apparently calls at least some OpenGL functions successfully. I see no reason at all to conclude that there is any link issue. There could be a "my OpenGL library is broken" issue, but most likely the issue is that your OpenGL calls don't mean what you think they mean. Even if I knew what you were expecting to see, however, I'm not enough of an OpenGL person to easily recognize what you might be doing wrong.

    – John Bollinger
    Mar 22 at 21:56












  • I'm experienced in OpenGL with other languages like Java, so this should be clearing the window to white. But it doesn't.

    – mackycheese21
    Mar 22 at 21:57











  • Sorry! I figured it out. Mostly. Basically, it was working just fine, but only after the window had been dragged around.

    – mackycheese21
    Mar 22 at 23:56

















  • The program both compiles and runs, and it apparently calls at least some OpenGL functions successfully. I see no reason at all to conclude that there is any link issue. There could be a "my OpenGL library is broken" issue, but most likely the issue is that your OpenGL calls don't mean what you think they mean. Even if I knew what you were expecting to see, however, I'm not enough of an OpenGL person to easily recognize what you might be doing wrong.

    – John Bollinger
    Mar 22 at 21:56












  • I'm experienced in OpenGL with other languages like Java, so this should be clearing the window to white. But it doesn't.

    – mackycheese21
    Mar 22 at 21:57











  • Sorry! I figured it out. Mostly. Basically, it was working just fine, but only after the window had been dragged around.

    – mackycheese21
    Mar 22 at 23:56
















The program both compiles and runs, and it apparently calls at least some OpenGL functions successfully. I see no reason at all to conclude that there is any link issue. There could be a "my OpenGL library is broken" issue, but most likely the issue is that your OpenGL calls don't mean what you think they mean. Even if I knew what you were expecting to see, however, I'm not enough of an OpenGL person to easily recognize what you might be doing wrong.

– John Bollinger
Mar 22 at 21:56






The program both compiles and runs, and it apparently calls at least some OpenGL functions successfully. I see no reason at all to conclude that there is any link issue. There could be a "my OpenGL library is broken" issue, but most likely the issue is that your OpenGL calls don't mean what you think they mean. Even if I knew what you were expecting to see, however, I'm not enough of an OpenGL person to easily recognize what you might be doing wrong.

– John Bollinger
Mar 22 at 21:56














I'm experienced in OpenGL with other languages like Java, so this should be clearing the window to white. But it doesn't.

– mackycheese21
Mar 22 at 21:57





I'm experienced in OpenGL with other languages like Java, so this should be clearing the window to white. But it doesn't.

– mackycheese21
Mar 22 at 21:57













Sorry! I figured it out. Mostly. Basically, it was working just fine, but only after the window had been dragged around.

– mackycheese21
Mar 22 at 23:56





Sorry! I figured it out. Mostly. Basically, it was working just fine, but only after the window had been dragged around.

– mackycheese21
Mar 22 at 23:56












1 Answer
1






active

oldest

votes


















1














Turns out, this is a known bug on Mac Mojave. I fixed this by setting the window position (simulating a window drag) on the first iteration of the main loop:



bool hasWindowBeenFixed=false;

while(true)
glfwSwapBuffers(); // IMPORTANT: The fix only works AFTER swap buffers has been called
if(!hasWindowBeenFixed)
hasWindowBeenFixed=true;
glfwSetWindowPos(window,50,50);







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307896%2fmac-opengl-window-movement-required-to-show-something%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Turns out, this is a known bug on Mac Mojave. I fixed this by setting the window position (simulating a window drag) on the first iteration of the main loop:



    bool hasWindowBeenFixed=false;

    while(true)
    glfwSwapBuffers(); // IMPORTANT: The fix only works AFTER swap buffers has been called
    if(!hasWindowBeenFixed)
    hasWindowBeenFixed=true;
    glfwSetWindowPos(window,50,50);







    share|improve this answer



























      1














      Turns out, this is a known bug on Mac Mojave. I fixed this by setting the window position (simulating a window drag) on the first iteration of the main loop:



      bool hasWindowBeenFixed=false;

      while(true)
      glfwSwapBuffers(); // IMPORTANT: The fix only works AFTER swap buffers has been called
      if(!hasWindowBeenFixed)
      hasWindowBeenFixed=true;
      glfwSetWindowPos(window,50,50);







      share|improve this answer

























        1












        1








        1







        Turns out, this is a known bug on Mac Mojave. I fixed this by setting the window position (simulating a window drag) on the first iteration of the main loop:



        bool hasWindowBeenFixed=false;

        while(true)
        glfwSwapBuffers(); // IMPORTANT: The fix only works AFTER swap buffers has been called
        if(!hasWindowBeenFixed)
        hasWindowBeenFixed=true;
        glfwSetWindowPos(window,50,50);







        share|improve this answer













        Turns out, this is a known bug on Mac Mojave. I fixed this by setting the window position (simulating a window drag) on the first iteration of the main loop:



        bool hasWindowBeenFixed=false;

        while(true)
        glfwSwapBuffers(); // IMPORTANT: The fix only works AFTER swap buffers has been called
        if(!hasWindowBeenFixed)
        hasWindowBeenFixed=true;
        glfwSetWindowPos(window,50,50);








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 0:17









        mackycheese21mackycheese21

        568416




        568416





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307896%2fmac-opengl-window-movement-required-to-show-something%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해