Displaying text in P3D

edited October 2013 in Questions about Code

I'm trying to simulate a card being flipped with some text on it. nothing shows with text() using P3D or OPENGL. I read that I might need to add a text to the data file. how do I do this? where do I copy it from?

float angle = 0;
void setup() {
  size(500,500,P3D);
 camera(400,-200,700,
         0,0,0,
         0,1,0);
 text("Hey", 20,60,-10);
}
void draw() {
  if (angle < 3) {
    angle =angle +0.1;
  fill(150,150,150);
  background(255);
   rectMode(CORNER);
    rotateY(angle);
    box(150,350,2);
    textSize(30);
    color(255,0,0);
    text("Hey", 20,60,-10);
  delay(100);
  println(angle);
 if (angle >= 2.9){ angle =0;}
  }
     
 }
Tagged:

Comments

  • Actually, I think your 3D code is fine. the problem is that you're not settling the text color correctly. The color() function just returns a color, it doesn't set the display color for text. You need to call fill() for that. When I make that one change, your text starts to show up for me. It might not have exactly the relationship to the plane that you think it should, though. I might think about using a PGraphics object to draw both the rectangle and the text and then rotating that in 3D to make things simpler.

    float angle = 0; 
    
    void setup() { 
      size(500, 500, P3D); 
      camera(400, -200, 700, 0, 0, 0, 0, 1, 0); 
    } 
    void draw() { 
      if (angle < 3) { 
        angle =angle +0.1; 
        fill(150, 150, 150); 
        background(255); 
        rectMode(CORNER); 
        rotateY(angle); 
        box(150, 350, 2); 
        textSize(30); 
        fill(255, 0, 0); 
        text("Hey", 20, 60, -10); 
        delay(100); 
        println(angle); 
        if (angle >= 2.9) { 
          angle =0;
        }
      }
    }
    
  • You are correct on both points. Text now shows and it will not give the effect I was looking for. Thanks sorry about the code formatting. I will look at PGraphics

  • How can I only show the text on one side of the card after it is flipped?

    __float angle = 0; 
    PGraphics pg; 
    void setup() { 
      size(500, 500, P3D); 
      camera(400, -200, 700, 0, 0, 0, 0, 1, 0); 
       pg = createGraphics(200, 340);
      fill(255, 0, 0); 
        //text("Hey", 130, 60, -30);
        
        
         pg.beginDraw();
      //pg.background(100);
      pg.stroke(255);
      pg.textSize(32);
      pg.fill(255,0,0,50);
      pg.text("Hey", 20, 50);
      pg.fill(89,92,255,100);
      pg.rectMode(CORNER); 
      pg.rect(20, 20,150,250);
      
      pg.fill(255,0,0);
      pg.text("Action", 20, 50);
      pg.endDraw();
    } 
    void draw() { 
      
      
     
      if (angle < 3) { 
        angle =angle+0.1; 
        //fill(150, 150, 150); 
        background(255); 
        rectMode(CORNER); 
        rotateY(angle); 
        translate(-60,0);
        image(pg, 50, 130);
        
        delay(100); 
        println(angle); 
        if (angle >= 2.99) { 
          angle =0;
        }
      }
    }
    
  • edited October 2013

    How about 2 PImages for front & back.
    Then decide which 1 to display based on current angle? :-\"

    /** 
     * Rotating Card (v2.82)
     * by  Redwire (2013/Oct)
     * mod GoToLoop
     * 
     * forum.processing.org/two/discussion/92/displaying-text-in-p3d
     * studio.processingtogether.com/sp/pad/export/ro.9oKy5N3D6zFZT/latest
     */
    
    //final static float TAU = TWO_PI;   // JS
    
    final static float STEP = .01;
    final static short FPS = 60, SMOOTH = 4;
    
    PImage front, back;
    float angle, dir = 1.;
    boolean isPaused;
    
    void setup() {
      size(500, 500, P3D);
      frameRate(FPS);
      smooth(SMOOTH);
      rectMode(CORNER);
    
      camera(width - 100, -100, 300, 0, 0, 0, 0, 1, 0);
    
      front = createCard(true);
      back  = createCard(false);
    }
    
    void draw() {
      background(-1);
      rotateY(angle);
    
      showInfo();   // Java
    
      final boolean bool = angle < HALF_PI + QUARTER_PI
        | angle > TAU - QUARTER_PI/1.5;
    
      image(bool? front : back, 0, -180);
    
      if ((angle += STEP*dir) > TAU)   angle = 0;
      else if (angle < 0)              angle = TAU;
    }
    
    void mousePressed() {
      if      (mouseButton != LEFT)    dir *= -1.;
      else if (isPaused = !isPaused)   noLoop();
      else                             loop();
    }
    
    void keyPressed() {
      mousePressed();
    }
    
    void showInfo() {   // Java
      frame.setTitle("Rotating Card \t\t\t Angle: " 
        + nf(angle, 0, 2));
    }
    
    PImage createCard(boolean hasText) {
      final PGraphics pg = createGraphics(200, 340, P2D);
    
      pg.beginDraw();
      pg.smooth(SMOOTH);
      pg.rectMode(CORNER);
      pg.background(0200);
      pg.stroke(-1);
      pg.textSize(040);
    
      pg.fill(89, 92, 255, 100);
      pg.rect(20, 20, 150, 250);
    
      if (hasText) {
        pg.fill(#FF0000);
        pg.text("Action", 30, 50);
    
        pg.fill(#00FFFF);
        pg.text("Hey", pg.width - 100, pg.height - 100);
      }
    
      pg.endDraw();
      return pg.get();
    }
    
  • The sketch opens but nothing show up regardless of whether I click the mouse or hit a key. If I change a fill parameter say #FF0000 to #C700FF , I get an error message Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting.

  • edited October 2013

    Perhaps a SMOOTH = 8 is too high for your system! (O_O) Lower that and try again. :D

    Anyways, I've posted an adapted version of it online. Check it out: (^_^)
    http://studio.processingtogether.com/sp/pad/export/ro.9oKy5N3D6zFZT/latest

  • I tried with SMOOTH = 6,4,2 and with reduced frame rate with no success. I think it is a computer software issue. Here is the complete output.

    Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
    OpenGL error 1286 at top endDraw(): invalid framebuffer operation
    OpenGL error 1286 at bot endDraw(): invalid framebuffer operation
    Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
    Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
    Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
    Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000001800585e4, pid=5724, tid=3856
    #
    # JRE version: 6.0_37-b06
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (20.12-b01 mixed mode windows-amd64 compressed oops)
    # Problematic frame:
    # C  [ig4icd64.dll+0x585e4]
    #
    # An error report file with more information is saved as:
    # C:\Users\Hingle\Processing2.0.3\processing-2.0.3\hs_err_pid5724.log
    #
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #
    Could not run the sketch (Target VM failed to initialize).
    For more information, read revisions.txt and Help ? Troubleshooting.
    

    for Java

Sign In or Register to comment.