java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4100
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Outline fonts - NeHe Tutorial JOGL Port E-mail
User Rating: / 3
PoorBest 

This example shows how to use Outline fonts. Outline fonts can be moved along the Z axis and can be resized. You can spin them around on an axis and because proper normals are generated for each character, they can be lit up with lighting. You can build Outline fonts using any of the fonts installed on your computer.

This is the Java port of the one of the NeHe OpenGL tutorials.

You can get complete IntelliJ IDEA project structure (all source, resources, build script, ) by downloading the source distribution from here.

The original post of the programmer who ported the examples can be found here.


Image

package demos.nehe.lesson14;


import demos.common.GLDisplay;

/**
 @author Pepijn Van Eeckhoudt
 */
public class Lesson14 {
    public static void main(String[] args) {
        GLDisplay neheGLDisplay = GLDisplay.createGLDisplay("Lesson 14: Outline fonts");
        Renderer renderer = new Renderer();
        neheGLDisplay.addGLEventListener(renderer);
        neheGLDisplay.start();
    }
}


package demos.nehe.lesson14;

import com.sun.opengl.util.GLUT;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;

import java.text.NumberFormat;

class Renderer implements GLEventListener {
    private float rotation;    // Rotation
    private GLU glu = new GLU();
    private GLUT glut = new GLUT();
    private NumberFormat numberFormat;
    

    public Renderer() {
        numberFormat = NumberFormat.getNumberInstance();
        numberFormat.setMinimumFractionDigits(2);
        numberFormat.setMaximumFractionDigits(2);
    }

    void renderStrokeString(GL gl, int font, String string) {
        // Center Our Text On The Screen
        float width = glut.glutStrokeLength(font, string);
        gl.glTranslatef(-width / 2f00);
        // Render The Text
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            glut.glutStrokeCharacter(font, c);
        }
    }

    public void init(GLAutoDrawable glDrawable) {
        GL gl = glDrawable.getGL();
        gl.glShadeModel(GL.GL_SMOOTH);              // Enable Smooth Shading
        gl.glClearColor(0.0f0.0f0.0f0.5f);    // Black Background
        gl.glClearDepth(1.0f);                      // Depth Buffer Setup
        gl.glEnable(GL.GL_DEPTH_TEST);              // Enables Depth Testing
        gl.glDepthFunc(GL.GL_LEQUAL);               // The Type Of Depth Testing To Do
        
        gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
        gl.glEnable(GL.GL_LIGHT0);                  // Enable Default Light (Quick And Dirty)
        gl.glEnable(GL.GL_LIGHTING);                // Enable Lighting
        gl.glEnable(GL.GL_COLOR_MATERIAL);          // Enable Coloring Of Material
    }

    public void display(GLAutoDrawable glDrawable) {
        GL gl = glDrawable.getGL();
        
        // Clear Screen And Depth Buffer
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);  
        
        gl.glLoadIdentity();                                // Reset The Current Modelview Matrix
        gl.glTranslatef(0.0f0.0f, -15.0f);                // Move One Unit Into The Screen
        gl.glRotatef(rotation, 1.0f0.0f0.0f);           // Rotate On The X Axis
        gl.glRotatef(rotation * 1.5f0.0f1.0f0.0f);    // Rotate On The Y Axis
        gl.glRotatef(rotation * 1.4f0.0f0.0f1.0f);    // Rotate On The Z Axis
        gl.glScalef(0.005f0.005f0.0f);
        // Pulsing Colors Based On The Rotation
        gl.glColor3f((float) (Math.cos(rotation / 20.0f))
                (float) (Math.sin(rotation / 25.0f))1.0f 0.5f 
                (float) (Math.cos(rotation / 17.0f)));
        
        renderStrokeString(gl, GLUT.STROKE_MONO_ROMAN, "NeHe - " 
                numberFormat.format((rotation / 50)))// Print GL Text To The Screen
        
        rotation += 0.5f;  // Increase The Rotation Variable
    }

    public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
        if (h == 0h = 1;
        GL gl = glDrawable.getGL();
        
        // Reset The Current Viewport And Perspective Transformation
        gl.glViewport(00, w, h);                       
        
        gl.glMatrixMode(GL.GL_PROJECTION);    // Select The Projection Matrix
        gl.glLoadIdentity();                  // Reset The Projection Matrix
        
        // Calculate The Aspect Ratio Of The Window
        glu.gluPerspective(45.0f(floatw / (floath, 0.1f100.0f);  
        
        gl.glMatrixMode(GL.GL_MODELVIEW);     // Select The Modelview Matrix
        gl.glLoadIdentity();                  // Reset The ModalView Matrix
    }

    public void displayChanged(GLAutoDrawable glDrawable, boolean b, boolean b1) {
    }
}

 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.