>>683
Well it was surprisingly difficult, but I finally managed to get a system set up where I can make a simple OpenGL window with a spinning triangle. I got it working after switching to Manjaro (ARCH) Linux, and 'm using GLFW + GLAD. I had to install GLFW from the software manager, and I had cloned and built both GLFW and GLAD from github. I generated the GLAD files specific for my machine with the command:
python main.py --generator c --no-loader --out-path output
, and then copied the two include directories into /usr/include/ and the glad.c file into my project directory (as per the GLAD instructions). I used the code example from here:
www.glfw.org/docs/latest/quick.html
The image is a capp of the simple OpenGL window result.
Here's the simplest blank window code (w/o animation) that I managed to get working:
// based on code at:
// http://www.glfw.org/docs/latest/quick.html
#include <glad/glad.h> // NOTE: must be #include'd before glfw3.h
#include <GLFW/glfw3.h>
#include <iostream>
//------------------------------------------------------------------------------
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()
{
if (!glfwInit()) {
std::cerr << "Failed to init OpenGL\n";
return -1;
}
GLFWwindow* window = glfwCreateWindow(
640, 480, "Even simpler example", nullptr, nullptr);
if (!window) {
std::cerr << "Failed to create a window\n";
glfwTerminate();
return -1;
}
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
// NOTE: Leaving this directive out causes a failure with a return code 139 on
// my box
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cerr << "Failed to initialize GLAD\n";
glfwDestroyWindow(window); // NOTE: Are these needed here?
glfwTerminate(); //
return -1;
}
glfwSwapInterval(1);
while (!glfwWindowShouldClose(window)) {
// DESIGN: Any rendering code would go here:
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
Here's my basic CMakeLists.txt file to go with that code:
cmake_minimum_required(VERSION 2.8)
project(simple)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wno-unused-parameter")
add_executable(simple main.cpp glad.c)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
target_link_libraries(simple ${GLFW_LIBRARIES} )
Simple I know, but hey we all have to start somewhere yea? Now I'll begin trying to figure out how to manage creating, saving and loading geometry data on the disk files from inside the code. That should let me start exploring how to create and display environment and object geometries to use in my OpenGL windows. Once that's basically working, I could then start thinking about things like better shaders, etc. But on my old notebook machine right now I only have OpenGL v 2.1 (an Intel Mobile 4 series integrated graphics controller) so I don't expect to do anything remarkable atm. OTOH, this also means my stuff should be compatible w/ basically everyone's graphics setup if it becomes something I package up sometime.
Also, now that I have a reasonably usable OpenGL dev box I've begun working through this book:
learnopengl.com/
>===
-
julay fmt bug edit
Edited last time by Chobitsu on 10/27/2023 (Fri) 05:29:28.