/* carrega uma nova cena */ int load_cb(void) { char* filename = get_file_name(); /* chama o dialogo de abertura de arquivo */ char buffer[30]; if (filename==NULL) return 0; /* Le a cena especificada */ scene = sceLoad( filename ); if( scene == NULL ) return IUP_DEFAULT; camera = sceGetCamera( scene ); eye = camGetEye( camera ); width = camGetScreenWidth( camera ); height = camGetScreenHeight( camera ); yc=0; if (image) imgDestroy(image); image = imgCreate( width, height ); IupSetfAttribute(label, "TITLE", "%3dx%3d", width, height); sprintf(buffer,"%3dx%3d", width, height); IupSetAttribute(canvas,IUP_RASTERSIZE,buffer); IupSetFunction (IUP_IDLE_ACTION, (Icallback) idle_cb); start_time = clock(); IupGLMakeCurrent(canvas); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glEnd(); glFlush(); IupGLSwapBuffers(canvas); /* change the back buffer with the front buffer */ return IUP_DEFAULT; }
/* calcula uma linha da imagem a cada camada de idle */ int idle_cb(void) { int x; /* Faz uma linha de pixels por vez */ if (yc<height) { IupGLMakeCurrent(canvas); glBegin(GL_POINTS); for( x = 0; x < width; ++x ) { Color pixel; Vector ray; ray = camGetRay( camera, x, yc ); pixel = rayTrace( scene, eye, ray, 0 ); imageSetPixel( image, x, yc, pixel ); glColor3f((float)pixel.red,(float)pixel.green,(float)pixel.blue); glVertex2i(x,yc); } glEnd(); glFlush(); IupGLSwapBuffers(canvas); /* change the back buffer with the front buffer */ yc++; } else { IupSetFunction (IUP_IDLE_ACTION, (Icallback) NULL); /* a imagem ja' esta' completa */ finish_time = clock(); duration = (double)(finish_time - start_time)/CLOCKS_PER_SEC; IupSetfAttribute(label, "TITLE", "tempo=%.3lf s", duration); } return IUP_DEFAULT; }
/* function called when the canvas is exposed in the screen. self is the iuphandle of the canvas */ int repaint_cb(Ihandle *self) { int x,y; IupGLMakeCurrent(self); /* all OpenGL primitives will be directed to this canvas */ glClearColor(0.3f, 0.3f, 0.3f, 1.0f); /* dark grey color in the RGBA mode A is the alpha channel (ignore) */ glClear(GL_COLOR_BUFFER_BIT); /* clear the color buffer */ if (gc.image!=NULL) { int h = imgGetHeight(gc.image); int w = imgGetWidth(gc.image); /* assing to each pixel of the canvas the color of the corresponding pixel in the image */ glBegin(GL_POINTS); for (y=0;y<h;y++) { for (x=0;x<w;x++) { float r,g,b; imgGetPixel3f(gc.image,x,y,&r,&g,&b); /* gets the RGB value the pixel (x,y) */ glColor3f(r,g,b); /* define a current color in OpenGL */ glVertex2i(x,y); /* paint the pixel */ } } glEnd(); } IupGLSwapBuffers(self); /* change the back buffer with the front buffer */ return IUP_DEFAULT; /* returns the control to the main loop */ }
static void drawTestGL(Ihandle* ih) { Ihandle* glcanvas = IupGetAttributeHandle(ih, "PREVIEWGLCANVAS"); if (glcanvas) { int w = IupGetInt(ih, "PREVIEWWIDTH"); int h = IupGetInt(ih, "PREVIEWHEIGHT"); IupGLMakeCurrent(glcanvas); glViewport(0,0,w,h); glClearColor(1.0, 0.0, 1.0, 1.f); /* pink */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0,0.0,0.0); /* red */ glBegin(GL_QUADS); glVertex2f(0.9f,0.9f); glVertex2f(0.9f,-0.9f); glVertex2f(-0.9f,-0.9f); glVertex2f(-0.9f,0.9f); glEnd(); IupGLSwapBuffers(glcanvas); } else drawTest(ih); }
int ERN2DViewMethod::Idle_Action_CB (Ihandle* cnv_renderer) { IupGLMakeCurrent (cnv_renderer); if (m_redisplay || m_auto_redisplay) { if (m_outdated) { if (!m_renderer.m_glsl_preintegrated_texture || Viewer::Instance ()->m_volumename.compare (m_volumename) != 0) { m_volumename = Viewer::Instance ()->m_volumename; m_renderer.ReloadVolume (Viewer::Instance ()->m_volume, Viewer::Instance ()->m_transfer_function); } UpdateIupUserInterface (); m_outdated = false; } if (m_renderer.m_glsl_preintegrated_texture) { m_renderer.Render (Viewer::Instance ()->m_CurrentWidth, Viewer::Instance ()->m_CurrentHeight); IupGLSwapBuffers (cnv_renderer); } m_redisplay = false; } return IUP_DEFAULT; }
static int motion_cb(Ihandle *ih,int x,int y,char* status) { (void)status; if (move) { double dif_x, dif_y; double dx, dy, dz; double x1, y1, z1; double x2, y2, z2; double angle, norma; int height = IupGetInt2(ih, "RASTERSIZE"); double mv[16]; double pm[16]; int vp[4]; IupGLMakeCurrent(ih); glGetDoublev(GL_MODELVIEW_MATRIX, mv); glGetDoublev(GL_PROJECTION_MATRIX, pm); glGetIntegerv(GL_VIEWPORT, vp); dif_x = x - pos_x; dif_y = y - pos_y; if (dif_x == 0 && dif_y == 0) return IUP_DEFAULT; pos_x = x; pos_y = y; angle = sqrt(dif_x*dif_x + dif_y*dif_y); gluUnProject(pos_x, INVERT_Y(pos_y), 0.0, mv, pm, vp, &x1, &y1, &z1); gluUnProject((double)(dif_y + pos_x), (double)(dif_x + INVERT_Y(pos_y)), 0.0, mv, pm, vp, &x2, &y2, &z2); dx = x2-x1; dy = y2-y1; dz = z2-z1; norma = sqrt(dx*dx + dy*dy + dz*dz); dx /= norma; dy /= norma; dz /= norma; glMatrixMode(GL_MODELVIEW); glTranslated(0.5, 0.5, 0.5); glRotated (angle, dx, dy, dz); glTranslated(-0.5, -0.5, -0.5); glGetDoublev(GL_MODELVIEW_MATRIX, model_view_matrix); use_model_matrix = 1; draw_cube(); IupGLSwapBuffers(ih); } return IUP_DEFAULT; }
static int action(Ihandle *ih) { IupGLMakeCurrent(ih); init(); draw_cube(); IupGLSwapBuffers(ih); return IUP_DEFAULT; }
/* - Callback de repaint do canvas */ int repaint_cb(Ihandle *self) { int w,h; int x,y; Color rgb; if (yc==0){ /* e' a primeira vez: limpa o canvas */ IupGLMakeCurrent(self); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); IupGLSwapBuffers(self); /* change the back buffer with the front buffer */ glFlush(); } if (yc!=height) { /* esta callback so'desenha depois que o algoritmo termina a imagem */ return IUP_DEFAULT; } w = imgGetWidth(image); h = imgGetHeight(image); 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++) { rgb = imageGetPixel(image, x, y); glColor3f((float)rgb.red,(float)rgb.green,(float)rgb.blue); glVertex2i(x,y); } } glEnd(); IupGLSwapBuffers(self); /* change the back buffer with the front buffer */ glFlush(); return IUP_DEFAULT; /* retorna o controle para o gerenciador de eventos */ }
int app_repaint_cb(Ihandle* self) { unsigned char* gl_data = (unsigned char*)IupGetAttribute(self, "APP_GL_DATA"); int width = IupGetInt(self, "APP_GL_WIDTH"); int height = IupGetInt(self, "APP_GL_HEIGHT"); IupGLMakeCurrent(self); /* activates this GL Canvas as the current drawing area. */ glClear(GL_COLOR_BUFFER_BIT); /* clears the back buffer */ if (gl_data) { /* Draws the captured image at (0,0) */ glRasterPos2f(0.f, 0.f); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, gl_data); } IupGLSwapBuffers(self); /* swap data from back buffer to front buffer */ return IUP_DEFAULT; }
int canvas_action_cb(Ihandle* canvas) { int x, y, canvas_width, canvas_height; void* gldata; unsigned int ri, gi, bi; imImage* image; Ihandle* config = (Ihandle*)IupGetAttribute(canvas, "CONFIG"); const char* background = IupConfigGetVariableStrDef(config, "MainWindow", "Background", "255 255 255"); IupGetIntInt(canvas, "DRAWSIZE", &canvas_width, &canvas_height); IupGLMakeCurrent(canvas); /* OpenGL configuration */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* image data alignment is 1 */ glViewport(0, 0, canvas_width, canvas_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, canvas_width, 0, canvas_height, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* draw the background */ sscanf(background, "%u %u %u", &ri, &gi, &bi); glClearColor(ri / 255.f, gi / 255.f, bi / 255.f, 1); glClear(GL_COLOR_BUFFER_BIT); /* draw the image at the center of the canvas */ image = (imImage*)IupGetAttribute(canvas, "IMAGE"); if (image) { x = (canvas_width - image->width) / 2; y = (canvas_height - image->height) / 2; gldata = (void*)imImageGetAttribute(image, "GLDATA", NULL, NULL); glRasterPos2i(x, y); /* this will not work for negative values, OpenGL limitation */ glDrawPixels(image->width, image->height, GL_RGB, GL_UNSIGNED_BYTE, gldata); /* no zoom support, must use texture */ } IupGLSwapBuffers(canvas); return IUP_DEFAULT; }
/* function called when the canvas is exposed in the screen */ static int repaint_cb(Ihandle *self) { IupGLMakeCurrent(self); glClearColor(0.3f, 0.3f, 0.3f, 1.0f); /* White */ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); glPushMatrix(); /* saves current model view in a stack */ glTranslatef( 0.0f, 0.0f , 0.0f ); glScalef( 1.0f, 1.0f, 1.0f ); glRotatef(t,0,0,1); colorCube(); glPopMatrix(); IupGLSwapBuffers(self); /* change the back buffer with the front buffer */ return IUP_DEFAULT; /* returns the control to the main loop */ }
/* calcula uma linha da imagem a cada camada de idle */ int idle_cb(void) { int x; double ray[VECTOR]; float pixel[COLOR]; /* Faz uma linha de pixels por vez */ if (yc < height) { IupGLMakeCurrent(canvas); glBegin(GL_POINTS); { for (x = 0; x < width; ++x) { camGetRay(camera, x, yc, ray); rayTrace(scene, eye, ray, 0, pixel); imageSetPixel(image, x, yc, pixel); glColor3f((float) pixel[RED], (float) pixel[GREEN], (float) pixel[BLUE]); glVertex2i(x, yc); } } glEnd(); glFlush(); IupGLSwapBuffers(canvas); yc++; } else { IupSetFunction (IUP_IDLE_ACTION, (Icallback) NULL); /* a imagem ja' esta' completa */ finish_time = clock(); duration = (double)(finish_time - start_time)/CLOCKS_PER_SEC; IupSetfAttribute(label, "TITLE", "tempo=%.3lf s", duration); glFlush(); } return IUP_DEFAULT; }
static int action(Ihandle *ih) { static int first = 1; IupGLMakeCurrent(ih); if (first) { init(); first = 0; } glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); draw_cube(); glFlush(); IupGLSwapBuffers(ih); return IUP_DEFAULT; }
static int motion_cb(Ihandle *ih,int x,int y,char* status) { (void)status; if (move) { double dif_x, dif_y; double dx, dy, dz; double x1, y1, z1; double x2, y2, z2; double angle, norma; int height = IupGetInt2(ih, "RASTERSIZE"); IupGLMakeCurrent(ih); dif_x = x - pos_x; dif_y = y - pos_y; pos_x = x; pos_y = y; angle = sqrt(dif_x*dif_x + dif_y*dif_y); unproject (pos_x, INVERT_Y(pos_y), &x1, &y1, &z1); unproject ((double)(dif_y+pos_x), (double)(dif_x+INVERT_Y(pos_y)), &x2, &y2, &z2); dx = x2-x1; dy = y2-y1; dz = z2-z1; norma = sqrt(dx*dx + dy*dy + dz*dz); dx /= norma; dy /= norma; dz /= norma; glTranslated(0.5, 0.5, 0.5); glRotated (angle, dx, dy, dz); glTranslated(-0.5, -0.5, -0.5); draw_cube(); glFlush(); IupGLSwapBuffers(ih); } return IUP_DEFAULT; }
void TransferFunctionsViewer::Redraw () { IupGLMakeCurrent (m_iup_canvas); vr::TransferFunction *tf = Viewer::Instance ()->m_transfer_function; if (tf) { for (int i = 0; i < 256; i++) { lqc::Vector4d c = tf->Get (i); for (int j = 0; j < 50; j++) { if (id < 2) { m_pixels[i * 4 + j * 258 * 4] = c.x; m_pixels[i * 4 + j * 258 * 4 + 1] = c.y; m_pixels[i * 4 + j * 258 * 4 + 2] = c.z; m_pixels[i * 4 + j * 258 * 4 + 3] = 1.0; } else { m_pixels[i * 4 + j * 258 * 4] = c.w; m_pixels[i * 4 + j * 258 * 4 + 1] = c.w; m_pixels[i * 4 + j * 258 * 4 + 2] = c.w; m_pixels[i * 4 + j * 258 * 4 + 3] = 1.0; } } } } glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDrawPixels (258, 50, GL_RGBA, GL_FLOAT, m_pixels); id = (id + 1) % 4; IupGLSwapBuffers (m_iup_canvas); }
int redraw(Ihandle *self, float x, float y) { int w, h; char *size = IupGetAttribute(self, "RASTERSIZE"); sscanf(size, "%dx%d", &w, &h); IupGLMakeCurrent(self); glViewport(0, 0, w, h); glClearColor(1.0, 1.0, 1.0, 1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0,0.0,0.0); glBegin(GL_QUADS); glVertex2f( 0.9f, 0.9f); glVertex2f( 0.9f, -0.9f); glVertex2f(-0.9f, -0.9f); glVertex2f(-0.9f, 0.9f); glEnd(); IupGLSwapBuffers(self); return IUP_DEFAULT; }
void SimpleFlush(void) { IupGLSwapBuffers(IupGetHandle("SimpleCanvas")); }
static int GLSwapBuffers(lua_State *L) { IupGLSwapBuffers(iuplua_checkihandle(L,1)); return 0; }