painterly rendering

Download Painterly Rendering

Post on 03-Jan-2016




0 download

Embed Size (px)


Painterly Rendering. CMPS 160 - Assignment 2. OpenGL. OpenGL is a cross-language, cross-platform specification definingand API for 2D and 3D graphics (taking advantage of hardwareacceleration when possible).. GLUT. GL Utility Toolkit - PowerPoint PPT Presentation


  • Painterly RenderingCMPS 160 - Assignment 2

  • OpenGLOpenGL is a cross-language, cross-platform specification definingand API for 2D and 3D graphics (taking advantage of hardwareacceleration when possible).

  • GLUTGL Utility ToolkitGLUT is a layer on top of OpenGL that hides details of communicatingwith the system to control windows, and monitor the keyboard and mouse.

  • Assignment OverviewWrite code from scratch (ok, minimal base code)Due in 1 weekMakefile takes care of building and converting image formatsBuild process assumes you use C++ but you dont have to use an OO concepts (base code doesnt).Designed for Mac lab (if you want to build elsewhere you should only have to change the Makefile) -- Makefile.cygwin available on class page

  • DemoMy is 217 lines longIncludes generous whitespace and commentsAllows various color and brush modes.I spent way too much time painting cool pictures instead of debugging to give a good estimate on programming time My guess 2-8 hours?

  • ConceptsThink of GLUT as a machine, you configure it, turn it on, and leave it run by itself.Register callbacks to have to contact you back when certain events happen.Within callbacks, think of OpenGL as something you are sending message to.Use your normal loops and conditionals to get the right commands triggered at the right time and use glFlush() to get to to actually perform all the actions it has stored up. Its lazy on these Macs.

  • extreeeeeeeeeeeeeeeeeeeemly high level psuedocode)include ppm canvas headerinclude gl/glut headers

    declare some shared state variablesdeclare some callback functionsdeclare main

  • main()Initialize glut -- glutInitload source image -- ppmLoadCanvasCreate a window -- glutCreateWindowregister callbacks -- glutSomethingFunc

    Let GLUT take over -- glutMainLoop() **never returns**

  • cb_display()Normally all screen drawing code goes hereWe are lazyWe only draw when the user tries to paint somethingLeave the body of this function blank

  • cb_mouse(button,state,x,y)Called whenever a mouse button is pushed down or let upPut your code to draw a paint blob here or in

  • cb_motion(x,y)Called for each location along a mouse dragging pathWhen user drags, moves, drags again there is a jump in the coordinates fed to this function, use cb_mouse to figure out when this happensPaint here if you likeSave this x,y for later so you can use it to draw lines from this position to the nextIf you want to track mouse motion when no buttons are down there is way

  • cb_keyboard(key,x,y)Called whenever a key is pressedYou should exit(0) when the user presses qYou can use other keys to trigger changing of painting modes or clear the screen.No modifiers (alt,ctrl,whatever) are passed, there is a way to get these

  • cb_reshape(w,h)Called at startup and when the window is resizedYou should save w,h to help interpret mouse coordinatesglViewport tells GL what part of the window you want to use (all of it!)Look up glMatrixMode and gluOrtho2D to setup projection matrix properlyOptionally, clear the screen as well

  • Global state variablesCanvas - the function where you actually paint needs access to the source image loaded in main()Window size - compare mouse coordinates to these to figure out relative location within windowLast cursor position - draw lines from this location to current location to make directional strokes if you like

  • ppm_canvas usagecanvas_t canvas;ppmLoadCanvas(some.ppm,&canvas);int x = 50; // column, left to rightint y = 100; // row, top to bottom (I think)pixel_t pixel = PIXEL(canvas,x,y);int r = RED(pixel);float g = GREEN(pixel)/255.0;// OpenGL expects colors in the range 0.0f-1.0f

  • Actually painting somethingLook these up in the linked documentaiton:glBegin(GL_???)glEnd()glColor*()glVertex*()

  • the provided Makefilemake builds your program, tells you what to write in your README if you dont have onemake demo builds binary+documentation tarball to brag to your friends/classmates without revealing top secret painting effect implementationmake some.ppm converts some.jpg to ppm format (also works for gif, png, whatever)If you use multiple source files to complete the assignment you must edit the a line in the Makefile


View more >