/** * Loads the fragment program into a byte array. * * @see com.jme.scene.state.FragmentProgramState#load(java.net.URL) */ public void load(String programContents) { try { byte[] bytes = programContents.getBytes(); program = BufferUtils.createByteBuffer(bytes.length); program.put(bytes); program.rewind(); programID = -1; setNeedsRefresh(true); } catch (Exception e) { logger.severe("Could not load fragment program: " + e); logger.logp(Level.SEVERE, getClass().getName(), "load(URL)", "Exception", e); } }
/** * Update variableID for attribute shadervariable if needed. * * @param variable shadervaribale to update ID on * @param programID shader program context ID */ public static void updateAttributeLocation(ShaderVariable variable, int programID) { if (variable.variableID == -1) { ByteBuffer nameBuf = BufferUtils.createByteBuffer(variable.name.getBytes().length + 1); nameBuf.clear(); nameBuf.put(variable.name.getBytes()); nameBuf.rewind(); variable.variableID = ARBVertexShader.glGetAttribLocationARB(programID, nameBuf); if (variable.variableID == -1) { logger.severe("Shader attribute [" + variable.name + "] could not be located in shader"); } } }
/** * Update variableID for uniform shadervariable if needed. * * @param variable shadervaribale to update ID on * @param programID shader program context ID */ public static void updateUniformLocation(ShaderVariable variable, int programID) { if (variable.variableID == -1) { ByteBuffer nameBuf = BufferUtils.createByteBuffer(variable.name.getBytes().length + 1); nameBuf.clear(); nameBuf.put(variable.name.getBytes()); nameBuf.rewind(); variable.variableID = ARBShaderObjects.glGetUniformLocationARB(programID, nameBuf); if (variable.variableID == -1) { logger.severe("Shader uniform [" + variable.name + "] could not be located in shader"); } } }
/** * <code>print</code> renders the specified string to a given (x,y) location. The x, y location is * in terms of screen coordinates. There are currently two sets of fonts supported: NORMAL and * ITALICS. * * @param r * @param x the x screen location to start the string render. * @param y the y screen location to start the string render. * @param text the String to render. * @param set the mode of font: NORMAL or ITALICS. */ public void print(Renderer r, float x, float y, Vector3f scale, StringBuffer text, int set) { RendererRecord matRecord = (RendererRecord) DisplaySystem.getDisplaySystem().getCurrentContext().getRendererRecord(); if (set > 1) { set = 1; } else if (set < 0) { set = 0; } boolean alreadyOrtho = r.isInOrthoMode(); if (!alreadyOrtho) r.setOrtho(); else { matRecord.switchMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); } GL11.glTranslatef(x, y, 0); GL11.glScalef(scale.x, scale.y, scale.z); GL11.glListBase(base - 32 + (128 * set)); // Put the string into a "pointer" if (text.length() > scratch.capacity()) { scratch = BufferUtils.createByteBuffer(text.length()); } else { scratch.clear(); } int charLen = text.length(); for (int z = 0; z < charLen; z++) scratch.put((byte) text.charAt(z)); scratch.flip(); matRecord.setCurrentColor(fontColor); // call the list for each letter in the string. GL11.glCallLists(scratch); // set color back to white matRecord.setCurrentColor(1, 1, 1, 1); if (!alreadyOrtho) { r.unsetOrtho(); } else { matRecord.switchMode(GL11.GL_MODELVIEW); GL11.glPopMatrix(); } }
/** * Loads the fragment program into a byte array. * * @see com.jme.scene.state.FragmentProgramState#load(java.net.URL) */ public void load(java.net.URL file) { InputStream inputStream = null; try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(16 * 1024); inputStream = new BufferedInputStream(file.openStream()); byte[] buffer = new byte[1024]; int byteCount = -1; // Read the byte content into the output stream first while ((byteCount = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, byteCount); } // Set data with byte content from stream byte data[] = outputStream.toByteArray(); // Release resources inputStream.close(); outputStream.close(); program = BufferUtils.createByteBuffer(data.length); program.put(data); program.rewind(); programID = -1; setNeedsRefresh(true); } catch (Exception e) { logger.severe("Could not load fragment program: " + e); logger.logp(Level.SEVERE, getClass().getName(), "load(URL)", "Exception", e); } finally { // Ensure that the stream is closed, even if there is an exception. if (inputStream != null) { try { inputStream.close(); } catch (IOException closeFailure) { logger.log(Level.WARNING, "Failed to close the fragment program", closeFailure); } } } }
/** * Constructor instantiates a new <code>LWJGLFont</code> object. The initial color is set to * white. */ public LWJGLFont() { fontColor = new ColorRGBA(1, 1, 1, 1); scratch = BufferUtils.createByteBuffer(1); buildDisplayList(); }