#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();
}
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());
}
#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();
}
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());
}
To copy to clipboard, switch view to plain text mode
In the file sphere.pro as I set to get a successful compilation ?
Bookmarks