|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object glapp.GLApp
public class GLApp
Collection of functions to init and run an OpenGL app using LWJGL.
Includes functions to handle:
Setup display mode, keyboard, mouse, handle events
Run main loop of application
Buffer allocation -- manage IntBuffer, ByteBuffer calls.
OpenGL functions -- convert screen/world coords, set modes, lights, etc.
Utility functions -- load images, convert pixels, getTimeInMillis, etc.
Has a main() function to run as an application, though this class has only minimal placeholder functionality. It is meant to be subclassed, and the subclass will define setup() draw() mouseMove() functions, etc.
GLApp initializes the LWJGL environment for OpenGL rendering, ie. creates a window, sets the display mode, inits mouse and keyboard, then runs a loop.
Uses GLImage to load and hold image pixels.
napier -at- potatoland -dot- org
GLImage
Field Summary | |
---|---|
static java.net.URL |
appletBaseURL
|
static float |
aspectRatio
|
static java.nio.FloatBuffer |
bufferModelviewMatrix
|
static java.nio.FloatBuffer |
bufferProjectionMatrix
|
static java.nio.IntBuffer |
bufferViewport
|
static float[] |
colorBlack
|
static float[] |
colorBlue
|
static float[] |
colorClear
|
static float[] |
colorGray
|
static float[] |
colorGreen
|
static float[] |
colorRed
|
static float[] |
colorWhite
|
static java.lang.String |
configFilename
|
static int |
cursorX
|
static int |
cursorY
|
static int |
depthBufferBits
|
static boolean |
disableNativeCursor
|
static int |
displayColorBits
|
static int |
displayFrequency
|
static int |
displayHeight
|
static java.util.ArrayList |
displayLists
|
static DisplayMode |
displayMode
|
static int |
displayWidth
|
static DisplayMode |
DM
|
static boolean |
finished
|
static int |
finishedKey
|
static int |
frameCount
|
static boolean |
fullScreen
|
static java.lang.String |
GLAPP_VERSION
|
static boolean |
hideNativeCursor
|
static double |
lastFrameTime
|
static java.nio.FloatBuffer |
mtlambient
|
static java.nio.FloatBuffer |
mtldiffuse
|
static java.nio.FloatBuffer |
mtlemissive
|
static java.nio.FloatBuffer |
mtlshininess
|
static java.nio.FloatBuffer |
mtlspecular
|
static DisplayMode |
origDM
|
static float |
PIOVER180
|
static float |
PIUNDER180
|
static java.lang.Class |
rootClass
|
static float |
rotation
|
static int |
screenTextureSize
|
static double |
secondsSinceLastFrame
|
static java.util.Properties |
settings
|
static boolean |
showMessages
|
static int |
SIZE_BYTE
|
static int |
SIZE_DOUBLE
|
static int |
SIZE_FLOAT
|
static int |
SIZE_INT
|
static long |
ticksPerSecond
|
static java.nio.ByteBuffer |
tmpByte
|
static java.nio.ByteBuffer |
tmpFloat
|
static java.nio.FloatBuffer |
tmpFloats
|
static java.nio.ByteBuffer |
tmpInt
|
static java.nio.IntBuffer |
tmpInts
|
static java.nio.FloatBuffer |
tmpResult
|
static boolean |
useCurrentDisplay
|
static int |
viewportH
|
static int |
viewportW
|
static int |
viewportX
|
static int |
viewportY
|
static boolean |
VSyncEnabled
|
static java.lang.String |
window_title
|
Constructor Summary | |
---|---|
GLApp()
|
Method Summary | |
---|---|
static void |
activateMask(int maskvalue)
Restrict rendering to the masked area. |
static void |
activateTexture(int textureHandle)
"Select" the given texture for further texture operations. |
static int |
allocateTexture()
Allocate a texture (glGenTextures) and return the handle to it. |
static java.nio.ByteBuffer |
allocBytes(byte[] bytearray)
|
static java.nio.ByteBuffer |
allocBytes(int howmany)
|
static java.nio.DoubleBuffer |
allocDoubles(double[] darray)
|
static java.nio.DoubleBuffer |
allocDoubles(int howmany)
|
static java.nio.FloatBuffer |
allocFloats(float[] floatarray)
|
static java.nio.FloatBuffer |
allocFloats(int howmany)
|
static java.nio.IntBuffer |
allocInts(int howmany)
|
static java.nio.IntBuffer |
allocInts(int[] intarray)
|
static void |
applyMaterial()
Call glMaterial() to activate these material properties in the OpenGL environment. |
static int |
beginDisplayList()
Begin a display list. |
static void |
beginMask(int maskvalue)
Begin creating a mask. |
static void |
buildFont(int fontTxtrHandle,
int fontWidth)
Build the character set display list from the given texture. |
static boolean |
buildFont(java.lang.String charSetImage,
int fontWidth)
Build a character set from the given texture image. |
static void |
callDisplayList(int displayListID)
Render the geometry stored in a display list. |
void |
cleanup()
Run() calls this right before exit. |
static void |
clearMask()
clear the stencil buffer |
static void |
copyImageToTexture(GLImage img,
int textureHandle)
Calls glTexSubImage2D() to copy pixels from an image into a texture. |
static void |
copyPixelsToTexture(java.nio.ByteBuffer bb,
int w,
int h,
int textureHandle)
Copy pixels from a ByteBuffer to a texture. |
static void |
deleteTexture(int textureHandle)
De-allocate the given texture (glDeleteTextures()). |
static void |
destroyDisplayList(int DL_ID)
Delete the given display list ID. |
static void |
destroyDisplayLists()
Clean up the allocated display lists. |
static void |
destroyFont()
Clean up the allocated display lists for the character set. |
static void |
disableMask()
turn off the stencil test so stencil has no further affect on rendering. |
static void |
disableNativeCursor(boolean off)
If the param is true, turn off the hardware cursor. |
void |
draw()
Called by run() to draw one frame. |
static void |
drawCircle(float innerRadius,
float outerRadius,
int numSegments)
Draws a circle centered at 0,0,0. |
static void |
drawCircle(int x,
int y,
int radius,
int linewidth)
Draws a circle with the given radius centered at the given world position. |
static void |
drawCircleZ(int x,
int y,
int z,
int radius,
int linewidth)
Draws a circle with the given radius centered at the given world position. |
static void |
drawCursor(int cursorTextureHandle)
Draw a cursor image textured onto a quad at cursorX,cursorY. |
static void |
drawCursorOLD(int cursorTextureHandle)
OLD function: this drew the cursor only into the current viewport, and could not handle difffent ortho coordinate systems (ortho had to be exactly mapped to screen size). |
static void |
drawImage(GLImage img,
int x,
int y,
float w,
float h)
Draw an image in whichever projection mode is current (does not switch to ortho mode). |
static void |
drawImageFullScreen(GLImage img)
Draw an image in ortho mode (2D) over the entire viewport area. |
static void |
drawQuad(int textureHandle,
int x,
int y,
float w,
float h)
Draw a textured quad in Ortho mode (2D) at the given xy, scaled to the given width and height. |
static void |
drawQuadZ(int textureHandle,
float x,
float y,
float z,
float w,
float h)
Draw a textured quad at the given xyz position in 3D space. |
static void |
drawRect(int x,
int y,
float w,
float h)
Draw a rectangle outline in ortho mode (draws in 2D over the scene). |
static void |
drawRectZ(int x,
int y,
int z,
float w,
float h)
Draw a rectangle outline in world space. |
static void |
endDisplayList()
Finish display list creation. |
static void |
endMask()
End the mask. |
static void |
err(java.lang.String text)
Show an error message on the system console (calls System.out.println()). |
void |
exit()
Shutdown the application. |
static boolean |
extensionExists(java.lang.String extensionName)
Return true if the OpenGL context supports the given OpenGL extension. |
static void |
frameCopy(int txtrHandle)
Save entire screen image to a texture. |
static void |
frameCopy(int txtrHandle,
int x,
int y,
int w,
int h)
Save a region of the screen to a texture. |
static void |
frameCopy(Pbuffer pbuff,
int textureHandle)
Copy the pbuffer contents to a texture. |
static void |
frameDraw(int txtrHandle)
Draw the screen-sized image over entire screen area. |
static java.nio.ByteBuffer |
framePixels()
Return a ByteBuffer containing ARGB pixels of the entire screen area. |
static java.nio.ByteBuffer |
framePixels(int x,
int y,
int w,
int h)
Return a ByteBuffer containing ARGB pixels from the given screen area. |
static int[] |
framePixelsInt(int x,
int y,
int w,
int h)
Return an int array containing ARGB pixels from the given screen area. |
static void |
frameSave()
Save the current frame buffer to a PNG image. |
static void |
get(java.nio.ByteBuffer b,
int[] values)
copy ints from the given byteBuffer into the given int array. |
static void |
get(java.nio.IntBuffer b,
int[] values)
copy ints from the given IntBuffer into the given int array. |
static byte[] |
getBytesFromFile(java.lang.String filename)
Return an array of bytes read from a file. |
static byte[] |
getBytesFromStream(java.io.InputStream is)
Return an array of bytes read from an InputStream. |
static DisplayMode |
getDisplayMode(int w,
int h,
int colorBits,
int freq)
Retrieve a DisplayMode object with the given params |
static double |
getFramesPerSecond()
Return the moving average of the frames per second for the last 50 frames. |
static int |
getHeight()
return the height of the Viewport (the screen area that OpenGL will draw into). |
static int |
getHeightWindow()
return the Display height (the height of the full window). |
static java.io.InputStream |
getInputStream(java.lang.String filename)
Open the given file and return the InputStream. |
static int[] |
getInts(java.nio.ByteBuffer b)
return the contents of the byteBuffer as an array of ints. |
static int |
getMaskValue(int x,
int y)
Return the stencil buffer value at the given screen position. |
static float[][] |
getMatrixAsArray(java.nio.FloatBuffer fb)
Convert a FloatBuffer matrix to a 4x4 float array. |
static java.nio.FloatBuffer |
getModelviewMatrix()
|
static java.lang.String[] |
getPathAndFile(java.lang.String filename)
Return a String array containing the path portion of a filename (result[0]), and the fileame (result[1]). |
static byte[] |
getPixelColor(int x,
int y)
Return the color buffer RGB value at the given screen position as byte[3]. |
static float |
getPixelDepth(int x,
int y)
Return the depth buffer value at the given screen position. |
static int |
getPixelStencil(int x,
int y)
Return the stencil buffer value at the given screen position. |
static int |
getPowerOfTwoBiggerThan(int n)
Find a power of two equal to or greater than the given value. |
static java.nio.FloatBuffer |
getProjectionMatrix()
|
static java.lang.String |
getProperty(java.util.Properties props,
java.lang.String propName)
|
static java.lang.String |
getProperty(java.lang.String propertyName)
Return a property from the application configuration file (the filename given in the configFilename variable). |
static boolean |
getPropertyBool(java.util.Properties props,
java.lang.String propName)
|
static float |
getPropertyFloat(java.util.Properties props,
java.lang.String propName)
|
static int |
getPropertyInt(java.util.Properties props,
java.lang.String propName)
|
static double |
getSecondsPerFrame()
Return the moving average of the seconds per frame for the last 50 frames. |
static int |
getSettingInt(int whichSetting)
retrieve a setting from OpenGL (calls glGetInteger()) |
static double |
getTimeInMillis()
|
static double |
getTimeInSeconds()
|
static java.nio.IntBuffer |
getViewport()
|
static int |
getWidth()
return the width of the Viewport (the screen area that OpenGL will draw into). |
static int |
getWidthWindow()
return the Display width (the width of the full window). |
static float[] |
getWorldCoordsAtScreen(int x,
int y)
For given screen xy, return the world xyz coords in a float array. |
static float[] |
getWorldCoordsAtScreen(int x,
int y,
float z)
For given screen xy and z depth, return the world xyz coords in a float array. |
static float |
getZDepth(int x,
int y)
Return the Z depth of the single pixel at the given screen position. |
static float |
getZDepthAtOrigin()
Find the Z depth of the origin in the projected world view. |
void |
handleEvents()
Called by the run() loop. |
static void |
hideNativeCursor(boolean hide)
If param is true, make the native cursor transparent. |
void |
init()
Called only once when app is first started, init() prepares the display, mouse and OpenGL context for use. |
static boolean |
initDisplay()
Initialize the Display mode, viewport size, and open a Window. |
void |
initGL()
Initialize the OpenGL context. |
static void |
initInput()
Initialize the Keyboard and Mouse. |
void |
invoke(java.lang.reflect.Method method)
Similar to the static invoke() function, this execute a method on the GLApp class or subclass. |
static void |
invoke(java.lang.Object object,
java.lang.reflect.Method method)
Execute a method on the given object. |
static boolean |
isPowerOf2(int n)
Returns true if n is a power of 2. |
char |
keyChar()
Return the character associatated with the last key event. |
void |
keyDown(int keycode)
Called when key is pressed. |
void |
keyUp(int keycode)
Called when key is released. |
static GLImage |
loadImage(java.lang.String imgFilename)
Load an image from the given file and return a GLImage object. |
static java.nio.ByteBuffer |
loadImagePixels(java.lang.String imgFilename)
Load an image from the given file and return a ByteBuffer containing ARGB pixels. Can be used to create textures. |
static java.util.Properties |
loadPropertiesFile(java.lang.String configFilename)
Load configuration settings from a properties file. |
void |
loadSettings(java.lang.String configFilename)
Load configuration settings from optional properties file. |
static void |
lookAt(float lookatX,
float lookatY,
float lookatZ,
float distance)
A simple way to set eye position. |
static void |
main(java.lang.String[] args)
|
static GLImage |
makeImage(int w,
int h)
Make a blank image of the given size. |
static Pbuffer |
makePbuffer(int width,
int height)
Create a Pbuffer for use as an offscreen buffer, with the given width and height. |
static int |
makeTexture(java.nio.ByteBuffer pixels,
int w,
int h,
boolean anisotropic)
Create a texture from the given pixels in the default OpenGL RGBA pixel format. |
static int |
makeTexture(GLImage textureImg)
Create a texture from the given image. |
static int |
makeTexture(int w)
Create a blank square texture with the given size. |
static int |
makeTexture(int[] pixelsARGB,
int w,
int h,
boolean anisotropic)
Create a texture from the given pixels in the default Java ARGB int format. Configure the texture to repeat in both directions and use LINEAR for magnification. |
static int |
makeTexture(java.lang.String textureImagePath)
Create a texture and mipmap from the given image file. |
static int |
makeTexture(java.lang.String textureImagePath,
boolean mipmap,
boolean anisotropic)
Create a texture and optional mipmap with the given parameters. |
static int |
makeTextureARGB(java.nio.ByteBuffer pixels,
int w,
int h)
Create a texture from the given pixels in ARGB format. |
static int |
makeTextureForScreen(int screenSize)
Create a texture large enough to hold the screen image. |
static int |
makeTextureMipMap(int textureHandle,
GLImage textureImg)
Build Mipmaps for currently bound texture (builds a set of textures at various levels of detail so that texture will scale up and down gracefully) |
static java.lang.String |
makeTimestamp()
make a time stamp for filename |
static java.lang.reflect.Method |
method(java.lang.Object object,
java.lang.String methodName)
Find a method in the given class with the given method name. |
java.lang.reflect.Method |
method(java.lang.String methodName)
Similar to the static method() function, this looks for the method in the GLApp class (or it's subclass). |
boolean |
mouseButtonDown(int whichButton)
Return true if the given mousebutton is down. |
void |
mouseDown(int x,
int y)
|
void |
mouseMove(int x,
int y)
Called by handleEvents() when mouse moves |
void |
mouseUp(int x,
int y)
|
void |
mouseWheel(int wheelMoved)
|
static void |
msg(java.lang.String text)
Show a debug message on the system console (calls System.out.println()). |
static void |
popAttrib()
return to the OpenGL settings that were preserved by the previous pushAttrib() call. |
static void |
print(int x,
int y,
java.lang.String msg)
Render a text string in 2D over the scene, using the character set created by buildFont(). |
static void |
print(int x,
int y,
java.lang.String msg,
int set)
Render a text string in 2D over the scene, using the character set created by buildFont(). |
static void |
printZ(float x,
float y,
float z,
int set,
float scale,
java.lang.String msg)
Render a text string in model space, using the character set created by buildFont(). |
static void |
project(float x,
float y,
float z,
float[] resultf)
Return screen coordinates for a given point in world space. |
static void |
pushAttrib()
preserve all OpenGL settings that can be preserved. |
static void |
pushAttrib(int attribute_bits)
preserve the specified OpenGL setting. |
static void |
pushAttribOrtho()
preserve the OpenGL settings that will be affected when we draw in ortho mode over the scene. |
static void |
pushAttribViewport()
preserve the OpenGL viewport settings. |
static void |
put(java.nio.ByteBuffer b,
byte[] values)
|
static void |
put(java.nio.DoubleBuffer b,
double[] values)
|
static void |
put(java.nio.FloatBuffer b,
float[] values)
|
static void |
put(java.nio.IntBuffer b,
int[] values)
|
static float |
random()
Return a random floating point value between 0 and 1 |
static float |
random(float upperbound)
Return a random floating point value between 0 and upperbound (not including upperbound) |
static int |
random(int upperbound)
Return a random integer value between 0 and upperbound (not including upperbound) |
void |
render()
Same as draw(). |
static void |
renderCube()
Render a 2 unit cube centered at origin. |
static void |
renderCube(float size,
int segments)
draw a cube with the given size, centered at origin. |
static void |
renderPlane(float length,
float height,
int length_segments,
int height_segments)
draw a rectangular plane in the X,Y axis, centered at origin. |
static void |
renderPlane(float size,
int segments)
draw a square plane in the X,Y axis, centered at origin. |
static void |
renderSphere()
draw a sphere with 48 facets (pretty smooth) with normals and texture coords |
static void |
renderSphere(int facets)
call the LWJGL Sphere class to draw sphere geometry with texture coordinates and normals |
static void |
resetViewport()
Reset the viewport to full screen (displayWidth x displayHeight). |
static int |
round(float f)
Round a float value to the nearest int. |
void |
run()
Runs the application. |
static void |
savePixelsToPNG(java.nio.ByteBuffer framebytes,
int width,
int height,
java.lang.String imageFilename,
boolean flipY)
Save a ByteBuffer of ARGB pixels to a PNG file. |
static void |
screenShot()
Save the current frame buffer to a PNG image. |
static void |
screenShot(int x,
int y,
int width,
int height,
java.lang.String imageFilename)
Save a region of the current render buffer to a PNG image. |
static void |
screenShot(java.lang.String imageFilename)
Save the current frame buffer to a PNG image. |
static void |
screenShotRGB(int width,
int height,
java.lang.String saveFilename)
Save the contents of the current render buffer to a PNG image. |
static void |
selectDisplay()
Make the Display the current context for OpenGL commands. |
static Pbuffer |
selectPbuffer(Pbuffer pb)
Make the pbuffer the current context for opengl commands. |
static void |
setAmbientLight(float[] ambientLightColor)
Set the color of the Global Ambient Light. |
static void |
setBackgroundColor(float R,
float G,
float B)
Set the background color of the screen. |
static void |
setColor(float[] rgba)
Set the current color to the given RGB or RGBA float array. |
static void |
setColor(float R,
float G,
float B,
float A)
Set the current color with RGBA floats in range 0-1. |
static void |
setColorB(int R,
int G,
int B,
int A)
Set the current color with RGBA bytes in range 0-255. |
static void |
setColorMaterial(boolean on)
Enable/disable the color-material setting. |
static void |
setCursorPosition(int screenX,
int screenY)
Set the cursorX,cursorY position. |
static void |
setFog(boolean on)
Enable/disable fog effect. |
static void |
setFog(float[] fogColor,
float fogdensity)
Enable atmospheric fog effect, with the given color and density. |
static void |
setLight(int GLLightHandle,
boolean on)
enable/disable the given light. |
static void |
setLight(int GLLightHandle,
float[] diffuseLightColor,
float[] ambientLightColor,
float[] specularLightColor,
float[] position)
Set the color of a 'positional' light (a light that has a specific position within the scene). |
static void |
setLighting(boolean on)
Enable/disable lighting. |
static void |
setLightPosition(int GLLightHandle,
float[] position)
Set the position (or direction) of a light to the given xyz. |
static void |
setLightPosition(int GLLightHandle,
float x,
float y,
float z)
Set the position of a light to the given xyz. |
static void |
setLineWidth(int width)
Sets glLineWidth() and glPointSize() to the given width. |
static void |
setMaterial(float[] surfaceColor,
float shiny)
A simple way to set the current material properties to approximate a "real" surface. |
static void |
setMaterial(float[] diffuseColor,
float[] ambientColor,
float[] specularColor,
float[] emissiveColor,
float shininess)
Set the four material colors and calls glMaterial() to change the current material color in OpenGL. |
static void |
setMaterialAlpha(float alpha)
Alter the material opacity by setting the diffuse material color alpha value to the given value |
static void |
setOrtho()
Set OpenGL to render in flat 2D (no perspective) with a one-to-one relation between screen pixels and world coordinates, ie. |
static void |
setOrtho(int width,
int height)
|
static void |
setOrthoOff()
Turn 2D mode off. |
static void |
setOrthoOn()
Set OpenGL to render in flat 2D (no perspective) on top of current scene. |
static void |
setPerspective()
Set OpenGL to render in 3D perspective. |
void |
setRootClass()
Hold onto this Class for later class.getResource() calls (to load resources from JAR files, see getInputStream()) and also to get class name for use in screenshot filenames (see screenShot()). |
static void |
setSpotLight(int GLLightHandle,
float[] diffuseLightColor,
float[] ambientLightColor,
float[] position,
float[] direction,
float cutoffAngle)
|
void |
setup()
Setup can be overridden by the subclass to initialize the application ie load textures, models, and create data structures used by the app. |
static void |
setViewport(int x,
int y,
int width,
int height)
Define the position and size of the screen area in which the OpenGL context will draw. |
static void |
unProject(float x,
float y,
float z,
float[] resultf)
Return world coordinates for a given point on the screen. |
void |
update()
Update can be overridden by the subclass |
static void |
updateTimer()
Calculate time since we last called updateTimer(). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String GLAPP_VERSION
public static final int SIZE_DOUBLE
public static final int SIZE_FLOAT
public static final int SIZE_INT
public static final int SIZE_BYTE
public static int finishedKey
public static java.lang.String window_title
public static java.lang.String configFilename
public static boolean hideNativeCursor
public static boolean disableNativeCursor
public static boolean VSyncEnabled
public static boolean useCurrentDisplay
public static boolean fullScreen
public static boolean showMessages
public static float aspectRatio
public static int displayWidth
public static int displayHeight
public static int displayColorBits
public static int displayFrequency
public static int depthBufferBits
public static int viewportX
public static int viewportY
public static int viewportW
public static int viewportH
public static DisplayMode DM
public static DisplayMode origDM
public static DisplayMode displayMode
public static java.util.Properties settings
public static boolean finished
public static int cursorX
public static int cursorY
public static double lastFrameTime
public static double secondsSinceLastFrame
public static long ticksPerSecond
public static int frameCount
public static int screenTextureSize
public static java.nio.IntBuffer bufferViewport
public static java.nio.FloatBuffer bufferModelviewMatrix
public static java.nio.FloatBuffer bufferProjectionMatrix
public static java.nio.FloatBuffer tmpResult
public static java.nio.FloatBuffer tmpFloats
public static java.nio.ByteBuffer tmpFloat
public static java.nio.IntBuffer tmpInts
public static java.nio.ByteBuffer tmpByte
public static java.nio.ByteBuffer tmpInt
public static java.nio.FloatBuffer mtldiffuse
public static java.nio.FloatBuffer mtlambient
public static java.nio.FloatBuffer mtlspecular
public static java.nio.FloatBuffer mtlemissive
public static java.nio.FloatBuffer mtlshininess
public static float rotation
public static final float PIOVER180
public static final float PIUNDER180
public static final float[] colorClear
public static final float[] colorBlack
public static final float[] colorWhite
public static final float[] colorGray
public static final float[] colorRed
public static final float[] colorGreen
public static final float[] colorBlue
public static java.util.ArrayList displayLists
public static java.net.URL appletBaseURL
public static java.lang.Class rootClass
Constructor Detail |
---|
public GLApp()
Method Detail |
---|
public static void main(java.lang.String[] args)
public void run()
Calls init(), handleEvents(), update() and draw().
handleEvents() calls: mouseMove(), mouseDown(), mouseUp(), keyDown(), keyUp()
public void init()
public void handleEvents()
public void loadSettings(java.lang.String configFilename)
# Comment displayWidth=1024 displayHeight=768
configFilename
- public static boolean initDisplay()
public static DisplayMode getDisplayMode(int w, int h, int colorBits, int freq)
public static void initInput()
Disable or hide the native cursor. Set the initial cursor position. Get the timer resolution (ticks per second).
handleEvents()
public void initGL()
public void setup()
init()
public void update()
run()
public void draw()
public void render()
public void cleanup()
public void exit()
cleanup()
public void mouseMove(int x, int y)
public void mouseDown(int x, int y)
public void mouseUp(int x, int y)
public void mouseWheel(int wheelMoved)
public boolean mouseButtonDown(int whichButton)
whichButton
- number of mouse button (0=left button)public void keyDown(int keycode)
keycode
- class in the LWJGL documentation
public void keyUp(int keycode)
keycode
- class in the LWJGL documentation
public char keyChar()
public static java.util.Properties loadPropertiesFile(java.lang.String configFilename)
# Comment displayWidth=1024 displayHeight=768
configFilename
- public static java.lang.String getProperty(java.util.Properties props, java.lang.String propName)
public static int getPropertyInt(java.util.Properties props, java.lang.String propName)
public static float getPropertyFloat(java.util.Properties props, java.lang.String propName)
public static boolean getPropertyBool(java.util.Properties props, java.lang.String propName)
public static java.lang.String getProperty(java.lang.String propertyName)
loadSettings()
public static int getWidth()
This function is only valid after app is running and Display has been initialized.
setViewport(int,int,int,int)
public static int getHeight()
This function is only valid after app is running and Display has been initialized.
setViewport(int,int,int,int)
public static int getWidthWindow()
public static int getHeightWindow()
public static void setBackgroundColor(float R, float G, float B)
public static void disableNativeCursor(boolean off)
If the param is false, the hardware cursor will behave normally. Use hideHardwareCursor() to show or hide the hardware cursor.
hideHardwareCursor()
public static void hideNativeCursor(boolean hide)
If param is false, reset the cursor to the default.
disableHardwareCursor()
public static void setCursorPosition(int screenX, int screenY)
screenX
- screenY
- public static int getSettingInt(int whichSetting)
whichSetting
- the id number of the value to be returned (same constants as for glGetInteger())public static java.nio.FloatBuffer getModelviewMatrix()
public static java.nio.FloatBuffer getProjectionMatrix()
public static java.nio.IntBuffer getViewport()
public static float[][] getMatrixAsArray(java.nio.FloatBuffer fb)
fb
- FloatBuffer containing 16 values of 4x4 matrix
public static float getZDepth(int x, int y)
public static float getZDepthAtOrigin()
public static void project(float x, float y, float z, float[] resultf)
x
- world coordinatesy
- z
- resultf
- the screen coordinate as an array of 3 floatspublic static void unProject(float x, float y, float z, float[] resultf)
x
- screen x positiony
- screen y positionz
- z-buffer depth positionresultf
- the world coordinate as an array of 3 floatsgetWorldCoordsAtScreen()
public static float[] getWorldCoordsAtScreen(int x, int y)
public static float[] getWorldCoordsAtScreen(int x, int y, float z)
public static int allocateTexture()
public static void activateTexture(int textureHandle)
public static int makeTexture(java.lang.String textureImagePath)
public static int makeTexture(java.lang.String textureImagePath, boolean mipmap, boolean anisotropic)
mipmap:
- if true, create mipmaps for the textureanisotropic:
- if true, enable anisotropic filteringpublic static int makeTexture(GLImage textureImg)
public static void deleteTexture(int textureHandle)
public static boolean isPowerOf2(int n)
public static int makeTexture(int w)
public static int makeTexture(int[] pixelsARGB, int w, int h, boolean anisotropic)
public static int makeTexture(java.nio.ByteBuffer pixels, int w, int h, boolean anisotropic)
public static int makeTextureARGB(java.nio.ByteBuffer pixels, int w, int h)
Configure the texture to repeat in both directions and use LINEAR for magnification.
NOTE: I'm having problems creating mipmaps when image pixel data is in GL_BGRA format. Looks like GLU type param doesn't recognize GL_UNSIGNED_INT_8_8_8_8 and GL_UNSIGNED_INT_8_8_8_8_REV so I can't specify endian byte order. Mipmaps look right on PC but colors are reversed on Mac. Have to stick with GL_RGBA byte order for now.
public static int makeTextureMipMap(int textureHandle, GLImage textureImg)
textureImg
- the texture image
public static int makeTextureForScreen(int screenSize)
frameCopy()
,
frameDraw()
public static int getPowerOfTwoBiggerThan(int n)
dimension
-
makeTextureForScreen()
public static void copyPixelsToTexture(java.nio.ByteBuffer bb, int w, int h, int textureHandle)
bb
- ByteBuffer of pixels stored as ARGB or BGRA integersw
- width of source imageh
- height of source imagetextureHandle
- texture to copy pixels intopublic static void copyImageToTexture(GLImage img, int textureHandle)
public static void setPerspective()
public static void setOrtho()
ABOUT Ortho and Viewport:
Let's say we're drawing in 2D and want to have a cinema proportioned
viewport (16x9), and want to bound our 2D rendering into that area ie.
___________1024,576 | | | Scene | Set the bounds on the scene geometry |___________| to the viewport size and shape 0,0 ___________1024,576 | | | Ortho | Set the projection to cover the same |___________| area as the scene 0,0 ___________ 1024,768 |___________| | |1024,672 | Viewport | Set the viewport to the same shape 0,96|___________| as scene and ortho, but centered on |___________| screen. 0,0
public static void setOrtho(int width, int height)
public static void setOrthoOn()
NOTE: if the viewport is the same size as the window (by default it is), then setOrtho() will make the world coordinates exactly match the screen pixel positions. This is convenient for mouse interaction, but be warned: if you setViewport() to something other than fullscreen, then you need to use getWorldCoordsAtScreen() to convert screen xy to world xy.
Once Ortho is on, glTranslate() will take pixel coords as arguments, with the lower left corner 0,0 and the upper right corner 1024,768 (or whatever your screen size is). !!!
setOrthoOff()
,
setViewport(int,int,int,int)
public static void setOrthoOff()
setOrthoOn()
public static void setViewport(int x, int y, int width, int height)
NOTE: by default the window size, viewport size and setOrtho() size are all the same, so in ortho mode screen pixel positions exactly match to world coordinates. THIS IS NO LONGER TRUE if you setViewport() to some other size. With a custom viewport you need to use getWorldCoordsAtScreen() to convert screen xy to world xy.
x
- position of the lower left of viewport area, in pixelsy
- width
- size of the viewport area, in pixelsheight
- setPerspective()
,
setOrtho()
,
setOrthoDimensions(int,int)
public static void resetViewport()
setViewport(int,int,int,int)
public static void lookAt(float lookatX, float lookatY, float lookatZ, float distance)
public static void pushAttrib()
popAttrib()
public static void pushAttrib(int attribute_bits)
popAttrib()
public static void pushAttribOrtho()
call pushAttribOverlay(), enable settings that you need, when done call popAttrib()
popAttrib()
public static void pushAttribViewport()
pushAttribViewport(); setViewport(0,0,displaymode.getWidth(),displaymode.getHeight()); ... do some drawing outside of previous viewport area popAttrib();
popAttrib()
public static void popAttrib()
pushAttrib()
public static void setLight(int GLLightHandle, float[] diffuseLightColor, float[] ambientLightColor, float[] specularLightColor, float[] position)
GLLightHandle
- diffuseLightColor
- ambientLightColor
- position
- public static void setSpotLight(int GLLightHandle, float[] diffuseLightColor, float[] ambientLightColor, float[] position, float[] direction, float cutoffAngle)
public static void setAmbientLight(float[] ambientLightColor)
public static void setLightPosition(int GLLightHandle, float x, float y, float z)
public static void setLightPosition(int GLLightHandle, float[] position)
public static void setLight(int GLLightHandle, boolean on)
public static void setLighting(boolean on)
public static void setMaterial(float[] surfaceColor, float shiny)
Sets diffuse material color to the surfaceColor and ambient material color to surfaceColor/2. Based on the shiny value (0-1), sets the specular property to a color between black (0) and white (1), and sets the shininess property to a value between 0 and 127.
Lighting must be enabled for material colors to take effect.
surfaceColor
- - must be float[4] {R,G,B,A}reflection
- - a float from 0-1 (0=very matte, 1=very shiny)public static void setMaterial(float[] diffuseColor, float[] ambientColor, float[] specularColor, float[] emissiveColor, float shininess)
shininess:
- size of reflection (0 is matte, 127 is pinpoint reflection)public static void setMaterialAlpha(float alpha)
public static void applyMaterial()
public static void setFog(float[] fogColor, float fogdensity)
setFog(new float[] {.5f,.5f,.5f,1f}, .3f);
fogColor
- float[4] specifies the RGB fog color valuefogDensity
- float in range 0-1 specifies how opaque the fog will bepublic static void setFog(boolean on)
public static double getTimeInSeconds()
public static double getTimeInMillis()
public static void updateTimer()
Called by run() at the beginning of each loop.
run()
,
getSecondsPerFrame()
public static double getSecondsPerFrame()
updateTimer()
public static double getFramesPerSecond()
updateTimer()
public static GLImage makeImage(int w, int h)
public static GLImage loadImage(java.lang.String imgFilename)
image
- filename
public static java.nio.ByteBuffer loadImagePixels(java.lang.String imgFilename)
imgFilename
-
public static void drawCursor(int cursorTextureHandle)
NOTE: the cursor is drawn in screen space, at an absolute screen pixel location without regard for viewport (temporarily zets viewport to entire screen).
See handleEvents() for cursorX cursorY and mouse motion handling.
Example:
int cursorTxtr; public void setup() { cursorTxtr = makeTexture("images/cursorCrosshair32.gif"); // image must be 32x32 } public void draw() { // render scene ... drawCursor(cursorTxtr); }
cursorTextureHandle
- handle to texture containing 32x32 cursor imagepublic static void drawCursorOLD(int cursorTextureHandle)
See handleEvents() for cursorX cursorY and mouse motion handling.
Example:
int cursorTxtr; public void setup() { cursorTxtr = makeTexture("images/cursorCrosshair32.gif"); // image must be 32x32 } public void draw() { // render scene ... drawCursor(cursorTxtr); }
cursorTextureHandle
- handle to texture containing 32x32 cursor imagepublic static void drawImageFullScreen(GLImage img)
NOTE: By default the viewport is the same size as the window so this function will draw the image over the entire window. If you setViewport() to a custom size the image will be drawn into the custom viewport area. To insure that the image is drawn truly full screen, call resetViewport() before drawImageFullScreen().
loadImage(String)
,
setViewport(int,int,int,int)
,
resetViewport()
public static void drawImage(GLImage img, int x, int y, float w, float h)
loadImage()
,
drawQuad()
,
drawImageFullScreen()
public static void drawQuad(int textureHandle, int x, int y, float w, float h)
public static void drawQuadZ(int textureHandle, float x, float y, float z, float w, float h)
public static java.nio.ByteBuffer framePixels()
public static java.nio.ByteBuffer framePixels(int x, int y, int w, int h)
public static int[] framePixelsInt(int x, int y, int w, int h)
public static byte[] getPixelColor(int x, int y)
x
- screen positiony
-
public static float getPixelDepth(int x, int y)
x
- screen positiony
-
public static int getPixelStencil(int x, int y)
x
- screen positiony
-
public static void frameCopy(int txtrHandle)
txtrHandle
- texture where screen image will be storedframeDraw()
,
makeTextureForScreen()
public static void frameCopy(int txtrHandle, int x, int y, int w, int h)
txtrHandle
- texture where screen region will be storedframeDraw()
,
makeTextureForScreen()
public static void frameDraw(int txtrHandle)
Reset the viewport and ortho mode to full screen (viewport may be different proportion than screen if custom aspectRatio is set). Draw the quad the same size as texture so no stretching or compression of image.
txtrHandle
- public static void frameSave()
screenShot()
public static void drawRect(int x, int y, float w, float h)
setLineWidth()
,
drawRectZ()
public static void drawRectZ(int x, int y, int z, float w, float h)
setLineWidth()
,
drawRect()
public static void drawCircle(int x, int y, int radius, int linewidth)
public static void drawCircleZ(int x, int y, int z, int radius, int linewidth)
public static void drawCircle(float innerRadius, float outerRadius, int numSegments)
public static void renderCube()
public static void renderCube(float size, int segments)
size
- length of each sidesegments
- # segments to divide each side intopublic static void renderPlane(float size, int segments)
size
- length of each sidesegments
- number of segments to divide each side intopublic static void renderPlane(float length, float height, int length_segments, int height_segments)
length
- length on X axisdepth
- length on Y axissegments
- number of segments to divide each side intopublic static void renderSphere(int facets)
facets
- number of divisions around longitude and latitudepublic static void renderSphere()
public static void setLineWidth(int width)
public static void setColor(float R, float G, float B, float A)
public static void setColorB(int R, int G, int B, int A)
public static void setColor(float[] rgba)
public static void setColorMaterial(boolean on)
on
- when true, glColor() will set the current material colorpublic static boolean buildFont(java.lang.String charSetImage, int fontWidth)
charSetImage
- texture image containing 256 characters in a 16x16 gridfontWidth
- how many pixels to allow per character on screendestroyFont()
public static void buildFont(int fontTxtrHandle, int fontWidth)
charSetImage
- texture image containing 256 characters in a 16x16 gridfontWidth
- how many pixels to allow per character on screendestroyFont()
public static void destroyFont()
public static void print(int x, int y, java.lang.String msg)
x
- screen pixel position of the stringy
- msg
- text string to drawpublic static void print(int x, int y, java.lang.String msg, int set)
x
- screen pixel position of the stringy
- msg
- text string to drawset
- which of the two character sets: 0 or 1public static void printZ(float x, float y, float z, int set, float scale, java.lang.String msg)
public static Pbuffer makePbuffer(int width, int height)
width
- height
-
selectPbuffer(), selectDisplay()
public static Pbuffer selectPbuffer(Pbuffer pb)
NOTE: the Pbuffer may be recreated if it was lost since last used. It's a good idea to use:
pbuff = selectPbuffer(pbuff);to hold onto the new Pbuffer reference if Pbuffer was recreated.
pb
- pbuffer to make current
selectDisplay(), makePbuffer()
public static void selectDisplay()
selectPbuffer()
public static void frameCopy(Pbuffer pbuff, int textureHandle)
public static void screenShot()
public static void screenShot(java.lang.String imageFilename)
public static void screenShot(int x, int y, int width, int height, java.lang.String imageFilename)
WARNING: this function hogs memory! Call java with more memory (java -Xms128m -Xmx128m)
selectPbuffer(Pbuffer)
,
selectDisplay()
,
savePixelsToPNG()
public static void savePixelsToPNG(java.nio.ByteBuffer framebytes, int width, int height, java.lang.String imageFilename, boolean flipY)
public static void screenShotRGB(int width, int height, java.lang.String saveFilename)
If the current buffer is the framebuffer then this will work as a screen capture. Can also be used with the PBuffer class to copy large images or textures that have been rendered into the offscreen pbuffer.
WARNING: this function hogs memory! Call java with more memory (java -Xms128m -Xmx128)
selectPbuffer(), selectDisplay()
public static void clearMask()
public static void beginMask(int maskvalue)
public static void endMask()
public static void activateMask(int maskvalue)
public static void disableMask()
public static int getMaskValue(int x, int y)
public static int beginDisplayList()
To use, create a display list in setup():
int teapotID = beginDisplayList(); ... // run teapot render code here endDisplayList();Then call the display list later in render():
callDisplayList(teapotID);
endDisplayList(), callDisplayList(), destroyDisplayList()
public static void endDisplayList()
beginDisplayList()
public static void callDisplayList(int displayListID)
beginDisplayList()
,
endDisplayList()
public static void destroyDisplayList(int DL_ID)
public static void destroyDisplayLists()
cleanUp();
public static java.nio.ByteBuffer allocBytes(int howmany)
public static java.nio.IntBuffer allocInts(int howmany)
public static java.nio.FloatBuffer allocFloats(int howmany)
public static java.nio.DoubleBuffer allocDoubles(int howmany)
public static java.nio.ByteBuffer allocBytes(byte[] bytearray)
public static java.nio.IntBuffer allocInts(int[] intarray)
public static java.nio.FloatBuffer allocFloats(float[] floatarray)
public static java.nio.DoubleBuffer allocDoubles(double[] darray)
public static void put(java.nio.ByteBuffer b, byte[] values)
public static void put(java.nio.IntBuffer b, int[] values)
public static void put(java.nio.FloatBuffer b, float[] values)
public static void put(java.nio.DoubleBuffer b, double[] values)
public static void get(java.nio.ByteBuffer b, int[] values)
b
- source ByteBuffervalues
- target integer array, must be same length as ByteBuffer capacity/4public static void get(java.nio.IntBuffer b, int[] values)
b
- source IntBuffervalues
- target integer array, must be same length as IntBufferpublic static int[] getInts(java.nio.ByteBuffer b)
b
- source ByteBufferpublic static java.io.InputStream getInputStream(java.lang.String filename)
filename
- to openpublic static byte[] getBytesFromStream(java.io.InputStream is)
public static byte[] getBytesFromFile(java.lang.String filename)
public static java.lang.String[] getPathAndFile(java.lang.String filename)
public void setRootClass()
To load files from a jar we need to access a class in the root folder of the installation. It's not good to use GLApp.class because that class is in the glapp package folder, and the getResource() function will not find model, image and sound files because they're a level higher in the folder tree. Below we call this.getClass() to record the class of the application that subclasses GLApp, ie. assume we create an app MyGame that extends GLApp, and MyGame.class is in the root folder of the installation:
MyGame.class models (folder) images (folder) sounds (folder)In this case setRootClass() will set the rootClass to MyGame. If MyGame and subfolders are packaged in a jar file, then getInputStream() should be able to do a rootClass.getResource("models/some_model.obj") and correctly retrieve the file from the JAR.
getInputStream()
public static java.lang.String makeTimestamp()
public static float random()
public static float random(float upperbound)
public static int random(int upperbound)
public static int round(float f)
public static boolean extensionExists(java.lang.String extensionName)
public static void msg(java.lang.String text)
text
- public static void err(java.lang.String text)
text
- public static java.lang.reflect.Method method(java.lang.Object object, java.lang.String methodName)
NOTE: method invocation is very fast for methods that take no parameters. If the method takes parameters then invoking is much slower than calling the function directly through code. For this reason and for simplicity I assume there are no parameters on the function.
object
- object that has the method we want to invokemethodName
- name of function that we want to invoke
invoke()
public java.lang.reflect.Method method(java.lang.String methodName)
methodName
- name of function that we want to invoke
invoke()
public static void invoke(java.lang.Object object, java.lang.reflect.Method method)
object
- (the object to call the method on)method
- (the method that will be executed)method()
public void invoke(java.lang.reflect.Method method)
method
- (the method that will be executed)method()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |