Sunday, September 25, 2011

C++ FLTK (X,Y) AXIS TUTORIAL







REVISED: Friday, March 22, 2013


CONTENTS:
I.      INTRODUCTION
II.     BACKGROUND WINDOW
III.    (X,Y) Axis
IV.    POLYGON
V.     RECTANGLE
VI.    CIRCLE
VII.   ELLIPSE
VIII.  MARK
IX.    SCREEN SAVER

YOU WILL LEARN HOW TO CODE A C++ FLTK:
1. AXIS
2. POLYGON
3. RECTANGLE
4. CIRCLE
5. ELLIPSE
6. MARK
7. SCREEN SAVER

I. INTRODUCTION


Welcome to the “C++ FLTK (X,Y) Axis Tutorial.”

This tutorial is a very brief overview of information presented by:

Dr. Bjarne Stroustrup in his book “Programming Principles and Practices Using C++,” Addison-Wesley 2009, ISBN 978-0321543721.

The web site for his book and the appropriate FLTK .h header files and .cpp files is:

http://www.stroustrup.com/Programming/


Please copy paste the following example program into your IDE. Build and debug the example program and it will help you understand the information covered in this tutorial.

//***********************************
//C++ FLTK (X,Y) AXIS TUTORIAL
//***********************************
#include "Simple_window.h"
#include "Graph.h"

int main( int argc, char* argv[] )
{
   //========================START BACKGROUND WINDOW
   using namespace Graph_lib;
   Point tl(100, 0);
   Simple_window win(Point(100,100),600,450,"(X,Y) Axis");
   //========================START (X,Y) Axis
   Axis X_Axis(Axis::x, Point(0,400),550, 40, "X Axis");
   win.attach(X_Axis);
   X_Axis.label.set_color(Color::blue);
 
   Axis Y_Axis(Axis::y, Point(250,400),350, 20, "Y Axis");
   win.attach(Y_Axis);
   Y_Axis.label.set_color(Color::blue);
 
   win.set_label("(X,Y) AXIS");
   //========================START POLYGON
   Polygon poly;
   poly.add(Point(50,0));        
//Triangle top (x,y) coordinate point.
   poly.add(Point(0,100));      
//Triangle bottom, left  (x,y) coordinate point.
   poly.add(Point(100,100));  
//Triangle bottom, right (x,y) coordinate point.
   poly.set_fill_color(Color::red);
   win.attach(poly);
   //========================START RECTANGLE
   Rectangle r(Point(110,5), 100, 100);
   r.set_fill_color(Color::yellow);
   win.attach(r);
   //========================START CIRCLE
   Circle c(Point(110,210), 100);
   c.set_color(Color::dark_cyan);
   win.attach(c);
   //========================START ELLIPSE
   Ellipse e(Point(300,300),75,25);
   e.set_color(Color::dark_green);
   win.attach(e);
   //========================START MARK
   Mark m(Point(300,300),'x');
   win.attach(m);
   //========================START SCREEN SAVER
   win.wait_for_button();
   //==========================
}


Looking close you will see a repeating pattern for this FLTK code.

First, a FLTK keyword describes a geometric primitive; e.g., Rectangle.

Second, you name your function; e.g., r.

Third, you define a starting point; e.g., Point(110,5); the top left corner.

Fourth, you define the horizontal distance and the vertical distance; e.g., 100, 100; the width and height.

Fifth, you set the color; e.g., r.set_fill_color(Color::yellow);

Sixth, you attach the geometric primitive to win; e.g., win.attach®;

II. BACKGROUND WINDOW

//========================START BACKGROUND WINDOW
   using namespace Graph_lib;
   Point tl(100, 0);
   Simple_window win(Point(100,100),600,450,"(X,Y) Axis");

We are using the Graph library.


We define the top left corner of our window; e.g., Point tl(100, 0);


We are using Simple_window so we will have the "Next" button.

The window will start at Point(100,100); the horizontal x axis distance from this point will be 600, and the vertical y axis distance will be 450; and the label for the window will be "(X,Y) Axis."

III. (X,Y) Axis

//========================START (X,Y) Axis
   Axis X_Axis(Axis::x, Point(0,400),550, 40, "X Axis");
   X_Axis.label.set_color(Color::blue);
   win.attach(X_Axis);
 
   Axis Y_Axis(Axis::y, Point(250,400),350, 20, "Y Axis");
   win.attach(Y_Axis);
   Y_Axis.label.set_color(Color::blue);
 
   win.set_label("(X,Y) AXIS");

X_Axis


First, a FLTK keyword describes a geometric primitive; e.g., Axis, which is a line.

Second, you name your function; e.g., X_Axis.

Third, you define a starting point; e.g., Point(0,400).

Fourth, you define the horizontal distance; e.g., 550 is the x-axis length and 40 is the measurement increments on the x-axis.

Fifth, you set the color; e.g., X_Axis.label.set_color(Color::blue);

Sixth, you attach the geometric primitive to win; e.g., win.attach(X_Axis);

Y_Axis

First, a FLTK keyword describes a geometric primitive; e.g., Axis, which is a line.

Second, you name your function; e.g., Y_Axis.

Third, you define a starting point; e.g., Point(250,400).

Fourth, you define the vertical distance; from Point(250,400) e.g., 350, and 20 is the y-axis measurement increments.

Fifth, you set the color; e.g., Y_Axis.label.set_color(Color::blue);

Sixth, you attach the geometric primitive to win; e.g., win.attach(Y_Axis);

IV. POLYGON

//========================START POLYGON
   Polygon poly;
   poly.add(Point(50,0));    
//Triangle top (x,y) coordinate point.
   poly.add(Point(0,100));  
//Triangle bottom, left  (x,y) coordinate point.
   poly.add(Point(100,100));  
//Triangle bottom, right (x,y) coordinate point.
   poly.set_fill_color(Color::red);
   win.attach(poly);


First, a FLTK keyword describes a geometric primitive; e.g., Polygon.

Second, you name your function; e.g., poly.

Third, you define a starting point; e.g., Point(50,0) the top; Point(0,100) the bottom, left; and Point(100,100) the bottom right.

Fourth, you set the color; e.g., r.set_fill_color(Color::red);

Fifth, you attach the geometric primitive to win; e.g., win.attach(poly);

V. RECTANGLE

//========================START RECTANGLE
  Rectangle r(Point(110,5), 100, 100);
  r.set_fill_color(Color::yellow);
  win.attach(r);


First, a FLTK keyword describes a geometric primitive; e.g., Rectangle.

Second, you name your function; e.g., r.

Third, you define a starting point; e.g., Point(110,5); the top left point.

Fourth, you define the horizontal distance and the vertical distance; e.g., 100, 100; the width and height.

Fifth, you set the color; e.g., r.set_fill_color(Color::yellow);

Sixth, you attach the geometric symbol to win; e.g., win.attach( r );

VI. CIRCLE

//========================START CIRCLE
   Circle c(Point(110,210), 100);
   c.set_color(Color::dark_cyan);
   win.attach(c);


First, a FLTK keyword describes a geometric primitive; e.g., Circle.

Second, you name your function; e.g., c.

Third, you define a starting point; e.g., Point(110,210).

Fourth, you define the horizontal distance and the vertical distance; e.g., 100 which is the radius.

Fifth, you set the color; e.g., c.set_color(Color::dark_cyan);

Sixth, you attach the geometric primitive to win; e.g., win.attach( c );

VII. ELLIPSE

//========================START ELLIPSE
   Ellipse e(Point(300,300),75,25);
   e.set_color(Color::dark_green);
   win.attach(e);


First, a FLTK keyword describes a geometric primitive; e.g., Ellipse.

Second, you name your function; e.g., e.

Third, you define a starting point; e.g., Point(300,300).

Fourth, you define the horizontal distance and the vertical distance; e.g., 100, 100.

Fifth, you set the color; e.g., r.set_fill_color(Color::yellow);

Sixth, you attach the geometric symbol to win; e.g., win.attach(e);

VIII. MARK

//========================START MARK
   Mark m(Point(300,300),'x');
   win.attach(m);


First, a FLTK keyword describes a geometric primitive; e.g., Mark.

Second, you name your function; e.g., m.

Third, you define a starting point; e.g., Point(300,300).

IX. SCREEN SAVER

//========================START SCREEN SAVER
   win.wait_for_button();


Screen saver might not be a good choice of words but it saves the screen until you click the "Next" button. This give you time to admire your work!

YOU HAVE LEARNED HOW TO CODE A C++ FLTK:
1. AXIS
2. POLYGON
3. RECTANGLE
4. CIRCLE
5. ELLIPSE
6. MARK
7. SCREEN SAVER

Elcric Otto Circle




-->

-->

-->




How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




C++ FLTK OPENGL 3D ANIMATION TUTORIAL









REVISED: Friday, March 22, 2013



CONTENTS:
I.     INTRODUCTION
II.    INSTALLING OPENGL
III.   USING FLTK IN MICROSOFT VISUAL STUDIO
IV.   3D ANIMATION USING FLTK AND OPENGL

YOU WILL LEARN HOW TO:
1. INSTALL AND USE OPENGL WITH FLTK.
2. CODE 3D ANIMATION WITH FLTK OPENGL.

I. INTRODUCTION


Welcome to the “C++ FLTK OPENGL 3D ANIMATION TUTORIAL"

II. INSTALLING OPENGL


There are lots of free download websites you can Google; this is one of the many for OpenGL95:

http://download-opengl-graphics.com/


Download and use WinZip or a similar package to extract the OpenGL95.zip file to your C:\ drive.

III. USING FLTK IN MICROSOFT VISUAL STUDIO


Use the following steps to use OpenGL with FLTK in Microsoft Visual Studio:

1. Open Visual Studio


Use the same Win32 console application empty project you have been using for all of your non-OpenGL FLTK applications.


2. From the Visual Studio main top menu choose Project and from the drop-down menu choose Properties.

To expand a sub-menu click the Linker folder in the left menu of the Properties dialog box. In the sub-menu click Input. On the right, in the additional dependencies text field you should see the following entries we added for FLTK:

fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib


At the end of this list add the following four libraries:

opengl32.lib glu32.lib fltkgld.lib glaux.lib


In the “Ignore Specific Library” text field you should already have the following text if you do not have it add it now:

libcd.lib


In the left menu of the Properties window click C\C++ to expand a sub-menu. Click the “Code Generation” sub-menu item. On the right, if it has not already been changed, change the “Runtime Library” drop-down to:

Multi-threaded Debug DLL (\MDd)

Click OK to close the Properties window.

IV. 3D ANIMATION USING FLTK AND OPENGL


Please copy and paste the following example into your IDE. You have to use the same Project file we just setup. It will not work in other Project files until you set them up the same way we did the one above. Then, build and debug the example program to test to see if you can now code in OpenGL using FLTK.

//***********************************
//Texture Mapped Cube
//erco/loic 03/17/09
//***********************************
#include <cmath>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#include <stdio.h>
#include <math.h>
#include <FL/Fl.H>
#include <FL/Fl_window.H>
#include <FL/Fl_Gl_window.H>
#include <FL/gl.h>

//***********************************
//OpenGL spinning cube with
//checker texturemap
//***********************************
#define WIN_W 400      
//window width
#define WIN_H 400       
//window height
#define TEX_W 64        
//texturemap width
#define TEX_H 64        
//texturemap height
#define FPS (1.0/24.0)  
//frames per second playback

//***********************************
//OpenGL class to show
//texturemapped cube
//***********************************
class MyGlWindow : public Fl_Gl_Window {
    double spin;
    GLuint TexID;
//***********************************
//TIMER CALLBACK
//Handles rotation the object
//***********************************
    static void Timer_CB(void *userdata) {
        MyGlWindow *mygl = (MyGlWindow*)userdata;
        mygl->spin += 2.0;      
//spin
        mygl->redraw();
        Fl::repeat_timeout(FPS, Timer_CB, userdata);
    }
public:
//CTOR
    MyGlWindow(int x,int y,int w,int h,const char *l=0) : Fl_Gl_Window(x,y,w,h,l) {
        spin = 0.0;
        Fl::add_timeout(FPS, Timer_CB, (void*)this);       
//24fps timer
    }
//***********************************
//PERSPECTIVE VIEW
//Same as gluPerspective()..
//***********************************
    void Perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) {
        GLdouble xmin, xmax, ymin, ymax;
        ymax = zNear * tan(fovy * M_PI / 360.0);
        ymin = -ymax;
        xmin = ymin * aspect;
        xmax = ymax * aspect;
        glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
    }
//***********************************
//RESHAPED VIEWPORT
//OpenGL
//window changes size
//***********************************
    void ReshapeViewport() {
//***********************************
//Viewport
//***********************************
        glViewport(0, 0, w(), h());
//***********************************
//Projection
//***********************************
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        GLfloat ratio = w() / h();
        Perspective(30.0, 1.0*ratio, 1.0, 30.0);
        glTranslatef(0.0, 0.0, -8.0);
//***********************************
//Model view
//***********************************
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
//***********************************
//OPENGL INITIALIZATION
//OpenGL do *only once* on startup.
//***********************************
    void GlInit() {
//***********************************
//Make sure we only do this once
//***********************************
        static int first_time = 1;
        if ( first_time ) {
            first_time = 0;
//***********************************
//Texture Map Init
//***********************************
            GLubyte img[TEX_W][TEX_H][3]; //after glTexImage2D(), array is no longer needed
            glGenTextures(1, &TexID);
            glBindTexture(GL_TEXTURE_2D, TexID);
//***********************************
//Texture Mapping Mode
//Uncomment one of the following lines:
//GL_DECAL or GL_MODULATE
//glTexEnvf(GL_TEXTURE_ENV,
//GL_TEXTURE_ENV_MODE,
//GL_DECAL);   
//use actual texture colors
//***********************************
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);  
//texture colors affected by poly's color

            for (int x=0; x<TEX_W; x++) {
                for (int y=0; y<TEX_H; y++) {
//***********************************
//Texture Pattern
//Uncomment one of the following lines:
//checkboard or basketweave
//GLubyte c = ((x&16)^(y&16)) ? ((x%16)
//<<4) : (((x%16)^15)<<4); //basket weave
//***********************************
                    GLubyte c = ((x&16)^(y&16)) ? 255 : 0;                        
//checkerboard
                    img[x][y][0] = c;
                    img[x][y][1] = c;
                    img[x][y][2] = c;
                }
            }
            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEX_W, TEX_H, 0, GL_RGB, GL_UNSIGNED_BYTE, &img[0][0][0]);
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glEnable(GL_TEXTURE_2D);
//***********************************
//OpenGL settings
//***********************************
            glShadeModel(GL_FLAT);
            glEnable(GL_DEPTH_TEST);
            glDepthFunc(GL_LEQUAL);
        }
    }
//***********************************
//FLTK DRAW
//Called by FLTK to draw the scene.
//***********************************
    void draw() {
//***********************************
//Initialize/handle reshaped viewport
//***********************************
        if ( !valid() ) {
            valid(1);
            GlInit();
            ReshapeViewport();
        }
//***********************************
//Clear
//***********************************
        glClearColor(.5,.5,.5, 0.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//***********************************
//Setup model matrix
//***********************************
        glLoadIdentity();
        glRotatef(spin, 0.5, 1.0, 0.0); 
//show all sides of cube

//***********************************
//Draw cube with texture assigned
//to each face
//***********************************
        glBegin(GL_QUADS);
//***********************************
//Front Face
//***********************************
        glColor3f(1.0, 0.0, 0.0); 
//red
        glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0,  1.0); 
//Top Left Of The Texture and Quad
        glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0,  1.0); 
//Top Right Of The Texture and Quad
        glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0,  1.0); 
//Bottom Right Of The Texture and Quad
        glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0,  1.0); 
//Bottom Left Of The Texture and Quad
//***********************************
//Back Face
//***********************************
        glColor3f(0.0, 1.0, 1.0); 
//cyn
        glTexCoord2f(0.0, 1.0); glVertex3f( 1.0,  1.0, -1.0); 
//Top Left Of The Texture and Quad
        glTexCoord2f(1.0, 1.0); glVertex3f(-1.0,  1.0, -1.0); 
//Top Right Of The Texture and Quad
        glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0); 
//Bottom Right Of The Texture and Quad
        glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0, -1.0); 
//Bottom Left Of The Texture and Quad
//***********************************
//Top Face
//***********************************
        glColor3f(0.0, 1.0, 0.0); 
//grn
        glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0, -1.0); 
//Top Left Of The Texture and Quad
        glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0, -1.0); 
//Top Right Of The Texture and Quad
        glTexCoord2f(1.0, 0.0); glVertex3f( 1.0,  1.0,  1.0); 
//Bottom Right Of The Texture and Quad
        glTexCoord2f(0.0, 0.0); glVertex3f(-1.0,  1.0,  1.0); 
//Bottom Left Of The Texture and Quad
//***********************************
//Bottom Face
//***********************************
        glColor3f(1.0, 0.0, 1.0); 
//mag
        glTexCoord2f(0.0, 1.0); glVertex3f( 1.0, -1.0, -1.0); 
//Top Left Of The Texture and Quad
        glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, -1.0, -1.0); 
//Top Right Of The Texture and Quad
        glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0,  1.0); 
//Bottom Right Of The Texture and Quad
        glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0,  1.0); 
//Bottom Left Of The Texture and Quad
//***********************************
//Right face
//***********************************
        glColor3f(0.0, 0.0, 1.0); 
//blu
        glTexCoord2f(0.0, 1.0); glVertex3f( 1.0,  1.0,  1.0); 
//Top Left Of The Texture and Quad
        glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0, -1.0); 
//Top Right Of The Texture and Quad
        glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, -1.0); 
//Bottom Right Of The Texture and Quad
        glTexCoord2f(0.0, 0.0); glVertex3f( 1.0, -1.0,  1.0); 
//Bottom Left Of The Texture and Quad
//***********************************
//Left Face
//***********************************
        glColor3f(1.0, 1.0, 0.0); 
//yel
        glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0, -1.0); 
//Top Left Of The Texture and Quad
        glTexCoord2f(1.0, 1.0); glVertex3f(-1.0,  1.0,  1.0); 
//Top Right Of The Texture and Quad
        glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0,  1.0); 
//Bottom Right Of The Texture and Quad
        glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0); 
//Bottom Left Of The Texture and Quad
        glEnd();
//***********************************
//DEBUG: CHECK FOR ERRORS
//***********************************
        GLenum err = glGetError();
        if ( err != GL_NO_ERROR ) {
            fprintf(stderr, "GLGETERROR=%d\n", (int)err);
        }
    }
};
int main(int argc, char *argv[]) {
    MyGlWindow* mygl = new MyGlWindow(10, 10, WIN_W-20, WIN_H-20, "Texture Test");
    mygl->end();
    mygl->resizable(mygl);
    mygl->show();
    return(Fl::run());
}

YOU HAVE  LEARNED HOW TO:
1. INSTALL AND USE OPENGL WITH FLTK.
2. CODE 3D ANIMATION WITH FLTK OPENGL.

Elcric Otto Circle







-->

-->

-->




How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




C++ FLTK INSTALL OPENGL TUTORIAL









REVISED: Friday, March 22, 2013




CONTENTS:
I.     INTRODUCTION
II.   EXAMPLE 1 - C++ CLASS DERIVED FROM FLTK WIDGET
III. INSTALLING OPENGL
IV. USING OPENGL WITH FLTK IN MICROSOFT VISUAL STUDIO
V.  EXAMPLE 2 - OPENGL TEXT ON A ROTATING 3D OBJECT

YOU WILL LEARN HOW TO:
1. CODE A C++ CLASS DERIVED FROM A FLTK WIDGET.
2. INSTALL AND USE OPENGL WITH FLTK.

I. INTRODUCTION


Welcome to the “C++ FLTK INSTALL OPENGL TUTORIAL”

This tutorial is a very brief overview of information presented by Dr. Bjarne Stroustrup in his book “Programming Principles and Practices Using C++,” Addison-Wesley 2009, ISBN 978-0321543721.

The web site for his book and the appropriate FLTX header files is:

http://www.stroustrup.com/Programming/

II. EXAMPLE 1 - C++ CLASS DERIVED FROM FLTK WIDGET


Please copy and paste Example 1 into your IDE then build and debug.

//***********************************
//Exampe 1
//C++ CLASS DERIVED FROM FLTK WIDGET
//***********************************
#include <Fl/Fl.H>            
//Required by all FLTK programs.
#include <Fl/Fl_window.H>  
//Required for window class.
#include <FL/FL_Button.H>  
//Required for button class.
#include <stdio.h>            
//Required for display.
#include <stdlib.h>

class Passes_Userdata : public Fl_Window
{
   private:

      static void MyCallback(Fl_Widget*w, void* userdata)
      {
          fprintf(stderr, "Button Clicked! Userdata passed is %d\n", (int)userdata);
      }

   public:

       int data;
       Passes_Userdata(int w, int h, const char *name = 0) : Fl_Window(w, h, name)
       {
           data = 54321;
           Fl_Button *but = new Fl_Button(5, 5, 75, 30, "Click Me");
           but->callback(MyCallback, (void*)54321);

           show();
        }
};

int main()
{
    Passes_Userdata passes_userdata(600,400,"FLTK is easy to learn and fun to use!");
    return(Fl::run());      
//Returns value of FLTK command loop,
//this function returns only when all
//windows are closed.
}


Example 1 creates a C++ class derived from a FLTK Fl widget.

The Fl widget we used was Fl_window.

We made everything public to make it easier to understand.

When we coded the constructor we followed the FLTK parameter order of width, height, and label name.

We declared the window button inside of the class constructor.

We made the callback for the button a private member of the class.

Defining the class will automatically show the window.

III. INSTALLING OPENGL


There are lots of free download websites you can use; this is one of the many for OpenGL95:

http://download-opengl-graphics.com/


Download and use WinZip or a similar package to extract the OpenGL95.zip file to your C:\ drive.

IV. USING OPENGL WITH FLTK IN MICROSOFT VISUAL STUDIO


Use the following steps to use OpenGL with FLTK in Microsoft Visual Studio:

1. Open Visual Studio


Use the same Win32 console application empty project you have been using for all of your non-OpenGL FLTK applications.


2. From the Visual Studio main top menu choose Project and from the drop-down menu choose Properties.

To expand a sub-menu click the Linker folder in the left menu of the Properties dialog box. In the sub-menu click Input. On the right, in the additional dependencies text field you should see the following entries we added for FLTK:

fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib


At the end of this list add the following four libraries:

opengl32.lib glu32.lib fltkgld.lib glaux.lib


In the “Ignore Specific Library” text field you should already have the following text if you do not have it add it now:

libcd.lib


In the left menu of the Properties window click C\C++ to expand a sub-menu. Click the “Code Generation” sub-menu item. On the right, if it has not already been changed, change the “Runtime Library” drop-down to:

Multi-threaded Debug DLL (\MDd)

Click OK to close the Properties window.

V. EXAMPLE 2 - OPENGL TEXT ON A ROTATING 3D OBJECT.


Please copy and paste Example 2 into your IDE. You have to use the same Project file we just setup. It will not work in other Project files until you set them up the same way we did the one above. Then, build and debug Example 2 to test to see if you can now code in OpenGL using FLTK.

//***********************************
//Example 2
//OPENGL TEXT ON A ROTATING
//3D OBJECT
//***********************************
#include <FL/Fl.H>
#include <FL/Fl_Gl_window.H>
#include <FL/gl.h>
#include <GL/glu.h>
#include <string.h>
#include <stdio.h>
//Tetrahedron points.
#define TOP 0,  1,  0
#define RIGHT  1, -1,  1
#define LEFT  -1, -1,  1
#define BACK   0, -1, -1
class MyGlWindow : public Fl_Gl_Window {
    float rotangle;
    void draw() {
//Init viewport.
        if (!valid()) {
            valid(1);
// Initialize GL.
            glClearColor(0.0, 0.0, 0.0, 0.0);
            glClearDepth(1.0);
            glDepthFunc(GL_LESS);
            glEnable(GL_DEPTH_TEST);
            glShadeModel(GL_FLAT);
        }
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//Position camera/viewport init.
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glViewport(0,0,w(),h());
        gluPerspective(45.0, (float)w()/(float)h(), 1.0, 10.0);
        glTranslatef(0.0, 0.0, -5.0);
//Position object.
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef(rotangle, 1, 0, 1);
        glRotatef(rotangle, 0, 1, 0);
        glRotatef(rotangle, 1, 1, 1);
//Draw tetrahedron.
        glColor3f(1.0, 0.0, 0.0); glBegin(GL_POLYGON); glVertex3f(TOP);   glVertex3f(RIGHT);  glVertex3f(LEFT);  glEnd();
        glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(TOP);   glVertex3f(BACK);   glVertex3f(RIGHT); glEnd();
        glColor3f(0.0, 0.0, 1.0); glBegin(GL_POLYGON); glVertex3f(TOP);   glVertex3f(LEFT);   glVertex3f(BACK);  glEnd();
        glColor3f(0.5, 0.5, 0.5); glBegin(GL_POLYGON); glVertex3f(RIGHT); glVertex3f(BACK);   glVertex3f(LEFT);  glEnd();
//Print tetrahedron's points on object.
//Disable depth buffer while drawing text,
//so text draws /over/ object.
        glDisable(GL_DEPTH_TEST);
        {
            const char *p;
            gl_font(1, 12);
            glColor3f(1.0, 1.0, 1.0);
            glRasterPos3f(TOP);   p = "+ top";   gl_draw(p, strlen(p));
            glRasterPos3f(LEFT);  p = "+ left";  gl_draw(p, strlen(p));
            glRasterPos3f(RIGHT); p = "+ right"; gl_draw(p, strlen(p));
            glRasterPos3f(BACK);  p = "+ back";  gl_draw(p, strlen(p));
        }
        glEnable(GL_DEPTH_TEST);
//Print rotangle value at fixed position
//at lower left.
        char s[40];
        sprintf(s, "ROT=%.2f", rotangle);
        glLoadIdentity(); glRasterPos2f(-3,-2); gl_draw(s, strlen(s));
    }
    static void Timer_CB(void *userdata) {
        MyGlWindow *o = (MyGlWindow*)userdata;
        o->rotangle += 1.0;
        o->redraw();
        Fl::repeat_timeout(1.0/24.0, Timer_CB, userdata);      //24fps
    }
public:
//CONSTRUCTOR
    MyGlWindow(int X,int Y,int W,int H,const char*L=0) : Fl_Gl_Window(X,Y,W,H,L) {
        rotangle = 0;
        Fl::add_timeout(3.0, Timer_CB, (void*)this);       //Wait 3 secs before animation begins.
    }
};
//MAIN
int main() {
     Fl_Window win(500, 300);
     MyGlWindow mygl(10, 10, win.w()-20, win.h()-20);
     win.show();
     return(Fl::run());
}

YOU HAVE LEARNED HOW TO:
1. CODE A C++ CLASS DERIVED FROM A FLTK WIDGET.
2. INSTALL AND USE OPENGL WITH FLTK.

Elcric Otto Circle




-->

-->

-->




How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"