After much studying of cmake configuration, I got this program to build and run. Environment:
C++11
MacOS 14.2.1
FLTK library 1.3.9
But it draws nothing, the Fl_Gl_Window remains black. Any ideas? Recommendations for diagnostic steps? I have already tried changing the color from white to: glColor3f(0.5, 1.0, 1.0);
to no avail.
The code (based on a starter I got from chatgpt):
#define GL_SILENCE_DEPRECATION
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
#include <OpenGL/glu.h>
void glutWireSphere (GLdouble radius, GLint slices, GLint stacks);
class MyGlWindow : public Fl_Gl_Window {
public:
MyGlWindow(int x, int y, int w, int h, const char* l = 0) : Fl_Gl_Window(x, y, w, h, l) {}
void draw() override {
if (!valid()) {
glLoadIdentity();
glViewport(0, 0, w(), h());
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glEnable(GL_DEPTH_TEST);
valid(1);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set up the camera
gluLookAt(0.0, 0.0, 3.0, // eye position
0.0, 0.0, 0.0, // look-at position
0.0, 1.0, 0.0); // up direction
// Draw a sphere
glColor3f(0.5, 1.0, 1.0);
glutWireSphere(1.0, 20, 20);
glFlush();
}
};
int main() {
Fl_Window* window = new Fl_Window(400, 400, "FLTK Sphere Example");
MyGlWindow* glWindow = new MyGlWindow(10, 10, window->w() - 20, window->h() - 20);
window->resizable(glWindow);
window->end();
window->show();
return Fl::run();
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(HelloFLTK)
set(CMAKE_PREFIX_PATH "/opt/homebrew")
find_package(FLTK REQUIRED)
include_directories(${FLTK_INCLUDE_DIRS} /opt/homebrew/include)
link_directories(${FLTK_LIBRARY_DIRS})
add_executable(HelloFLTK flsphere.cpp)
target_compile_features(HelloFLTK PUBLIC cxx_std_11)
target_link_libraries(HelloFLTK ${FLTK_LIBRARIES})
BTW GL_SILENCE_DEPRECATION is needed because Apple, in their infinite wisdom, is threatening to get rid of OpenGL entirely. I am trying hard to resurrect and enjoy a piece of legacy code before that happens!