Opening a window with GLEW and GLFW
CMake
Minimal CMakeLists.txt to build an OpenGL application.
CMake
cmake_minimum_required(VERSION 3.15)
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release")
set(ProjectName "test00")
project(${ProjectName})
set(SOURCES "test00.cpp")
set(FILES ${SOURCES})
add_executable(${ProjectName} ${FILES})
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -std=gnu++11 -march=native")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
target_link_libraries(${ProjectName} glfw GLEW GL)
Minimal
Open a blank window.
cpp
#include
#include
#include
#include
int main(int argc, char** argv)
{
glewExperimental = true;
if(!glfwInit()){
fprintf(stderr, "Error: failed to initialize GLFW\n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 0);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Test00", NULL, NULL);
if(NULL == window){
fprintf(stderr, "Error: failed to open GLFW window\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if(GLEW_OK != glewInit()){
fprintf(stderr, "Error: failed to initialize GLEW\n");
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && 0 == glfwWindowShouldClose(window));
return 0;
}
Offscreen
Offscreen rendering only
cpp
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* offscreen_context = glfwCreateWindow(640, 480, "", NULL, NULL);
0 件のコメント:
コメントを投稿