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

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

Computação Gráfica Interativa - Gattass

Apresentações semelhantes


Apresentação em tema: "Computação Gráfica Interativa - Gattass"— Transcrição da apresentação:

1 Computação Gráfica Interativa - Gattass
3/25/2017 Sistemas de Interfaces com o Usuário (IUP ou GLUT) e Sistemas Gráficos (OpenGL) Interfaces Gráficas

2 Objetos de comuns interface
Computação Gráfica Interativa - Gattass 3/25/2017 Objetos de comuns interface MGattass Interfaces Gráficas

3 Computação Gráfica Interativa - Gattass
3/25/2017 Modelo de Programação Toolkit de Interface (GLUT, SDK, ... ) Programa Gráfico- Interativo Sistema Gráfico (OpenGL, Direct3D, ...) Dispositivos Computador Usuário MGattass Interfaces Gráficas

4 Programação Convencional
Computação Gráfica Interativa - Gattass 3/25/2017 Programação Convencional inicio Programação Convencional Os comandos são executados segundo uma ordem pré-estabelecida e sequencial. captura dados processa dados fim MGattass Interfaces Gráficas

5 Eventos típicos (WIMP)
Computação Gráfica Interativa - Gattass 3/25/2017 Eventos típicos (WIMP) KeyPress KeyRelease ButtonPress ButtonRelease Motion LeaveNotify EnterNotify WindowExposure (Repaint) Resize Timer Idle Janela A Janela B Janela C MGattass Interfaces Gráficas

6 Computação Gráfica Interativa - Gattass
3/25/2017 Modelo de Call Backs Processa Evento Tipo 1 Eventos Examina eventos, chama os módulos de processamento Processa Evento Tipo 2 Motif Visual Basic Glut IUP ... Processa Evento Tipo 3 Programa de Aplicação MGattass Interfaces Gráficas

7 Computação Gráfica Interativa - Gattass
3/25/2017 Visual Basic Interfaces Gráficas

8 OpenGL/GLUT #include <glut.h> #include “image.h”
/* Variaveis globais */ typedef struct window_impl { int width; int height;} Window; Window window; Image* pic; int main(int argc, char **argv) { pic = imgReadBMP(“teste.bmp”); imgGetDimensions(pic, &window.width, &window.height); /* GLUT - Initialization */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE ); glutInitWindowSize(window.width, window.height); glutCreateWindow("CG-T1"); /* Registrando callbacks */ glutDisplayFunc(displayCall); glutReshapeFunc(reshapeCall); glutMouseFunc(mouseCall); glutMotionFunc(motionCall); glutKeyboardFunc(keyboardCall); glutIdleFunc(idleCall); /* GLUT main loop */ glutMainLoop(); return 0; } MGattass

9 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); window.width = width; window.height = height; } MGattass

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

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

12 Incialização 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 Diálogo de seleção de arquivos
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; }

14 Canvas 1 e 2 Evento: RESIZE w h xv yv xe ye ze w h
int resize_cb(Ihandle *self, int w, int h) { IupGLMakeCurrent(self); glViewport(0,0,w,h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); gluOrtho2D (0., w, 0., h); glRasterPos2d(0.0,0.0); return IUP_DEFAULT; } xe ye ze 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 Canvas 2 (outra maneira)
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;

17 TAD: Interface do módulo: image.h
typedef struct Image_imp Image; 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);

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

19 TAD: Implementação do módulo: image.c
struct Image_imp { int width; int height; float *buf; }; 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 Inscrição na lista do curso
Mandar para: Subj: INF1761 MGattass


Carregar ppt "Computação Gráfica Interativa - Gattass"

Apresentações semelhantes


Anúncios Google