Hello folks!
I am having problems in redrawing the screen where my opengl program is
running. I have a Fl_Window that contains a menu bar and inside this window
I created a Fl_Gl_Window to display my drawing.
It is working properly but I dont know how to redraw the screen. The menu I
created should contain the options to translate, scale, rotate the drawing
but after the draw is done I cannot call the function redraw() inside the
class that inherits from the Fl_Gl_Window class.
This is my code for the Fl_Gl_Window subclass:
T.h
#ifndef T_H
#define T_H
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
class MyGlWindow : public Fl_Gl_Window {
int trans;
void draw();
void drawTriangle();
int handle(int);
void resize(int ,int ,int ,int);
public:
MyGlWindow(int , int , int , int , const char* );
void translate(float, float, float);
};
#endif
So, once the user chooses to translate the drawing, the variable trans
should be set to zero (0) which means that it should call the draw() method
again or redraw() and so the translation will be done because the trans
variables will do so in the if condition..,
What I wanna do is in the method translate call the redraw() method. But it
Fails!!
See the implementation file below...
#include "T.h"
#include <iostream>
MyGlWindow::MyGlWindow(int X, int Y, int W, int H, const char *L)
: Fl_Gl_Window(X, Y, W, H, L) {trans = 1;}
void MyGlWindow::draw(){
if(!valid()){
valid(1);
glLoadIdentity();
glViewport(0,0,w(),h());
glOrtho(-w(),w(),-h(),h(), -1, 1);
}
std::cout<<"drawing ..."<<std::endl;
if(!trans){
std::cout<<"translating..."<<std::endl;
glTranslatef(100.0, 0.0, 0.0);
}
drawTriangle();
glFlush();
}
int MyGlWindow::handle(int i){}
void MyGlWindow::drawTriangle(){
glMatrixMode(GL_MODELVIEW);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(-60.0, -60.0);
glVertex2f(30.0, 10.0);
glVertex2f(50.0, -50.0);
glEnd();
}
void MyGlWindow::resize(int X,int Y,int W,int H){
Fl_Gl_Window::resize(X,Y,W,H);
glLoadIdentity();
glViewport(0,0,W,H);
glOrtho(-W,W,-H,H,-1,1);
redraw();
}
void MyGlWindow::translate(float tx, float ty, float tz){
trans = 0; //Doesnt work as if I couldnt access this private
member...
redraw(); // Doesnt work! Why?
}
Sorry for this long email.. I'll be glad if someone could give me some
insight and I'm sorry if I'm asking a silly question..
--
Att,
Pedro Henrique Linhares.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk