FLTK logo

Re: OpenGL window in Fl_Wizard

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.opengl  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: OpenGL window in Fl_Wizard David Aiken May 19, 2012  
 
I've posted the code at https://rapidshare.com/files/801556596/fltkWizard.zip since there doesn't seem to be a way to attach a .zip . The files are also shown below:

src/main.cpp
==============================================
#include <stdlib.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_GL_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Wizard.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Multiline_Output.H>
#include <FL/gl.H>
#include <FL/Fl_Value_Slider.H>

class MyGlWindow : public Fl_Gl_Window {
    // FIX OPENGL VIEWPORT
    //     Do this on init or when window's size is changed
    void FixViewport(int W,int H) {
        glLoadIdentity();
        glViewport(0,0,W,H);
        glOrtho(-W,W,-H,H,-1,1);
    }
    // DRAW METHOD
    void draw() {
        if (!valid()) { valid(1); FixViewport(w(), h()); }      // first time? init
        // Clear screen to bg color
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);
        // Draw 'X' in fg color
        glColor3f(1, 1, 1);
        glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); glVertex2f(-w(),-h()); glEnd();
        glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), h()); glEnd();
    }
    // HANDLE WINDOW RESIZING
    void resize(int X,int Y,int W,int H) {
        Fl_Gl_Window::resize(X,Y,W,H);
        FixViewport(W,H);
        redraw();
    }

    virtual int handle(int event)
    {
        return Fl_Gl_Window::handle(event);
    }

public:
    // OPENGL WINDOW CONSTRUCTOR
    MyGlWindow(int X,int Y,int W,int H,const char*L=0) : Fl_Gl_Window(X,Y,W,H,L) {
        end();
    }
};

Fl_Wizard *G_wiz = 0;

void back_cb(Fl_Widget*,void*)
{
    G_wiz->prev();
}

void next_cb(Fl_Widget*,void*)
{
    G_wiz->next();
}

void done_cb(Fl_Widget*,void*)
{
    exit(0);
}


class MyAppWindow : public Fl_Window {
    MyGlWindow *mygl;                    // opengl window
public:
    // APP WINDOW CONSTRUCTOR
    MyAppWindow(int W,int H,const char*L=0) : Fl_Window(W,H,L) {
        // **************************************************
        // 1. OpenGL window. Want this to appear only in page 1.
        // Currently it overlaps on top of the Fl_Multiline_Output
        // windows.
        // **************************************************
        mygl = new MyGlWindow(10, 10, W-20, H-80);

        // **************************************************
        // 2. Would like the wizard buttons to stay the same size
        // during resize, shifting to adhere to the bottom and
        // right margins. Only the other windows should resize.
        // **************************************************
        G_wiz = new Fl_Wizard(0,0,W,H);

        // Wizard: page 1
        {
            Fl_Group *g = new Fl_Group(0, H-60, W, 60);
            Fl_Button *next = new Fl_Button(290,H-30,100,25,"Next"); next->callback(next_cb);
            g->end();
        }
        // Wizard: page 2
        {
            Fl_Group *g = new Fl_Group(0, H-60, W, 60);
            Fl_Button *next = new Fl_Button(290,H-30,100,25,"Next"); next->callback(next_cb);
            Fl_Button *back = new Fl_Button(120,H-30,100,25,"Back"); back->callback(back_cb);
            Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,W-20,H-80,"Terms And Conditions");
            out->labelsize(20);
            out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
            out->value("This is the Second page");
            g->end();
        }
        // Wizard: page 3
        {
            Fl_Group *g = new Fl_Group(0, H-60, W, 60);
            Fl_Button *done = new Fl_Button(290,H-30,100,25,"Finish"); done->callback(done_cb);
            Fl_Button *back = new Fl_Button(120,H-30,100,25,"Back"); back->callback(back_cb);
            Fl_Multiline_Output *out = new Fl_Multiline_Output(10,30,W-20,H-80,"Finish");
            out->labelsize(20);
            out->align(FL_ALIGN_TOP|FL_ALIGN_LEFT);
            out->value("This is the Last page");
            g->end();
        }
        G_wiz->end();
        end();
    }
    virtual int handle(int event)
    {
        return Fl_Window::handle(event);
    }
};


// Simple 'wizard' using fltk's new Fl_Wizard widget

Fl_Window *G_win = 0;

int main(int argc, char **argv)
{
    // **************************************************
    // 3. On initial display of MyAppWindow the OpenGL window
    // is blank. It is not refreshed until the user interacts
    // with it. Is there a way to force a refresh? Or maybe
    // the OpenGL window isn't handled properly..
    // **************************************************
    int w = 500, h=300;
    G_win = new MyAppWindow(w,h,"Example Wizard");
    G_win->resizable(G_win);
    G_win->end();
    G_win->show(argc, argv);
    return Fl::run();
}

CMakeLists.txt
==============================================
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT( fltkWizard )
SET ( CMAKE_PROJECT_NAME "fltkWizard" )

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/Modules)

set(FLTK_ROOT_PATH "/usr/local")
find_package(FLTK REQUIRED)

FILE(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.h)

INCLUDE_DIRECTORIES ( ${PUBLIC_INCLUDE_DIRS} ${FLTK_INCLUDE_DIR})

set(CMAKE_EXE_LINKER_FLAGS "-framework OpenGL -framework AGL -framework AppKit -framework Cocoa -framework ApplicationServices")

set(CMAKE_BUILD_TYPE Debug)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g" )

ADD_EXECUTABLE ( ${CMAKE_PROJECT_NAME} ${SOURCE_FILES} )
TARGET_LINK_LIBRARIES( ${CMAKE_PROJECT_NAME} ${LIBRARIES} ${FLTK_LIBRARIES})
INSTALL(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin COMPONENT RUNTIME)

SET_TARGET_PROPERTIES( ${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME} )

Modules/FindFLTK.cmake
==============================================
# - try to find FLTK Debug include files
#  FLTK_INCLUDE_DIR, where to find FLTK/fltk.h, etc.
#  FLTK_LIBRARIES, the libs
#  FLTK_FOUND, If false, do not try to use FLTK.

IF (WIN32)
  FIND_PATH( FLTK_INCLUDE_DIR NAMES fltk/fltksdk.h
    PATHS  ${FLTK_ROOT_PATH}/include )
ELSE (WIN32)

  IF (APPLE)
    # These values for Apple could probably do with improvement.
    FIND_PATH( FLTK_INCLUDE_DIR FL/Fl.H
      ${FLTK_ROOT_PATH}/include
      )
    FIND_LIBRARY( FLTK_FLTK_LIBRARY NAMES fltk
      PATHS
      ${FLTK_ROOT_PATH}/lib/
      )
    FIND_LIBRARY( FLTK_malloc_LIBRARY NAMES fltk_gl
      PATHS
      ${FLTK_ROOT_PATH}/lib/
      )
    FIND_LIBRARY( FLTK_malloc_LIBRARY NAMES fltk_images
      PATHS
      ${FLTK_ROOT_PATH}/lib/
      )
    FIND_LIBRARY( FLTK_malloc_LIBRARY NAMES fltk_forms
      PATHS
      ${FLTK_ROOT_PATH}/lib/
      )
  ELSE (APPLE)
    FIND_PATH( FLTK_INCLUDE_DIR fltk/fltk.h
      ${FLTK_ROOT_PATH}/include
      )
    FIND_LIBRARY( FLTK_FLTK_LIBRARY NAMES fltksdk-2013.1
      PATHS
      ${FLTK_ROOT_PATH}/lib/
      )
    FIND_LIBRARY( FLTK_malloc_LIBRARY NAMES fltkmalloc
      PATHS
      ${FLTK_ROOT_PATH}/lib/
      )
  ENDIF (APPLE)
ENDIF (WIN32)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK
                                  REQUIRED_VARS FLTK_FLTK_LIBRARY FLTK_malloc_LIBRARY FLTK_INCLUDE_DIR)

IF (FLTK_FOUND)
  SET( FLTK_LIBRARIES
    ${FLTK_FLTK_LIBRARY}
    ${FLTK_malloc_LIBRARY}
    )
  SET (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
ELSE(FLTK_FOUND)
  MESSAGE("FLTK NOT FOUND!!!")
ENDIF(FLTK_FOUND)

MARK_AS_ADVANCED(
  FLTK_INCLUDE_DIR
  FLTK_FLTK_LIBRARY
  FLTK_malloc_LIBRARY
  )





> hi all..
>
> I would like to place an OpenGL window into a wizard, but I'm new to fltk so my source has some problems. I'm using 1.3.0 I'm on OSX Lion 10.7.3 64-bit.
>
> 1. the OpenGL window overlaps all of the wizard pages. It should only appear on the first page.
>
> 2. the OpenGL window is blank until the user interacts with it. Perhaps there is a way to force a refresh on startup? I suspect there is a problem which prevents this from occurring.
>
> The project is attached.. it's derived from a merge of the Fl_Wizard and the "OpenGL Example with Widgets" demo at http://seriss.com/people/erco/fltk (a rather handy page).
>
> If anyone has any ideas it would be appreciated.
>
> thanks!
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.