static void redraw_handler(struct widget *widget, void *data) { struct cliptest *cliptest = data; struct geometry *g = cliptest->view.geometry; struct rectangle allocation; cairo_t *cr; cairo_surface_t *surface; GLfloat ex[8]; GLfloat ey[8]; int n; n = calculate_edges(&cliptest->view, &g->clip, &g->surf, ex, ey); widget_get_allocation(cliptest->widget, &allocation); surface = window_get_surface(cliptest->window); cr = cairo_create(surface); widget_get_allocation(cliptest->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_line_width(cr, 1.0); cairo_move_to(cr, allocation.width / 2.0, 0.0); cairo_line_to(cr, allocation.width / 2.0, allocation.height); cairo_move_to(cr, 0.0, allocation.height / 2.0); cairo_line_to(cr, allocation.width, allocation.height / 2.0); cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0); cairo_stroke(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_push_group(cr); cairo_translate(cr, allocation.width / 2.0, allocation.height / 2.0); cairo_scale(cr, 4.0, 4.0); cairo_set_line_width(cr, 0.5); cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL); cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 5.0); draw_geometry(cr, &cliptest->view, ex, ey, n); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0); cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, 12.0); draw_coordinates(cr, 10.0, 10.0, ex, ey, n); cairo_destroy(cr); cairo_surface_destroy(surface); }
void on_gl_select(const k3d::gl::render_state& State, const k3d::gl::selection_state& SelectState) { k3d::gl::store_attributes attributes; glDisable(GL_LIGHTING); k3d::gl::push_selection_token(this); draw_geometry(); k3d::gl::pop_selection_token(); }
void GeomDrawBox::draw_geometry(cairo_t *cr, OGRGeometry *geom, double scale, double x, double y, double height) { switch (geom->getGeometryType()) { case wkbPolygon: draw_polygon(cr, dynamic_cast<OGRPolygon*>(geom), scale, x, y, height); break; case wkbMultiPolygon: { OGRGeometryCollection *geoCollection = dynamic_cast<OGRGeometryCollection*>(geom); for (int i = 0; i < geoCollection->getNumGeometries(); ++i) draw_geometry(cr, geoCollection->getGeometryRef(i), scale, x, y, height); } break; default: log_warning("Can't paint geometry type %s\n", geom->getGeometryName()); break; } }
void GeomDrawBox::repaint(cairo_t *cr, int x, int y, int w, int h) { if (_geom) { OGREnvelope env; _geom->getEnvelope(&env); double fig_width = env.MaxX - env.MinX; double fig_height = env.MaxY - env.MinY; double scale; int padding = 5; if (fig_width > fig_height) scale = (get_width() - padding*2) / fig_width; else scale = (get_height() - padding*2) / fig_height; cairo_translate(cr, padding, padding); draw_geometry(cr, _geom, scale, env.MinX, env.MinY, get_height()-padding*2); } }
void glwidget::paintGL() { // if( !_info._ready_to_draw ) return; // Clear color and depth buffer. // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Calculate model view transformation. // QMatrix4x4 matrix; matrix.translate( 0,0, -5.0); // Set modelview-projection matrix. // _info._qprogram.setUniformValue("mvp_matrix", _info._projection * matrix); // Draw. // draw_geometry(); }
// called from Model::draw void Shape::draw(const Settings &settings, bool highlight, uint max_triangles) { //cerr << "Shape::draw" << endl; // polygons glEnable(GL_LIGHTING); Vector4f no_mat(0.0f, 0.0f, 0.0f, 1.0f); Vector4f low_mat(0.2f, 0.2f, 0.2f, 1.0f); // float mat_ambient[] = {0.7f, 0.7f, 0.7f, 1.0f}; // float mat_ambient_color[] = {0.8f, 0.8f, 0.2f, 1.0f}; Vector4f mat_diffuse(0.1f, 0.5f, 0.8f, 1.0f); Vector4f mat_specular(1.0f, 1.0f, 1.0f, 1.0f); // float no_shininess = 0.0f; // float low_shininess = 5.0f; // float high_shininess = 100.0f; // float mat_emission[] = {0.3f, 0.2f, 0.2f, 0.0f}; //for (uint i = 0; i < 4; i++) { mat_diffuse = settings.get_colour("Display","PolygonColour"); //} if (highlight) mat_diffuse.array[3] += 0.3*(1.-mat_diffuse.array[3]); // invert colours if partial draw (preview mode) if (max_triangles > 0) { for (uint i = 0; i < 3; i++) mat_diffuse.array[i] = 1.-mat_diffuse.array[i]; mat_diffuse[3] = 0.9; } mat_specular.array[0] = mat_specular.array[1] = mat_specular.array[2] = settings.get_double("Display","Highlight");; /* draw sphere in first row, first column * diffuse reflection only; no ambient or specular */ glMaterialfv(GL_FRONT, GL_AMBIENT, low_mat); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT, GL_SHININESS, 90); // 0..128 glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); // glEnable (GL_POLYGON_OFFSET_FILL); if(settings.get_boolean("Display","DisplayPolygons")) { glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); // glDepthMask(GL_TRUE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //define blending factors draw_geometry(max_triangles); } glDisable (GL_POLYGON_OFFSET_FILL); // WireFrame if(settings.get_boolean("Display","DisplayWireframe")) { if(!settings.get_boolean("Display","DisplayWireframeShaded")) glDisable(GL_LIGHTING); //for (uint i = 0; i < 4; i++) mat_diffuse = settings.get_colour("Display","WireframeColour"); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glColor4fv(mat_diffuse); for(size_t i=0;i<triangles.size();i++) { glBegin(GL_LINE_LOOP); glLineWidth(1); glNormal3dv((GLdouble*)&(triangles[i].Normal)); glVertex3dv((GLdouble*)&(triangles[i].A)); glVertex3dv((GLdouble*)&(triangles[i].B)); glVertex3dv((GLdouble*)&(triangles[i].C)); glEnd(); } } glDisable(GL_LIGHTING); // normals if(settings.get_boolean("Display","DisplayNormals")) { glColor4fv(settings.get_colour("Display","NormalsColour")); glBegin(GL_LINES); double nlength = settings.get_double("Display","NormalsLength"); for(size_t i=0;i<triangles.size();i++) { Vector3d center = (triangles[i].A+triangles[i].B+triangles[i].C)/3.0; glVertex3dv((GLdouble*)¢er); Vector3d N = center + (triangles[i].Normal*nlength); glVertex3dv((GLdouble*)&N); } glEnd(); } // Endpoints if(settings.get_boolean("Display","DisplayEndpoints")) { glColor4fv(settings.get_colour("Display","EndpointsColour")); glPointSize(settings.get_double("Display","EndPointSize")); glBegin(GL_POINTS); for(size_t i=0;i<triangles.size();i++) { glVertex3dv((GLdouble*)&(triangles[i].A)); glVertex3dv((GLdouble*)&(triangles[i].B)); glVertex3dv((GLdouble*)&(triangles[i].C)); } glEnd(); } glDisable(GL_DEPTH_TEST); }
int main (int argc, char** argv) { // 1. X stuff //1.1 X display g_xdisplay = XOpenDisplay (NULL); if (g_xdisplay == NULL) { return EGL_FALSE; } g_xroot = DefaultRootWindow (g_xdisplay); //1.2 X window XSetWindowAttributes swa; swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask; g_xwindow = XCreateWindow (g_xdisplay, g_xroot, 0, 0, g_xwindow_width, g_xwindow_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &swa); XSetWindowAttributes xattr; xattr.override_redirect = 0; XChangeWindowAttributes (g_xdisplay, g_xwindow, CWOverrideRedirect, &xattr); XWMHints hints; hints.input = 1; hints.flags = InputHint; XSetWMHints(g_xdisplay, g_xwindow, &hints); XMapWindow (g_xdisplay, g_xwindow); XStoreName (g_xdisplay, g_xwindow, g_xwindow_title); Atom wm_state; wm_state = XInternAtom (g_xdisplay, "_NET_WM_STATE", 0); // 2. EGL stuff // 2.1 egl display. g_egldisplay = eglGetDisplay ((EGLNativeDisplayType)g_egldisplay); if (g_egldisplay == EGL_NO_DISPLAY) { return EGL_FALSE; } // 2.2 Initialize EGL EGLint major_version; EGLint minor_version; if (!eglInitialize (g_egldisplay, &major_version, &minor_version)) { return EGL_FALSE; } // 2.3 configuration management EGLint num_configs; EGLint attrib_list[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_NONE }; if (!eglGetConfigs (g_egldisplay, NULL, 0, &num_configs)) { return EGL_FALSE; } if (!eglChooseConfig (g_egldisplay, attrib_list, &g_eglconfig, 1, &num_configs)) { return EGL_FALSE; } // 2.4 surface creation g_eglsurface = eglCreateWindowSurface (g_egldisplay, g_eglconfig, (EGLNativeWindowType)g_xwindow, NULL); if (g_eglsurface == EGL_NO_SURFACE) { return EGL_FALSE; } // 2.5 Create a GL context EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; g_eglcontext = eglCreateContext (g_egldisplay, g_eglconfig, EGL_NO_CONTEXT, context_attribs); if (g_eglcontext == EGL_NO_CONTEXT) { return EGL_FALSE; } // 2.6 Make the context current if (!eglMakeCurrent(g_egldisplay, g_eglsurface, g_eglsurface, g_eglcontext)) { return EGL_FALSE; } //3. init graphics pipeline. if (!init_pipeline ()) return GL_FALSE; //4. Main Loop int state = 1; XEvent xev; while (state) { XNextEvent (g_xdisplay, &xev); switch (xev.type) { case Expose: draw_geometry (); break; case DestroyNotify: state = 0; break; default: draw_geometry (); break; } // we must call eglSwapBuffers to show the back buffer. eglSwapBuffers (g_egldisplay, g_eglsurface); } }