giorgik
26th December 2012, 19:28
Hello to all. I found an example of a program that uses the libraries FLTK and OpenGL. These same examples can be used very well in Qt. Below I report the sample project.
OpenGLSphere.pro:
QT += core
QT -= gui
TARGET = OpenGLSphere
#CONFIG += console così non appare la finestra dos
CONFIG -= app_bundle
TEMPLATE = app
#------------------------------------------------
#
# Uso librerie FLTK 1.3.1
#
#------------------------------------------------
INCLUDEPATH += C:/MinGW/include \
C:/MinGW/include/FL/images
DEFINES += WIN32 USE_OPENGL32="1" LARGEFILE_SOURCE="1" LARGEFILE64_SOURCE="1"
LIBS += -mwindows \
-L C:/MinGW/lib \
-lfltk \
-lfltk_forms \
-lfltk_gl \
-lfltk_images \
-lfltk_jpeg \
-lfltk_png \
-lfltk_z \
-lole32 -luuid -lcomctl32
#------------------------------------------------
#
# Uso librerie Gl (OpenGL)
#
#------------------------------------------------
LIBS += -L C:/MinGW/lib \
#-lglaux \
-lopenglut \
-lglu32 \
-lopengl32 \
-lwinmm -lgdi32
SOURCES += main.cpp
HEADERS += \
simple.h
simple.h:
#ifndef SIMPLE_H
#define SIMPLE_H
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/glut.H>
#include <FL/gl.h>
#define WIDTH 640
#define HEIGHT 480
//
// Render a simple opengl shaded sphere with a single side light -- erco 11/28/08
//
// 1.1 Mods to use pure glut calls for subwindow -- erco 03/15/11
//
// You can build this example with: fltk-config --use-glut --compile sphere.cxx
//
// GLUT: RESHAPE THE VIEWPORT
void Reshape(int W, int H)
{
// (REFERENCE: SGI light.c DEMO)
GLfloat ratio = (float)W / (float)H;
glViewport(0, 0, (GLsizei)W, (GLsizei)H);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.5 * ratio, 1.5 * ratio, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// GLUT: REDRAW THE SCENE
void Redraw()
{
static int valid = 0;
if (!valid)
{
valid = 1;
Reshape(WIDTH, HEIGHT);
// (REFERENCE: SGI 'light.c' EXAMPLE)
GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
GLfloat light_position[] = { 5.0, 5.0, 0.0, 0.0 }; // XYZ
glClearColor(0.0, 0.0, 0.4, 0.0); // bg color
glShadeModel(GL_SMOOTH);
//
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, 20.0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(0.5, 0.5, 0.5);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
#endif // SIMPLE_H
main.cpp:
#include "simple.h"
int main(int argc, char *argv[])
{
Fl_Window win(WIDTH, HEIGHT, "sphere");
win.resizable(win);
win.show(argc, argv);
// Docs say to add glut subwindow /after/ calling win.show()
win.begin();
// glutInit(&argc, argv); // docs say not to call this if a subwindow
glutInitWindowSize(WIDTH - 20, HEIGHT - 20);
glutInitWindowPosition(10, 10); // place inside parent window
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutCreateWindow("sphere");
glutReshapeFunc(Reshape);
glutDisplayFunc(Redraw);
win.end();
return(Fl::run());
}
This code fails to compile in MinGW fine, but if I try to do it in the ide QtCreator 2.6.0 fails as it finds defined 2 functions:
glut_compatability.cxx:-1: error: undefined reference to `Fl::remove_idle(void (*)(void*), void*)'
glut_compatability.cxx:-1: error: undefined reference to `Fl::add_idle(void (*)(void*), void*)'
Can you help me solve this problem ?
OpenGLSphere.pro:
QT += core
QT -= gui
TARGET = OpenGLSphere
#CONFIG += console così non appare la finestra dos
CONFIG -= app_bundle
TEMPLATE = app
#------------------------------------------------
#
# Uso librerie FLTK 1.3.1
#
#------------------------------------------------
INCLUDEPATH += C:/MinGW/include \
C:/MinGW/include/FL/images
DEFINES += WIN32 USE_OPENGL32="1" LARGEFILE_SOURCE="1" LARGEFILE64_SOURCE="1"
LIBS += -mwindows \
-L C:/MinGW/lib \
-lfltk \
-lfltk_forms \
-lfltk_gl \
-lfltk_images \
-lfltk_jpeg \
-lfltk_png \
-lfltk_z \
-lole32 -luuid -lcomctl32
#------------------------------------------------
#
# Uso librerie Gl (OpenGL)
#
#------------------------------------------------
LIBS += -L C:/MinGW/lib \
#-lglaux \
-lopenglut \
-lglu32 \
-lopengl32 \
-lwinmm -lgdi32
SOURCES += main.cpp
HEADERS += \
simple.h
simple.h:
#ifndef SIMPLE_H
#define SIMPLE_H
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/glut.H>
#include <FL/gl.h>
#define WIDTH 640
#define HEIGHT 480
//
// Render a simple opengl shaded sphere with a single side light -- erco 11/28/08
//
// 1.1 Mods to use pure glut calls for subwindow -- erco 03/15/11
//
// You can build this example with: fltk-config --use-glut --compile sphere.cxx
//
// GLUT: RESHAPE THE VIEWPORT
void Reshape(int W, int H)
{
// (REFERENCE: SGI light.c DEMO)
GLfloat ratio = (float)W / (float)H;
glViewport(0, 0, (GLsizei)W, (GLsizei)H);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.5 * ratio, 1.5 * ratio, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// GLUT: REDRAW THE SCENE
void Redraw()
{
static int valid = 0;
if (!valid)
{
valid = 1;
Reshape(WIDTH, HEIGHT);
// (REFERENCE: SGI 'light.c' EXAMPLE)
GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
GLfloat light_position[] = { 5.0, 5.0, 0.0, 0.0 }; // XYZ
glClearColor(0.0, 0.0, 0.4, 0.0); // bg color
glShadeModel(GL_SMOOTH);
//
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, 20.0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(0.5, 0.5, 0.5);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
#endif // SIMPLE_H
main.cpp:
#include "simple.h"
int main(int argc, char *argv[])
{
Fl_Window win(WIDTH, HEIGHT, "sphere");
win.resizable(win);
win.show(argc, argv);
// Docs say to add glut subwindow /after/ calling win.show()
win.begin();
// glutInit(&argc, argv); // docs say not to call this if a subwindow
glutInitWindowSize(WIDTH - 20, HEIGHT - 20);
glutInitWindowPosition(10, 10); // place inside parent window
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutCreateWindow("sphere");
glutReshapeFunc(Reshape);
glutDisplayFunc(Redraw);
win.end();
return(Fl::run());
}
This code fails to compile in MinGW fine, but if I try to do it in the ide QtCreator 2.6.0 fails as it finds defined 2 functions:
glut_compatability.cxx:-1: error: undefined reference to `Fl::remove_idle(void (*)(void*), void*)'
glut_compatability.cxx:-1: error: undefined reference to `Fl::add_idle(void (*)(void*), void*)'
Can you help me solve this problem ?