feat: include glew on linux
This commit is contained in:
parent
4cbe93321d
commit
3944a76d6d
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.27)
|
cmake_minimum_required(VERSION 3.27)
|
||||||
project(HelloOpenGL)
|
project(HelloGLEW)
|
||||||
|
|
||||||
# Define platform-specific paths and libraries
|
# Define platform-specific paths and libraries
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
@ -8,11 +8,17 @@ if(WIN32)
|
||||||
include_directories(${GLFW_PATH}/include)
|
include_directories(${GLFW_PATH}/include)
|
||||||
link_directories(${GLFW_PATH}/lib-vc2022)
|
link_directories(${GLFW_PATH}/lib-vc2022)
|
||||||
|
|
||||||
|
# GLEW
|
||||||
|
set(GLEW_PATH "C:/libs/glew-2.2.0")
|
||||||
|
include_directories(${GLEW_PATH}/include)
|
||||||
|
link_directories(${GLEW_PATH}/lib)
|
||||||
|
|
||||||
# OpenGL
|
# OpenGL
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(GLFW REQUIRED glfw3)
|
pkg_search_module(GLFW REQUIRED glfw3)
|
||||||
|
find_package(GLEW REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
message(FATAL_ERROR "Linux and macOS platforms are not supported yet.")
|
message(FATAL_ERROR "Linux and macOS platforms are not supported yet.")
|
||||||
|
@ -22,9 +28,12 @@ add_executable(${PROJECT_NAME} hello.cpp)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(${PROJECT_NAME} glfw3)
|
target_link_libraries(${PROJECT_NAME} glfw3)
|
||||||
|
target_link_libraries(${PROJECT_NAME} glew)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE ${GLEW_INCLUDE_DIRS})
|
||||||
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
|
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
include_directories(${GLFW_INCLUDE_DIRS})
|
include_directories(${GLFW_INCLUDE_DIRS})
|
||||||
target_link_libraries(${PROJECT_NAME} ${GLFW_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME} ${GLFW_LIBRARIES})
|
||||||
|
target_link_libraries(${PROJECT_NAME} GLEW::GLEW)
|
||||||
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
|
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
|
||||||
endif()
|
endif()
|
||||||
|
|
12
hello.cpp
12
hello.cpp
|
@ -24,15 +24,18 @@
|
||||||
// To compile on Arch Linux
|
// To compile on Arch Linux
|
||||||
//
|
//
|
||||||
// Install dependencies
|
// Install dependencies
|
||||||
// sudo pacman -S glfw mesa
|
// sudo pacman -S glfw mesa glew
|
||||||
//
|
//
|
||||||
// Build
|
// Build
|
||||||
// cmake ..
|
// cmake ..
|
||||||
// cmake --build .
|
// cmake --build .
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
|
@ -47,6 +50,13 @@ int main()
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
glewExperimental = GL_TRUE;
|
||||||
|
if (glewInit() != GLEW_OK)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to initialize GLEW" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
Loading…
Reference in New Issue