A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

Sistemas de Interfaces com o Usuário (IUP ou GLUT) e Sistemas Gráficos (OpenGL)

Apresentações semelhantes


Apresentação em tema: "Sistemas de Interfaces com o Usuário (IUP ou GLUT) e Sistemas Gráficos (OpenGL)"— Transcrição da apresentação:

1 Sistemas de Interfaces com o Usuário (IUP ou GLUT) e Sistemas Gráficos (OpenGL)

2 MGattass Objetos de comuns interface

3 MGattass Modelo de Programação Usuário Dispositivos Computador Toolkit de Interface (GLUT, SDK,... ) Sistema Gráfico (OpenGL, Direct3D,...) Programa Gráfico- Interativo

4 MGattass Programação Convencional Os comandos são executados segundo uma ordem pré- estabelecida e sequencial. Programação Convencional captura dados inicio processa dados fim

5 MGattass Eventos típicos (WIMP) KeyPress KeyRelease ButtonPress ButtonRelease Motion LeaveNotify EnterNotify WindowExposure (Repaint) Resize Timer Idle Janela A Janela B Janela C

6 MGattass Modelo de Call Backs Examina eventos, chama os módulos de processamento Processa Evento Tipo 1 Processa Evento Tipo 2 Processa Evento Tipo 3 Eventos Motif Visual Basic Glut IUP... Programa de Aplicação

7 Visual Basic

8 MGattass OpenGL/GLUT #include /* inclui a glut que inclui o OpenGL */ /* Variaveis globais */ int width=640,height=480; /* largura e altura do canvas */ int main(int argc, char **argv) { /* Inicializando a GLUT */ glutInit(&argc, argv); /* formato obrigatorio de inicializacao da glut */ glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE); /* coloca a janela em modo RGBA e double_buffer */ glutInitWindowSize(width, height); /* define largura e altura inicial da janela */ glutCreateWindow("FCG: Trabalho T1"); /* cria a janela com os dizeres na barra */ /* Registrando as callbacks */ glutDisplayFunc(display_cb); /* registra a funcao a ser chamada quando a janela e' exibida */ glutReshapeFunc(reshape_cb); /* idem para a funcao de mudanca de tamanho */ glutSpecialFunc(special_cb); /* idem para quando as teclas especiais F1, F2,... forem acionadas */ /* GLUT main loop */ glutMainLoop(); /* o programa entra em modo de receber eventos do usuario */ return 0; }

9 MGattass Exemplo simples da GLUT void displayCall(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); imgDraw(pic); glutSwapBuffers(); } void reshapeCall(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D (0.0, width, 0.0, height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); window.width = width; window.height = height; }

10 OpenGL/IUP – Exemplo Simples void main(void) { IupOpen(); IupGLCanvasOpen(); if ( init() ) IupMainLoop(); IupClose(); }

11 Elementos de interface Canvas 1Canvas 2 HBox Eventos: RESIZE, REPAINT, BUTTON

12 int init(void) { Ihandle *canvas1, *canvas2, *dialog; char str[80]; char* filename = get_file_name( ); if (filename==NULL) return 0; /* le a imagem de fundo */ image1 = imgLoad(filename); image2 = imgGrey(image1); /* prepara um string com dim. da imagem, por exemplo "320x200" */ sprintf(str,"%dx%d",imgGetWidth(image1),imgGetHeight(image1)); /* cria dois canvas */ canvas1 = IupGLCanvas("repaint_cb1"); IupSetAttribute(canvas1,IUP_RASTERSIZE,str); IupSetAttribute(canvas1, "RESIZE_CB", "resize_cb"); IupSetAttribute(canvas1, "BUTTON_CB", "button_cb1"); /* associa o evento de repaint a funcao repaint_cb */ IupSetFunction("repaint_cb1", (Icallback) repaint_cb1); IupSetFunction("resize_cb", (Icallback) resize_cb); IupSetFunction("button_cb1", (Icallback) button_cb1); /* cria uma dialogo janela que contém o canvas */ dialog = IupDialog( IupHbox(canvas1,canvas2,NULL)); /* constroi e coloca o dialogo principal na tela */ IupShow(dialog); return 1; } Incialização

13 static char * get_file_name( void ) { Ihandle* getfile = IupFileDlg(); char* filename = NULL; IupSetAttribute(getfile, IUP_TITLE, "Abertura de arquivo"); IupSetAttribute(getfile, IUP_DIALOGTYPE, IUP_OPEN); IupSetAttribute(getfile, IUP_FILTER, "*.tga"); IupSetAttribute(getfile, IUP_FILTERINFO, "Arquivo de imagem (*.tga)"); IupPopup(getfile, IUP_CENTER, IUP_CENTER); filename = IupGetAttribute(getfile, IUP_VALUE); return filename; } Diálogo de seleção de arquivos

14 Canvas 1 e 2 Evento: RESIZE int resize_cb(Ihandle *self, int w, int h) { IupGLMakeCurrent(self); glViewport(0,0,w,h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D (0., w, 0., h); glRasterPos2d(0.0,0.0); return IUP_DEFAULT; } w h xvxv yvyv xexe yeye zeze w h

15 Canvas 1 (uma maneira) Evento: REPAINT nt repaint_cb1(Ihandle *self) { int w = imgGetWidth(image1); int h = imgGetHeight(image1); unsigned char *rgbData = imgGetRGBData(image1); IupGLMakeCurrent(self); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glDrawPixels (w, h, GL_RGB,GL_UNSIGNED_BYTE, (GLubyte *) rgbData); glFlush(); return IUP_DEFAULT; }

16 int repaint_cb2(Ihandle *self) { int w = imgGetWidth(image2); int h = imgGetHeight(image2); unsigned char *rgbData = imgGetRGBData(image2); int x,y; IupGLMakeCurrent(self); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); for (y=0;y<h;y++) { for (x=0; x<w; x++) { unsigned char rgb[3]; imgGetPixel3ubv(image2, x, y, rgb ); glColor3ubv(rgb); glVertex2i(x,y); } glEnd(); glFlush(); return IUP_DEFAULT; } Canvas 2 (outra maneira)

17 Image *imgCreate (int w, int h); void imgDestroy (Image *image); int imgGetWidth(Image * image); int imgGetHeight(Image * image); unsigned char * imgGetRGBData(Image * image); void imgSetPixel3fv(Image *image, int x, int y, float * color); void imgSetPixel3ubv(Image *image, int x, int y, unsigned char *color); void imgGetPixel3fv(Image *image, int x, int y, float *color); void imgGetPixel3ubv(Image *image, int x, int y, unsigned char *color); Image * imgLoad(char *filename); int imgWriteTGA(char *filename, Image * image); Image * imgCopy(Image * image); Image * imgGrey(Image * image); Image * imgResize(Image * img0, int w1, int h1); TAD: Interface do módulo: image.h typedef struct Image_imp Image;

18 unsigned int imgCountColor(Image *img, float tol); Image *imgReduceColors(Image *img, int ncolors); unsigned char* imgNormalizeColors(Image *img); TAD: Interface do módulo: image.h Funções do primeiro trabalho:

19 struct Image_imp { int width; int height; float *buf; }; TAD: Implementação do módulo: image.c Image * imgCreate (int w, int h) { Image * image = (Image*) malloc (sizeof(Image)); assert(image); image->width =(unsigned int) w; image->height =(unsigned int) h; image->buf = (float *) malloc (w * h * 3* sizeof(float)); assert(image->buf); return image; }

20 MGattass Inscrição na lista do curso Mandar e-mail para: mgattass@inf.puc-rio.br Subj: INF1761


Carregar ppt "Sistemas de Interfaces com o Usuário (IUP ou GLUT) e Sistemas Gráficos (OpenGL)"

Apresentações semelhantes


Anúncios Google