void Camera2D::_set_current(bool p_current) { if (p_current) make_current(); current=p_current; }
void rxvt_term::destroy_cb (ev::idle &w, int revents) { make_current (); delete this; }
void Listener::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { bool first_listener = get_viewport()->_listener_add(this); if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) make_current(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { _request_listener_update(); } break; case NOTIFICATION_EXIT_WORLD: { if (!get_tree()->is_node_being_edited(this)) { if (is_current()) { clear_current(); current = true; //keep it true } else { current = false; } } get_viewport()->_listener_remove(this); } break; } }
extern Bool glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx) { Bool result; result=GH_glXMakeCurrentReadSGI(dpy, draw, read, ctx); make_current(ctx, dpy, draw, read); return result; }
extern Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx) { Bool result; result=GH_glXMakeCurrent(dpy, drawable, ctx); make_current(ctx, dpy, drawable, drawable); return result; }
void rxvt_term::update_background_cb (ev::timer &w, int revents) { make_current (); update_background_ev.stop (); bgPixmap.render (); refresh_check (); }
World::World( const char* classname, int& argc, char** argv, const OptionDesc* opts, const PropertyData* initprops ) { session_ = new Session(classname, argc, argv, opts, initprops); display_ = session_->default_display(); make_current(); Sensor::init(); }
// ---------------------------------------------------------------------------- // resize() - update the size of our window and eaagles window. // ---------------------------------------------------------------------------- void GLWindow::resize(int x, int y, int w, int h) { Fl_Gl_Window::resize(x, y, w, h); if (display != 0) { // make our display current make_current(); display->reshapeIt(w, h); } }
void Camera::_camera_make_next_current(Node *p_exclude) { if (this==p_exclude) return; if (!is_inside_tree()) return; if (get_viewport()->get_camera()!=NULL) return; make_current(); }
void Engine::drawPoints( const Skeleton& skelet, const Zoom& zoom, Image& image, const int imax ) { skelet.setXY( _x, _y, _color ); iterBuildPoints( skelet, zoom, image, imax ); make_current(); image.mem_draw(); // we limit the frequence of checking because // it slows the program under Windows if ( Fl::ready() ) { Fl::check(); } }
void WaylandEGLContext::resize () { int scale; gdk_window_get_geometry (gdk_window, &x, &y, &width, &height); scale = gdk_window_get_scale_factor (gdk_window); wl_egl_window_resize (egl_window, width * scale, height * scale, 0, 0); wl_subsurface_set_position (subsurface, x, y); make_current (); }
bool Listener::_set(const StringName &p_name, const Variant &p_value) { if (p_name == "current") { if (p_value.operator bool()) { make_current(); } else { clear_current(); } } else return false; return true; }
bool CanvasX11::do_make_current() { if (!make_current()) return false; if (offscreen_) { if (!ensure_fbo()) return false; glBindFramebuffer(GL_FRAMEBUFFER, fbo_); } return true; }
void Camera::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_WORLD: { bool first_camera = get_viewport()->_camera_add(this); if (!get_tree()->is_node_being_edited(this) && (current || first_camera)) make_current(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { _request_camera_update(); } break; case NOTIFICATION_EXIT_WORLD: { if (!get_tree()->is_node_being_edited(this)) { if (is_current()) { clear_current(); current=true; //keep it true } else { current=false; } } get_viewport()->_camera_remove(this); } break; case NOTIFICATION_BECAME_CURRENT: { if (get_world().is_valid()) { get_world()->_register_camera(this); } } break; case NOTIFICATION_LOST_CURRENT: { if (get_world().is_valid()) { get_world()->_remove_camera(this); } } break; } }
me::AdorningDisplayBufferCompositor::AdorningDisplayBufferCompositor( mg::DisplayBuffer& display_buffer, std::tuple<float, float, float> const& background_rgb) : db{display_buffer}, render_target{me::as_render_target(display_buffer)}, vert_shader_src{ "attribute vec4 vPosition;" "uniform vec2 pos;" "uniform vec2 scale;" "attribute vec2 uvCoord;" "varying vec2 texcoord;" "void main() {" " gl_Position = vec4(vPosition.xy * scale + pos, 0.0, 1.0);" " texcoord = uvCoord.xy;" "}" }, frag_shader_src{ "precision mediump float;" "varying vec2 texcoord;" "uniform sampler2D tex;" "uniform float alpha;" "void main() {" " gl_FragColor = texture2D(tex, texcoord) * alpha;" "}" }, current(make_current(render_target)), vertex(&vert_shader_src, GL_VERTEX_SHADER), fragment(&frag_shader_src, GL_FRAGMENT_SHADER), program(vertex, fragment) { glUseProgram(program.program); vPositionAttr = glGetAttribLocation(program.program, "vPosition"); glVertexAttribPointer(vPositionAttr, 4, GL_FLOAT, GL_FALSE, 0, vertex_data); uvCoord = glGetAttribLocation(program.program, "uvCoord"); glVertexAttribPointer(uvCoord, 2, GL_FLOAT, GL_FALSE, 0, uv_data); posUniform = glGetUniformLocation(program.program, "pos"); glClearColor(std::get<0>(background_rgb), std::get<1>(background_rgb), std::get<2>(background_rgb), 1.0); scaleUniform = glGetUniformLocation(program.program, "scale"); alphaUniform = glGetUniformLocation(program.program, "alpha"); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); }
void OpenGLWindowProvider::get_opengl_version(int &version_major, int &version_minor) { make_current(); #undef glGetString std::string version = (char*)::glGetString(GL_VERSION); version_major = 0; version_minor = 0; std::vector<std::string> split_version = StringHelp::split_text(version, "."); if (split_version.size() > 0) version_major = StringHelp::text_to_int(split_version[0]); if (split_version.size() > 1) version_minor = StringHelp::text_to_int(split_version[1]); }
bool Camera::_set(const StringName& p_name, const Variant& p_value) { bool changed_all=false; if (p_name=="projection") { int proj = p_value; if (proj==PROJECTION_PERSPECTIVE) mode=PROJECTION_PERSPECTIVE; if (proj==PROJECTION_ORTHOGONAL) mode=PROJECTION_ORTHOGONAL; changed_all=true; } else if (p_name=="fov" || p_name=="fovy" || p_name=="fovx") fov=p_value; else if (p_name=="size" || p_name=="sizex" || p_name=="sizey") size=p_value; else if (p_name=="near") near=p_value; else if (p_name=="far") far=p_value; else if (p_name=="keep_aspect") set_keep_aspect_mode(KeepAspect(int(p_value))); else if (p_name=="vaspect") set_keep_aspect_mode(p_value?KEEP_WIDTH:KEEP_HEIGHT); else if (p_name=="h_offset") h_offset=p_value; else if (p_name=="v_offset") v_offset=p_value; else if (p_name=="current") { if (p_value.operator bool()) { make_current(); } else { clear_current(); } } else if (p_name=="visible_layers") { set_visible_layers(p_value); } else if (p_name=="environment") { set_environment(p_value); } else return false; _update_camera_mode(); if (changed_all) _change_notify(); return true; }
void imWindow::drawit() { if (!shown()) return; struct image_cb_data cbd; make_current(); if (pixelType == MONOCHROME) { if (gamma > 0.0 && gamma < 1.0) { cbd.pdata = pixelData; cbd.ndisp = ndisp; cbd.linesize = linesize; cbd.skip = skipw; cbd.gtab = gamtab; fl_draw_image_mono(gamma_image_cb_fn, (void *)&cbd, xoff, yoff, width, height, 1); } else fl_draw_image_mono(pixelData, xoff, yoff, width, height, skipw, linesize); } else if (pixelType == RGB24) { if (gamma > 0.0 && gamma < 1.0) { cbd.pdata = pixelData; cbd.ndisp = ndisp; cbd.linesize = linesize*3; cbd.skip = skipw*3; cbd.gtab = gamtab; fl_draw_image(gamma_color_image_cb_fn, (void *)&cbd, xoff, yoff, width, height, 3); } else fl_draw_image(pixelData, xoff, yoff, width, height, skipw*3, linesize*3); } else if (pixelType == DISPARITY) { cbd.pdata = pixelData; cbd.ndisp = ndisp; cbd.linesize = linesize; cbd.skip = skipw; fl_draw_image(disp_image_cb_fn, (void *)&cbd, xoff, yoff, width, height, 3); } }
// this tries to see which control point is under the mouse // (for when the mouse is clicked) // it uses OpenGL picking - which is always a trick // TODO: if you want to pick things other than control points, or you // changed how control points are drawn, you might need to change this void TrainView::doPick() { make_current(); // since we'll need to do some GL stuff int mx = Fl::event_x(); // where is the mouse? int my = Fl::event_y(); // get the viewport - most reliable way to turn mouse coords into GL coords int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); // set up the pick matrix on the stack - remember, FlTk is // upside down! glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPickMatrix((double)mx, (double)(viewport[3]-my), 5, 5, viewport); // now set up the projection setProjection(); // now draw the objects - but really only see what we hit GLuint buf[100]; glSelectBuffer(100,buf); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); // draw the cubes, loading the names as we go for(size_t i=0; i<world->points.size(); ++i) { glLoadName((GLuint) (i+1)); world->points[i].draw(); } // go back to drawing mode, and see how picking did int hits = glRenderMode(GL_RENDER); if (hits) { // warning; this just grabs the first object hit - if there // are multiple objects, you really want to pick the closest // one - see the OpenGL manual // remember: we load names that are one more than the index selectedCube = buf[3]-1; } else // nothing hit, nothing selected selectedCube = -1; printf("Selected Cube %d\n",selectedCube); //printf("Position: (%f,%f,%f)\n", world->points[selectedCube].pos.x, world->points[selectedCube].pos.y, world->points[selectedCube].pos.z); }
int Engine::drawPoints( const Skeleton& skelet, const Zoom& zoom, Image& image, unsigned long& clock0 ) { skelet.setXY( _x, _y, _color ); int counter = 0; do { iterBuildPoints( skelet, zoom, image, minimalBuiltPoints ); counter += minimalBuiltPoints; } while ( clock() - clock0 < intervalFrame * timecv ); clock0 = clock(); make_current(); image.mem_draw(); // we limit the frequence of checking because // it slows the program under Windows if ( Fl::ready() ) { Fl::check(); } return counter; }
bool make_current(draw_state const& state, draw_state const& previous_state) { TMPROF_BLOCK(); if (!previous_state.loaded_successfully()) return make_current(state); if (!state.loaded_successfully()) return false; if (state == previous_state) return true; if (state.cull_face_mode() != previous_state.cull_face_mode()) { if (state.cull_face_mode() == GL_NONE) glapi().glDisable(GL_CULL_FACE); else { if (previous_state.cull_face_mode() == GL_NONE) glapi().glEnable(GL_CULL_FACE); glapi().glCullFace(state.cull_face_mode()); } } if (state.use_alpha_blending() != previous_state.use_alpha_blending()) if (state.use_alpha_blending()) { glapi().glEnable(GL_BLEND); glapi().glBlendFunc(state.alpha_blending_src_function(),state.alpha_blending_dst_function()); } else glapi().glDisable(GL_BLEND); else if (state.use_alpha_blending() && (state.alpha_blending_src_function() != previous_state.alpha_blending_src_function() || state.alpha_blending_dst_function() != previous_state.alpha_blending_dst_function()) ) glapi().glBlendFunc(state.alpha_blending_src_function(),state.alpha_blending_dst_function()); INVARIANT(glapi().glGetError() == 0U); return true; }
void OriginalView::markTracker() { int drawWidth, drawHeight, startrow;; Point cur = m_pDoc->m_curPoint, last = m_pDoc->m_lastPoint; GLvoid* bitstart; const int size = 10; make_current(); drawWidth = min( m_nWindowWidth, m_pDoc->m_nWidth ); drawHeight = min( m_nWindowHeight, m_pDoc->m_nHeight ); //restric drawing in the image area glEnable(GL_SCISSOR_TEST); glScissor(0, m_nWindowHeight - drawHeight, drawWidth, drawHeight); //draw last point pixels back if(last.x <= drawWidth && last.y >= m_nWindowHeight - drawHeight) { last.x -= size >> 1; last.y -= size >> 1; if(last.x < 0) { last.x = 0; } if(last.x + size > drawWidth) { last.x = drawWidth - size; } if(last.y < m_nWindowHeight - drawHeight) { last.y = m_nWindowHeight - drawHeight; } if(last.y + size > m_nWindowHeight) { last.y = m_nWindowHeight - size; } //Restore content startrow = m_pDoc->m_nHeight - m_nWindowHeight + last.y; if ( startrow < 0 ) startrow = 0; bitstart = m_pDoc->m_ucBitmap + 3 * ((m_pDoc->m_nWidth * startrow) + last.x); glRasterPos2i( last.x, last.y ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glPixelStorei( GL_UNPACK_ROW_LENGTH, m_pDoc->m_nWidth ); glDrawBuffer( GL_FRONT ); glDrawPixels( size, size, GL_RGB, GL_UNSIGNED_BYTE, bitstart ); }
bool Camera::_set(const StringName& p_name, const Variant& p_value) { bool changed_all=false; if (p_name=="projection") { int proj = p_value; if (proj==PROJECTION_PERSPECTIVE) mode=PROJECTION_PERSPECTIVE; if (proj==PROJECTION_ORTHOGONAL) mode=PROJECTION_ORTHOGONAL; changed_all=true; } else if (p_name=="fov") fov=p_value; else if (p_name=="size") size=p_value; else if (p_name=="near") near=p_value; else if (p_name=="far") far=p_value; else if (p_name=="vaspect") set_use_vertical_aspect(p_value); else if (p_name=="current") { if (p_value.operator bool()) { make_current(); } else { clear_current(); } } else if (p_name=="visible_layers") { set_visible_layers(p_value); } else if (p_name=="environment") { set_environment(p_value); } else return false; _update_camera_mode(); if (changed_all) _change_notify(); return true; }
void ModelerView::saveBMP(const char* szFileName) { int xx = x(); int yy = y(); int ww = w(); int hh = h(); make_current(); unsigned char *imageBuffer = new unsigned char[3 * ww * hh]; glReadBuffer(GL_BACK); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ROW_LENGTH, ww); glReadPixels( 0, 0, ww, hh, GL_RGB, GL_UNSIGNED_BYTE, imageBuffer ); writeBMP(szFileName, ww, hh, imageBuffer); delete [] imageBuffer; }
// saving to a file void imWindow::Save(char *fname, int inum) { if (saveBuf == NULL) saveBuf = new unsigned char[dwidth*dheight*4]; make_current(); // link error in MSW???? // fl_read_image(saveBuf, 0, 0, dwidth, dheight); // get image into buffer if (inum >= 0) saveNum = inum; if (fname != NULL) saveName = fname; char name[256]; sprintf(name, "%s-%05d.bmp", saveName, saveNum); saveNum++; // if (fname != NULL && inum < 0) // just use fname // imWriteImageColorBMP(fname, saveBuf, dwidth, dheight, 0); // else // imWriteImageColorBMP(name, saveBuf, dwidth, dheight, 0); }
bool application::create_window() { WNDCLASSEXW wc; // register window class if it doesn't exist if (!::GetClassInfoExW(m_wc.hInstance, _class_name, &wc)) { if (!::RegisterClassExW(&m_wc)) { return false; } } int style = m_resizable ? WS_OVERLAPPEDWINDOW : WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME|WS_MAXIMIZEBOX); int ex_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; RECT rc; ::SetRect(&rc, 0, 0, m_width, m_height); ::AdjustWindowRectEx(&rc, style, FALSE, ex_style); m_hwnd = ::CreateWindowExW(ex_style, _class_name, str::to_wide(m_title).c_str(), style, CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, nullptr, nullptr); if (m_hwnd == nullptr) { return false; } // set window as GL PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 32; pfd.iLayerType = PFD_MAIN_PLANE; m_hdc = ::GetDC(m_hwnd); if (!m_hdc) { return false; } int pixelFormat = ::ChoosePixelFormat(m_hdc, &pfd); if (!::SetPixelFormat(m_hdc, pixelFormat, &pfd)) { return false; } m_hrc = ::wglCreateContext(m_hdc); make_current(); // init glew if (!_glew_init) { _glew_init = true; GLenum err = glewInit(); if (err != GLEW_OK) { return false; } if (!GLEW_VERSION_2_1) { return false; } } if (m_fn_start != nullptr) { m_fn_start(); } m_ready = true; return true; }
void Engine::zoom() { const int imagesWidth = ( state == SAVEMNG ) ? animationSavedWidth : w(); const int imagesHeight = ( state == SAVEMNG ) ? animationSavedHeight : h(); Skeleton skelSubframe; // we must check that we are not going to zoom inside the zoom function: if ( skel.selected() == 0 ) { // this section should be synchronized since the selected function // can be changed before its use by Skeleton::subframe skel.shiftSelectedFunction(1); } skelSubframe.subframe(skel); Function functionWork; const Zoom zoom( skel.findFrame( pointsForFraming, _x, _y, _color ), imagesWidth, imagesHeight, skel.getZoomFunction(), framesPerCycle ); for ( std::vector< Image* >::const_iterator i = images.begin(); i != images.end(); ++i ) { delete *i; } images.clear(); for ( int i = 0; i < framesPerCycle; ++i ) { images.push_back( buildImage( imagesWidth, imagesHeight, w(), h() ) ); } int idemo = 1; const int idemoMax = 3; unsigned long clock0 = clock(); const float dilat0 = 1.0/skelSubframe.getFunction().surface(); const float dilat1 = 1.0/skel.getFunction().surface(); const float otherDilat = 1.0/(skel.sumSurfaces() - skel.getFunction().surface()); while ( idemo <= idemoMax ) { for ( int k = 0; k < framesPerCycle; ++k ) { const float rate = (float)k / framesPerCycle; functionWork.spiralMix( skel.getFunction(), skelSubframe.getFunction(), rate ); functionWork.calculateTemp(); int pointsToCalculate = pointsPerFrame; if ( state == SAVEMNG) { // points(t) = points(0)*(1 + S/s(t) * (1/s(t) - 1/s(0))/(1/s(1) - 1/s(0)) ) pointsToCalculate = (int)( ( 1.0 + (1/functionWork.surface()-dilat0) / (dilat1-dilat0) * dilat1 / otherDilat ) * pointsPerFrame ); // to avoid explosion of computation time: if ( pointsToCalculate > 100 * pointsPerFrame ) { pointsToCalculate = 100 * pointsPerFrame; } } for ( int i = 1; clockNumber || i < pointsToCalculate; ++i ) { skel.nextPoint( _x, _y, _color ); float zx = _x; float zy = _y; functionWork.previousPoint( zx, zy, false ); zoom.toScreen( zx, zy ); images[k]->mem_plot( zoom.screenX, zoom.screenY ); images[k]->mem_coul( zoom.screenX, zoom.screenY, _color ); if ( clockNumber ) { if ( i % minimalBuiltPoints == 0 ) { const unsigned long newClock = clock(); if ( newClock - clock0 >= intervalFrame * timecv ) { clock0 = newClock; break; } } } } make_current(); images[k]->mem_draw(); if ( Fl::ready() ) { Fl::check(); } if ( state != ANIMATION && state != DEMO && state != SAVEMNG ) { return; } } if ( state == DEMO ) { ++idemo; } if ( state == SAVEMNG ) { return; } } }
void NavWin::drawPot(NavFn *nav) { float *pot = nav->potarr; COSTTYPE *cst = nav->costarr; int width = nav->nx; int height = nav->ny; // params pw = width; ph = height; // figure out decimation or expansion to fit dec = 1; inc = 1; if (width >= nw/2) { int ww = width; while (ww > nw) { dec++; ww = width/dec; } int hh = height/dec; while (hh > nh) { dec++; hh = height/dec; } if (im == NULL) im = new uchar[nw*nh*3]; // draw potential for (int i=0; i<height-dec+1; i+=dec) { float *pp = pot + i*width; uchar *ii = im + 3*i/dec * nw; for (int j=0; j<width-dec+1; j+=dec, pp+=dec) { int v; if (*pp > maxval) v = 255; else v = (int)((*pp/maxval) * 255.0); *ii++ = v; *ii++ = v; *ii++ = v; } } // draw obstacles for (int i=0; i<height-dec+1; i+=dec) { COSTTYPE *pp = cst + i*width; uchar *ii = im + 3*i/dec * nw; for (int j=0; j<width-dec+1; j+=dec, pp+=dec, ii+=3) { if (*pp >= COST_OBS) { *ii = 120; *(ii+1) = 60; *(ii+2) = 60; } } } } else // expand { int ww = width; while (ww < nw/2) { inc++; ww = width*inc; } int hh = height*inc; while (hh < nh/2) { inc++; hh = height*inc; } if (im == NULL) im = new uchar[nw*nh*3]; for (int i=0; i<height; i++) { float *pp = pot + i*width; uchar *ii = im + 3*i*inc * nw; for (int j=0; j<width; j++, pp++) { int v; if (*pp > maxval) v = 255; else v = (int)((*pp/maxval) * 255.0); for (int k=0; k<inc; k++) { uchar *iii = ii + 3*j*inc + 3*k*nw; for (int kk=0; kk<inc; kk++) { *iii++ = v; *iii++ = v; *iii++ = v; } } } } } make_current(); fl_draw_image(im, 0,0,nw,nh); if (pc) delete [] pc; pce = nav->curPe; pc = new int[pce]; memcpy(pc, nav->curP, pce*sizeof(int)); if (pn) delete [] pn; pne = nav->nextPe; pn = new int[pne]; memcpy(pn, nav->nextP, pne*sizeof(int)); if (po) delete [] po; poe = nav->overPe; po = new int[poe]; memcpy(po, nav->overP, poe*sizeof(int)); // start and goal goal[0] = nav->goal[0]; goal[1] = nav->goal[1]; start[0] = nav->start[0]; start[1] = nav->start[1]; // path if (nav->npath > 0) { pathlen = nav->npath; if (pathbuflen < pathlen) { pathbuflen = pathlen; if (path) delete [] path; path = new int[pathbuflen]; } for (int i=0; i<pathlen; i++) path[i] = width*(int)(nav->pathy[i])+(int)(nav->pathx[i]); } drawOverlay(); redraw(); }
void GLWindow::saveImage( const char *filename ) { // static int screenshotNum = 0; // grab pixels make_current(); int width = w(); int height = h(); unsigned char* pixelData = new unsigned char[width * height * 3]; glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixelData); // get filename // write bitmap file // (quick hack because fltk doesn't have support for saving images) int infoSize = 40; int offset = 14 + infoSize; // make sure each line is aligned on a 4 byte boundary int paddedWidth = ((width * 3) + 3) & (~3); int scanPadding = paddedWidth - (width * 3); int filesize = offset + (paddedWidth * height); int zero = 0; // used for all 0 fields short planes = 1, bitCount = 24; FILE* fp = fopen(filename, "wb"); // header: 14 bytes fwrite("BM", 1, 2, fp); // magic header fwrite(&filesize, 4, 1, fp); fwrite(&zero, 4, 1, fp); // reserved fwrite(&offset, 4, 1, fp); // info header: 40 bytes fwrite(&infoSize, 4, 1, fp); fwrite(&width, 4, 1, fp); fwrite(&height, 4, 1, fp); fwrite(&planes, 2, 1, fp); fwrite(&bitCount, 2, 1, fp); fwrite(&zero, 4, 1, fp); // compression fwrite(&zero, 4, 1, fp); // compressed image size fwrite(&zero, 4, 1, fp); // pixel resolution fwrite(&zero, 4, 1, fp); // pixel resolution fwrite(&zero, 4, 1, fp); // number of colours fwrite(&zero, 4, 1, fp); // important colours // raster image data unsigned char padding = 0, tmp; int n = width * height * 3; // swap red & blue unsigned char* src = pixelData; for (int i = 0; i < n; i += 3, src += 3) { tmp = *src; *src = *(src + 2); *(src + 2) = tmp; } // write out raster data src = pixelData; int delta = width * 3; for (int y = 0; y < height; y++) { fwrite(src, 1, delta, fp); src += delta; for (int i = 0; i < scanPadding; i++) fwrite(&padding, 1, 1, fp); } fclose(fp); delete [] pixelData; }
/// event handling int view::handle(int event) { int mx; int my; int dx=0; int dy=0; int mouse_x; int mouse_y; unsigned int button; int result; switch(event) { case fltk::SHORTCUT: case fltk::KEY: make_current(); // make OpenGL context current // keypress, key is in fltk::event_key(), ascii in fltk::event_text() // Return 1 if you understand/use the keyboard event, 0 otherwise... KeyPressed(FltkToSnowKey(fltk::event_key())); return 1; break; case fltk::MOVE: make_current(); // make OpenGL context current mouse_x = fltk::event_x(); mouse_y = fltk::event_y(); if (m_world) { mouse_move(mouse_x,mouse_y); } result = 1; break; case fltk::PUSH: make_current(); // make OpenGL context current mx = fltk::event_x(); my = fltk::event_y(); mouse_x_old = mx; mouse_y_old = my; take_focus(); button = fltk::event_button(); if (m_world) { mouse_push(button); } result = 1; break; case fltk::RELEASE: make_current(); // make OpenGL context current mx = fltk::event_x(); my = fltk::event_y(); dx = mx-mouse_x_old; dy = my-mouse_y_old; mouse_x_old = mx; mouse_y_old = my; button = fltk::event_button(); return 1; break; case fltk::DRAG: make_current(); // make OpenGL context current mx = fltk::event_x(); my = fltk::event_y(); dx = mx-mouse_x_old; dy = my-mouse_y_old; mouse_x_old = fltk::event_x(); mouse_y_old = fltk::event_y(); button = fltk::event_button(); if (m_world) { mouse_move_button_pressed(button, dx, dy); } result = 1; break; case fltk::FOCUS: return 1; break; case fltk::UNFOCUS: return 1; break; default: // let the base class handle all other events: result = fltk::GlWindow::handle(event); break; } redraw(); return result; }