@Override protected void init() { initializeProgram(); try { cylinderMesh = new Mesh("UnitCylinder.xml"); planeMesh = new Mesh("LargePlane.xml"); } catch (Exception exception) { exception.printStackTrace(); System.exit(-1); } glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); glDepthMask(true); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); glEnable(GL_DEPTH_CLAMP); projectionUniformBuffer = glGenBuffers(); glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer); glBufferData(GL_UNIFORM_BUFFER, ProjectionBlock.SIZE, GL_DYNAMIC_DRAW); // Bind the static buffers. glBindBufferRange( GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, ProjectionBlock.SIZE); glBindBuffer(GL_UNIFORM_BUFFER, 0); }
@Override public void click(Point p) { checked = !checked; try { if (call != null) call.click(this); } catch (Exception ex) { ex.printStackTrace(); } }
public TextureTest() { try { FileInputStream s = new FileInputStream("textures/texture1.png"); t = TextureLoader.getTexture("PNG", s); } catch (Exception e) { e.printStackTrace(); } }
private static TextureResource loadTexture(String fileName) { String[] splitArray = fileName.split("\\."); String ext = splitArray[splitArray.length - 1]; try { BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName)); int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()); ByteBuffer buffer = Util.createByteBuffer(image.getHeight() * image.getWidth() * 4); boolean hasAlpha = image.getColorModel().hasAlpha(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int pixel = pixels[y * image.getWidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); buffer.put((byte) ((pixel >> 8) & 0xFF)); buffer.put((byte) ((pixel) & 0xFF)); if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF)); else buffer.put((byte) (0xFF)); } } buffer.flip(); TextureResource resource = new TextureResource(); glBindTexture(GL_TEXTURE_2D, resource.getId()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); return resource; } catch (Exception e) { e.printStackTrace(); System.exit(1); } return null; }
@Override protected void init() { initializePrograms(); try { realHallway = new Mesh("RealHallway.xml"); fauxHallway = new Mesh("FauxHallway.xml"); } catch (Exception exception) { exception.printStackTrace(); System.exit(-1); } }
/** * Application init * * @param args Commandline args */ public static void main(String[] args) { try { init(false); run(); } catch (Exception e) { e.printStackTrace(System.err); Sys.alert(GAME_TITLE, "An error occured and the game will exit."); } finally { cleanup(); } System.exit(0); }
public static void init(int w, int h) { try { initGL(); initWindow(w, h); initShader(); // initTexture(); // initModel(); loadGraphicData("data/graphic.data"); // camera.setCameraBound(20.0f, -1.0f, -10f, 10f); } catch (Exception e) { e.printStackTrace(); } }
@Override protected void init() { glClearColor(0, 0, 0, 0); glPixelZoom(1, -1); try { for (int i = 0; i < fonts.length; ++i) { fonts[i] = new Font(new File(FONT_NAMES[i]), FONT_MAPS[i], width, height); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
public void Load() { mCamera = new Camera(GetGameWindow()); Light.Load(mGameWindow.Width(), mGameWindow.Height()); ComplexPolygon.Load(mGameWindow.Width(), mGameWindow.Height()); mShadowMask = new Texture(mGameWindow.Width(), mGameWindow.Height()); try { mShadowMaskObject = new FrameBufferObject(mShadowMask); } catch (Exception e) { e.printStackTrace(); } mCamera.ForceScaleFocus((mGameWindow.Width() / 1600.0f + mGameWindow.Height() / 900.0f) / 2); mAmbientLighting = 0.0f; }
private int load(String path) { int[] pixels = null; try { BufferedImage image = ImageIO.read(new FileInputStream(path)); width = image.getWidth(); height = image.getHeight(); pixels = new int[width * height]; image.getRGB(0, 0, width, height, pixels, 0, width); } catch (Exception e) { e.printStackTrace(); } int[] data = new int[width * height]; for (int i = 0; i < width * height; i++) { int a = (pixels[i] & 0xff000000) >> 24; int r = (pixels[i] & 0xff0000) >> 16; int g = (pixels[i] & 0xff00) >> 8; int b = (pixels[i] & 0xff); data[i] = a << 24 | b << 16 | g << 8 | r; } int result = glGenTextures(); glBindTexture(GL_TEXTURE_2D, result); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, BufferUtils.createIntBuffer(data)); glBindTexture(GL_TEXTURE_2D, 0); return result; }
void renderLoop() { long startTime = System.currentTimeMillis() + 5000; long fps = 0; while (glfwWindowShouldClose(window.handle) == GLFW_FALSE) { Runnable event; while ((event = events.poll()) != null) event.run(); try { display(); } catch (Exception e) { e.printStackTrace(); break; } glfwSwapBuffers(window.handle); if (startTime > System.currentTimeMillis()) { fps++; } else { long timeUsed = 5000 + (startTime - System.currentTimeMillis()); startTime = System.currentTimeMillis() + 5000; log( String.format( "%s: %d frames in 5 seconds = %.2f", getPlatformInfoStringUTF8(platform, CL_PLATFORM_VENDOR), fps, fps / (timeUsed / 1000f))); fps = 0; } } cleanup(); window.signal.countDown(); }
public void addTexture(BufferedImage img, Vector2f[] v) { subimages.add(img); coordinates.add(v[0]); coordinates.add(v[1]); coordinates.add(v[2]); Vector2f drawloc = new Vector2f(); for (boolean done = false; !done; ) { try { drawloc = tg.nearestSpace(img); done = true; } catch (Exception e) { if (e.getLocalizedMessage() == "enlarge") { atlas = new BufferedImage( atlas.getWidth() * 2, atlas.getHeight() * 2, BufferedImage.TYPE_INT_ARGB); tg.enlarge(atlas); for (int i = 0; i < drawingcoords.size(); i++) { tg.useup(drawingcoords.get(i), subimages.get(i)); } } } } drawingcoords.add(drawloc); atlasgraphics = atlas.getGraphics(); atlasgraphics.setColor(new Color(0.0f, 0.0f, 0.0f, 0.0f)); atlasgraphics.fillRect(0, 0, atlas.getWidth(), atlas.getHeight()); for (int i = 0; i < drawingcoords.size(); i++) { atlasgraphics.drawImage( (Image) subimages.get(i), (int) drawingcoords.get(i).x, (int) drawingcoords.get(i).y, null); } realtexcoods.clear(); for (int i = 0; i < subimages.size(); i++) { Vector2f vec = new Vector2f(); vec = converttoimagesizes( coordinates.get(i * 3), drawingcoords.get(i), subimages.get(i), atlas); realtexcoods.add(vec); vec = converttoimagesizes( coordinates.get((i * 3) + 1), drawingcoords.get(i), subimages.get(i), atlas); realtexcoods.add(vec); vec = converttoimagesizes( coordinates.get((i * 3) + 2), drawingcoords.get(i), subimages.get(i), atlas); realtexcoods.add(vec); } tg.useup(drawloc, img); TextureUtils util = new TextureUtils(); util.binddata(atlas, texID); // File outputfile = new File("saved @ " + this.hashCode() + ".png"); // try { // ImageIO.write(atlas, "png", outputfile); // } catch (IOException e) { // e.printStackTrace(); // } }
@Override protected void onStart() { INSTANCE = this; RENDER_THREAD_ID = Thread.currentThread().getId(); try { loadIcons(); Display.setIcon(icons); Display.setVSyncEnabled(GameSettings.Graphics.vsync); } catch (IOException e) { e.printStackTrace(); } try { setDisplayMode( GameSettings.Display.window_width, GameSettings.Display.window_height, GameSettings.Display.fullscreen); Display.create(); // ROBO //todo get all this changed to proper OGL glClearColor(0f, 0f, 0f, 1f); glClearDepth(1f); glViewport(0, 0, GameSettings.Display.window_width, GameSettings.Display.window_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0.0f, GameSettings.Display.resolution.getWidth(), GameSettings.Display.resolution.getHeight(), 0.0f, 0.1f, -1f); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glLoadIdentity(); curAlpha = 1f; capabilities = GLContext.getCapabilities(); System.out.println("OpenGL version: " + glGetString(GL_VERSION)); System.out.println("Building shaders.."); long ms = getTime(); ShaderFactory.buildAllShaders(); System.out.println("Done! Took " + (getTime() - ms) + "ms."); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(0); } finally { if (looping) { looping = false; Display.destroy(); } } started = getTime(); next_tick = getTime(); getDelta(); }