Java Code Examples for org.lwjgl.opengl.Display#create()
The following examples show how to use
org.lwjgl.opengl.Display#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LwJglRenderingEngine.java From Gaalop with GNU Lesser General Public License v3.0 | 7 votes |
/** * Starts the lwjgl engine and shows a window, where the point clouds are rendered */ public void startEngine() { int width = 800; int height = 600; try { Display.setDisplayMode(new DisplayMode(width, height)); Display.setFullscreen(false); Display.setTitle("Gaalop Visualization Window"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glShadeModel(GL11.GL_SMOOTH); changeSize(width, height); GL11.glDisable(GL11.GL_LIGHTING); // init OpenGL GL11.glViewport(0, 0, width, height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GLU.gluPerspective((float) 65.0, (float) width / (float) height, (float) 0.1, 100); GL11.glMatrixMode(GL11.GL_MODELVIEW); }
Example 2
Source File: Window.java From LowPolyWater with The Unlicense | 6 votes |
protected Window(Context context, WindowBuilder settings) { this.fpsCap = settings.getFpsCap(); try { getSuitableFullScreenModes(); DisplayMode resolution = getStartResolution(settings); Display.setInitialBackground(1, 1, 1); this.aspectRatio = (float) resolution.getWidth() / resolution.getHeight(); setResolution(resolution, settings.isFullScreen()); if (settings.hasIcon()) { Display.setIcon(settings.getIcon()); } Display.setVSyncEnabled(settings.isvSync()); Display.setTitle(settings.getTitle()); Display.create(new PixelFormat().withDepthBits(24).withSamples(4), context.getAttribs()); GL11.glViewport(0, 0, resolution.getWidth(), resolution.getHeight()); } catch (LWJGLException e) { e.printStackTrace(); } }
Example 3
Source File: SerializableDisplayMode.java From tribaltrouble with GNU General Public License v2.0 | 6 votes |
private final static void createWindow() throws LWJGLException { int[] depth_array = new int[]{24, 16}; int[] samples_array = new int[]{/*Settings.getSettings().samples, */0}; LWJGLException last_exception = new LWJGLException("Could not find a suitable pixel format"); for (int d = 0; d < depth_array.length; d++) for (int s = 0; s < samples_array.length; s++) { int depth = depth_array[d]; int samples = samples_array[s]; try { Display.create(new PixelFormat(0, depth, 0, samples)); return; } catch (LWJGLException e) { last_exception = e; System.out.println("Failed window: depthbits = " + depth + " | samples = " + samples + " with exception " + e); } } throw last_exception; }
Example 4
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 6 votes |
private void setupOpenGL() { // Setup an OpenGL context with API version 3.2 try { PixelFormat pixelFormat = new PixelFormat(); ContextAttribs contextAtrributes = new ContextAttribs(3, 2) .withForwardCompatible(true) .withProfileCore(true); Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.setTitle(WINDOW_TITLE); Display.create(pixelFormat, contextAtrributes); GL11.glViewport(0, 0, WIDTH, HEIGHT); } catch (LWJGLException e) { e.printStackTrace(); System.exit(-1); } // Setup an XNA like background color GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f); // Map the internal OpenGL coordinate system to the entire screen GL11.glViewport(0, 0, WIDTH, HEIGHT); this.exitOnGLError("setupOpenGL"); }
Example 5
Source File: DisplayManager.java From OpenGL-Animation with The Unlicense | 6 votes |
public static void createDisplay() { try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true); Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs); Display.setTitle(TITLE); Display.setInitialBackground(1, 1, 1); GL11.glEnable(GL13.GL_MULTISAMPLE); } catch (LWJGLException e) { e.printStackTrace(); System.err.println("Couldn't create display!"); System.exit(-1); } GL11.glViewport(0, 0, WIDTH, HEIGHT); lastFrameTime = getCurrentTime(); }
Example 6
Source File: LwjglGraphicsModule.java From tprogers2048game with GNU General Public License v3.0 | 5 votes |
private void initOpengl() { try { /* Задаём размер будущего окна */ Display.setDisplayMode(new DisplayMode(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT)); /* Задаём имя будущего окна */ Display.setTitle(Constants.SCREEN_NAME); /* Создаём окно */ Display.create(); } catch (LWJGLException e) { ErrorCatcher.graphicsFailure(e); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, Constants.SCREEN_WIDTH,0, Constants.SCREEN_HEIGHT,1,-1); glMatrixMode(GL_MODELVIEW); /* Для поддержки текстур */ glEnable(GL_TEXTURE_2D); /* Для поддержки прозрачности */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* Белый фоновый цвет */ glClearColor(1,1,1,1); }
Example 7
Source File: TwlTest.java From tablelayout with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main (String[] args) throws Exception { System.setProperty("org.lwjgl.librarypath", new File("lib/natives").getAbsolutePath()); Display.setTitle("TWL Examples"); Display.setDisplayMode(new DisplayMode(800, 600)); Display.setVSyncEnabled(true); Display.create(); new TwlTest(); }
Example 8
Source File: DisplayManager.java From OpenGL-Tutorial-1 with The Unlicense | 5 votes |
/** * Creates a display window on which we can render our game. The dimensions * of the window are determined by setting the display mode. By using * "glViewport" we tell OpenGL which part of the window we want to render * our game onto. We indicated that we want to use the entire window. */ public static void createDisplay() { ContextAttribs attribs = new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true); try { Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.create(new PixelFormat(), attribs); Display.setTitle(TITLE); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glViewport(0, 0, WIDTH, HEIGHT); }
Example 9
Source File: GLProgram.java From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initializes the context with its attributes and PixelFormat supplied. * * This method does not return until the game loop ends. * * @param format The PixelFormat specifying the buffers. * @param attribs The context attributes. */ public final void run(PixelFormat format, ContextAttribs attribs) { try { Display.create(format, attribs); } catch(Exception exc) { exc.printStackTrace(); System.exit(1); } gameLoop(); }
Example 10
Source File: Game.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public void init(int width, int height, String name) { time = System.nanoTime(); windowWidth = width*scaleX; windowHeight = height*scaleY; try { Display.setDisplayMode(new DisplayMode(windowWidth, windowHeight)); Display.create(); Display.setTitle(name); Keyboard.create(); Keyboard.enableRepeatEvents(true); Mouse.create(); glContextExists = true; } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } //init OpenGL glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.01f); glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glViewport(0, 0, windowWidth, windowHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, windowWidth/scaleX, windowHeight/scaleY, 0, 1, -1); //It's basically a camera glMatrixMode(GL_MODELVIEW); keys = new ArrayList<KeyboardEvent>(); mouseEvents = new ArrayList<MouseEvent>(); }
Example 11
Source File: Window.java From 3DGameEngine with Apache License 2.0 | 5 votes |
public static void CreateWindow(int width, int height, String title) { Display.setTitle(title); try { Display.setDisplayMode(new DisplayMode(width, height)); Display.create(); Keyboard.create(); Mouse.create(); } catch (LWJGLException e) { e.printStackTrace(); } }
Example 12
Source File: AppletGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create the LWJGL display * * @throws Exception Failure to create display */ private void createDisplay() throws Exception { try { // create display with alpha Display.create(new PixelFormat(8,8,GameContainer.stencil ? 8 : 0)); alphaSupport = true; } catch (Exception e) { // if we couldn't get alpha, let us know alphaSupport = false; Display.destroy(); // create display without alpha Display.create(); } }
Example 13
Source File: AppGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Try creating a display with the given format * * @param format The format to attempt * @throws LWJGLException Indicates a failure to support the given format */ private void tryCreateDisplay(PixelFormat format) throws LWJGLException { if (SHARED_DRAWABLE == null) { Display.create(format); } else { Display.create(format, SHARED_DRAWABLE); } }
Example 14
Source File: TestUtils.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initialise the GL display * * @param width The width of the display * @param height The height of the display */ private void initGL(int width, int height) { try { Display.setDisplayMode(new DisplayMode(width,height)); Display.create(); Display.setVSyncEnabled(true); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0,0,width,height); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, width, height, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); }
Example 15
Source File: ModelViewer.java From OpenRS with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Usage: modelfile"); System.exit(1); } ModelList list = new ModelList(); try (Cache cache = new Cache(FileStore.open(Constants.CACHE_PATH))) { list.initialize(cache); } Model md = list.list(Integer.valueOf(args[0])); Display.setDisplayMode(new DisplayMode(800, 600)); Display.setTitle("Model Viewer"); Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f, (float) Color.gray.getBlue() / 255f); Display.create(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); double aspect = 1; double near = 1; // near should be chosen as far into the scene as // possible double far = 1000; double fov = 1; // 1 gives you a 90� field of view. It's // tan(fov_angle)/2. GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far); GL11.glCullFace(GL11.GL_BACK); long last = 0; while (!Display.isCloseRequested()) { // Clear the screen and depth buffer GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glBegin(GL11.GL_TRIANGLES); for (int i = 0; i < md.faceCount; ++i) { int vertexA = md.triangleX[i]; int vertexB = md.triangleY[i]; int vertexC = md.triangleZ[i]; int vertexAx = md.vertexX[vertexA]; int vertexAy = md.vertexY[vertexA]; int vertexAz = md.vertexZ[vertexA]; int vertexBx = md.vertexX[vertexB]; int vertexBy = md.vertexY[vertexB]; int vertexBz = md.vertexZ[vertexB]; int vertexCx = md.vertexX[vertexC]; int vertexCy = md.vertexY[vertexC]; int vertexCz = md.vertexZ[vertexC]; short hsb = md.faceColor[i]; int rgb = hsbToRGB(hsb); Color c = new Color(rgb); // convert to range of 0-1 float rf = (float) c.getRed() / 255f; float gf = (float) c.getGreen() / 255f; float bf = (float) c.getBlue() / 255f; GL11.glColor3f(rf, gf, bf); GL11.glVertex3i(vertexAx, vertexAy, vertexAz - 50); GL11.glVertex3i(vertexBx, vertexBy, vertexBz - 50); GL11.glVertex3i(vertexCx, vertexCy, vertexCz - 50); } GL11.glEnd(); Display.update(); Display.sync(50); // fps long delta = System.currentTimeMillis() - last; last = System.currentTimeMillis(); Camera.create(); Camera.acceptInput(delta); Camera.apply(); } Display.destroy(); }
Example 16
Source File: Renderer.java From AnyaBasic with MIT License | 4 votes |
Renderer( int screenWidth, int screenHeight ) { try { Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight)); Display.create(); Display.setTitle( "AnyaBasic 0.4.0 beta" ); } catch( LWJGLException e ) { e.printStackTrace(); } this.screenWidth = screenWidth; this.screenHeight = screenHeight; GL11.glViewport( 0, 0, screenWidth, screenHeight ); GL11.glMatrixMode( GL11.GL_PROJECTION ); GL11.glLoadIdentity(); GL11.glOrtho( 0, screenWidth, screenHeight, 0, 1, -1 ); GL11.glMatrixMode( GL11.GL_MODELVIEW ); GL11.glLoadIdentity(); GL11.glShadeModel(GL11.GL_SMOOTH); //set shading to smooth(try GL_FLAT) GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //set Clear color to BLACK GL11.glClearDepth(1.0f); //Set Depth buffer to 1(z-Buffer) GL11.glDisable(GL11.GL_DEPTH_TEST); //Disable Depth Testing so that our z-buffer works GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable( GL11.GL_ALPHA_TEST ); GL11.glAlphaFunc(GL11.GL_GREATER, 0); GL11.glEnable( GL11.GL_BLEND ); GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL); GL11.glMatrixMode( GL11.GL_MODELVIEW ); GL11.glLoadIdentity(); GL11.glTranslatef( 0.375f, 0.375f, 0 ); // magic trick }
Example 17
Source File: Game.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 4 votes |
/** * Inits the. * * @param width the width * @param height the height * @param name the name */ public void init(int width, int height, String name) { Game.logicalWidth = width; Game.logicalHeight = height; Game.scale = FEResources.getWindowScale(); final int windowWidth = Math.round(logicalWidth * scale); final int windowHeight = Math.round(logicalHeight * scale); try { Display.setDisplayMode(new DisplayMode(windowWidth, windowHeight)); Display.create(); Display.setTitle(name); Keyboard.create(); Keyboard.enableRepeatEvents(true); Mouse.create(); glContextExists = true; } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } //init OpenGL glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.01f); glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glViewport(0, 0, windowWidth, windowHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, height, 0, 1, -1); //It's basically a camera glMatrixMode(GL_MODELVIEW); keys = new ArrayList<KeyboardEvent>(); mouseEvents = new ArrayList<MouseEvent>(); }
Example 18
Source File: ShoveTargetTest.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 4 votes |
@Before public void globalDisplayBefore() throws org.lwjgl.LWJGLException { Display.setDisplayMode(new org.lwjgl.opengl.DisplayMode(5, 5)); Display.create(); }
Example 19
Source File: Test.java From tribaltrouble with GNU General Public License v2.0 | 4 votes |
public final static void main(String[] args) { try { Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT)); Display.create(); initGL(); // Load font InputStream font_is = Utils.makeURL("/fonts/tahoma.ttf").openStream(); java.awt.Font src_font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, font_is); java.awt.Font font = src_font.deriveFont(14f); // Load text InputStreamReader text_is = new InputStreamReader(Utils.makeURL("/test_text.txt").openStream()); StringBuffer str_buffer = new StringBuffer(); int c = text_is.read(); do { str_buffer.append((char)c); c = text_is.read(); } while (c != -1); String str = str_buffer.toString(); // Build texture int[] pixels = new int[WIDTH*HEIGHT]; // ByteBuffer pixel_data = ByteBuffer.wrap(pixels); // NEW // pixelDataFromString(WIDTH, HEIGHT, str, font, pixels); // NEW IntBuffer pixel_data = BufferUtils.createIntBuffer(WIDTH*HEIGHT); // OLD pixel_data.put(pixels); // OLD pixel_data.rewind(); int texture_handle = createTexture(WIDTH, HEIGHT, pixel_data); FontRenderContext frc = g2d.getFontRenderContext(); AttributedString att_str = new AttributedString(str); att_str.addAttribute(TextAttribute.FONT, font); AttributedCharacterIterator iterator = att_str.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc); while (!Display.isCloseRequested()) { long start_time = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { pixelDataFromString(WIDTH, HEIGHT, str, font, pixels, measurer); pixel_data.put(pixels); // OLD pixel_data.rewind(); //texture_handle = createTexture(WIDTH, HEIGHT, pixel_data); updateTexture(WIDTH, HEIGHT, pixel_data); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glLoadIdentity(); // Background /* GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glColor4f(.1f, .1f, .1f, 1f); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f); GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f); GL11.glEnd(); */ // Text GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glColor4f(1f, 1f, 1f, 1f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0f, 1f); GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glTexCoord2f(1f, 1f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glTexCoord2f(1f, 0f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f); GL11.glTexCoord2f(0f, 0f); GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f); GL11.glEnd(); Display.update(); } long total_time = System.currentTimeMillis() - start_time; System.out.println("total_time = " + total_time); } Display.destroy(); } catch (Exception t) { t.printStackTrace(); } }
Example 20
Source File: TestWithDisplay.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
@BeforeClass public void createDisplay() throws LWJGLException { Display.setDisplayMode(new DisplayMode(1, 1)); Display.create(); }