3d + text

19 views
Skip to first unread message

Erik Svedäng

unread,
May 5, 2015, 1:48:56 PM5/5/15
to clj-pro...@googlegroups.com
I'm trying to experiment with 3d in Quil and it's going well but when I try to display some text at the same time (I just want a FPS-counter up in the corner to begin with) all my other graphics are gone.

Also, when I remove the call to 'text' and re-evaluate the form I don't get my graphics back...

Any help would be much appreciated!

Here's the code:

(defn cubo [x y]
  (q/with-translation [x y 0]
    (q/with-rotation [(* 0.001 (q/millis)) 0 1 0]
      (q/box 10))))

(defn draw-state [state]
  (q/background 100 100 100)
  (q/stroke-weight 1)
  (q/stroke 0)
  (q/begin-camera)
  (q/camera 0 0 (pulse -50 -570 3.0)
            0 0 0
            0 1 0)
  (doall (for [x (range -300 300 20)
               y (range -300 300 20)]
           (do (q/fill (* 255 (q/sin x))
                       (* 255 (q/sin (* 5 (t))))
                       (* 255 (q/cos y)))
               (cubo x y))))
  (q/end-camera)
 ;; (q/text "FPS: 60" 10 10)
  )


Erik Svedäng

unread,
May 5, 2015, 2:09:26 PM5/5/15
to clj-pro...@googlegroups.com
Oh, I solved it:

(q/begin-camera)
(q/camera)
(q/fill 255)
(q/no-stroke)
(q/rect 0 0 120 30)
(q/fill 0)
(q/text (str "FPS: " (q/current-frame-rate)) 10 20)
(q/end-camera)

The text is drawn in the same 3d space as the rest of the graphics though, I'd like to know how to make it appear always on top.

Cheers,
Erik

Nikita Beloglazov

unread,
May 5, 2015, 10:37:38 PM5/5/15
to clj-pro...@googlegroups.com
You can try following trick:
1. Create a graphics using create-graphics function. The size of graphics should be small, to fit the text.
2. Draw a text on that graphics.
3. Copy it to sketch using copy function. 

Nikita

--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Erik Svedäng

unread,
May 7, 2015, 7:45:17 AM5/7/15
to clj-pro...@googlegroups.com
Oh, interesting idea. Thanks!
Reply all
Reply to author
Forward
0 new messages