Mike Werner wrote:
> [..] In fact I can't get any shaded polygons to show up correctly!
Try this example. Just whipped it together based on one of
the other opengl examples on my 'fltk cheat' page.
It's been many, many years since I've done anything that
with lights and materials in opengl, but I think this is right.
#ifdef _WIN32
#include <windows.h>
#endif
#include <math.h>
#include <FL/Fl.h>
#include <FL/Fl_Window.h>
#include <FL/Fl_Gl_Window.h>
#include <FL/gl.h>
#include <FL/glut.h>
//
// Render a simple opengl shaded sphere with a single side light -- erco
11/28/08
// NOTE: Glut needed *only* for glutSolidSphere()
//
class MyGlWindow : public Fl_Gl_Window {
public:
// RESHAPE THE VIEWPORT
void Reshape(GLfloat W, GLfloat H) {
// (REFERENCE: SGI light.c DEMO)
GLfloat ratio = W / 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();
}
void draw() {
if (!valid()) {
valid(1);
Reshape(w(), h());
// (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();
}
// CTOR
MyGlWindow(int X,int Y,int W,int H,const char*L=0) :
Fl_Gl_Window(X,Y,W,H,L) {
}
};
int main() {
Fl_Window win(640, 480);
MyGlWindow mygl(10, 10, win.w()-20, win.h()-20);
win.resizable(&mygl);
win.show();
return(Fl::run());
}
_______________________________________________
fltk-opengl mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-opengl