List of usage examples for org.lwjgl.opengl GL11 glViewport
public static void glViewport(@NativeType("GLint") int x, @NativeType("GLint") int y, @NativeType("GLsizei") int w, @NativeType("GLsizei") int h)
From source file:kuake2.render.lwjgl.Main.java
License:Open Source License
/** * R_BeginFrame/* ww w .j a v a 2 s .co m*/ */ protected void R_BeginFrame(float camera_separation) { gl_state.camera_separation = camera_separation; /* ** change modes if necessary */ if (gl_mode.modified || vid_fullscreen.modified) { // FIXME: only restart if CDS is required cvar_t ref; ref = Cvar.Get("vid_ref", "lwjgl", 0); ref.modified = true; } if (gl_log.modified) { GLimp_EnableLogging((gl_log.value != 0.0f)); gl_log.modified = false; } if (gl_log.value != 0.0f) { GLimp_LogNewFrame(); } /* ** update 3Dfx gamma -- it is expected that a user will do a vid_restart ** after tweaking this value */ if (vid_gamma.modified) { vid_gamma.modified = false; if ((gl_config.renderer & GL_RENDERER_VOODOO) != 0) { // wird erstmal nicht gebraucht /* char envbuffer[1024]; float g; g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F; Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g ); putenv( envbuffer ); Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g ); putenv( envbuffer ); */ VID.Printf(Defines.PRINT_DEVELOPER, "gamma anpassung fuer VOODOO nicht gesetzt"); } } GLimp_BeginFrame(camera_separation); /* ** go into 2D mode */ GL11.glViewport(0, 0, vid.width, vid.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, vid.width, vid.height, 0, -99999, 99999); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glColor4f(1, 1, 1, 1); /* ** draw buffer stuff */ if (gl_drawbuffer.modified) { gl_drawbuffer.modified = false; if (gl_state.camera_separation == 0 || !gl_state.stereo_enabled) { if (gl_drawbuffer.string.equalsIgnoreCase("GL_FRONT")) GL11.glDrawBuffer(GL11.GL_FRONT); else GL11.glDrawBuffer(GL11.GL_BACK); } } /* ** texturemode stuff */ if (gl_texturemode.modified) { GL_TextureMode(gl_texturemode.string); gl_texturemode.modified = false; } if (gl_texturealphamode.modified) { GL_TextureAlphaMode(gl_texturealphamode.string); gl_texturealphamode.modified = false; } if (gl_texturesolidmode.modified) { GL_TextureSolidMode(gl_texturesolidmode.string); gl_texturesolidmode.modified = false; } /* ** swapinterval stuff */ GL_UpdateSwapInterval(); // // clear screen if desired // R_Clear(); }
From source file:kubex.gui.DepthPeelingLiquidRenderer.java
License:Creative Commons License
/** * Performs the depth peeling rendering//from www . j a v a2 s .c om */ @Override public void renderLayers(World w, int xres, int yres) { this.DPS.enable(); int upperLimitDepth = GL20.glGetUniformLocation(this.DPS.getID(), "upperLimitDepth"); int lowerLimitDepth = GL20.glGetUniformLocation(this.DPS.getID(), "lowerLimitDepth"); int upperLimitIndex = GL20.glGetUniformLocation(this.DPS.getID(), "upperLimitIndex"); GL20.glUniform1i(upperLimitDepth, KubexGame.LIQUIDLAYERS_TEXTURE_LOCATION); GL20.glUniform1i(lowerLimitDepth, KubexGame.BASEFBO_DEPTH_TEXTURE_LOCATION); GL20.glUniform1i(GL20.glGetUniformLocation(this.DPS.getID(), "xres"), xres); GL20.glUniform1i(GL20.glGetUniformLocation(this.DPS.getID(), "yres"), yres); w.overrideCurrentShader(this.DPS); //Makes world use the depth peeling shader when drawing chunks //Writes each liquid layer to a texture for (int i = 0; i < this.getNumLayers(); i++) { GL20.glUniform1i(upperLimitIndex, i - 1); glBindFramebuffer(GL_FRAMEBUFFER, this.layersFbos[i]); glClear(GL11.GL_DEPTH_BUFFER_BIT); GL11.glViewport(0, 0, xres, yres); w.drawLiquids(); } this.DPS.disable(); }
From source file:kubex.KubexGame.java
License:Creative Commons License
/** * Render loop//from www .j ava2s. c om */ private void render() { if (this.settings.SHADOWS_ENABLED) //If shadows are enabled, calculate each cascade shadow map { this.shadowsManager.calculateCascadeShadows(this.sunCam.getViewMatrix(), this.world.getWorldCornersLow(), this.world.getWorldCornersHigh()); this.world.overrideCurrentShader(this.DVSP); for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) { glBindFramebuffer(GL_FRAMEBUFFER, this.shadowFbos[i]); glClear(GL11.GL_DEPTH_BUFFER_BIT); GL11.glViewport(0, 0, SHADOW_XRES, SHADOW_YRES); this.world.overrideCurrentPVMatrix(this.shadowsManager.getOrthoProjectionForSplit(i)); this.world.draw(this.shadowsManager.getBoundaryCheckerForSplit(i)); } } glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, this.tilesTexture); glBindFramebuffer(GL_FRAMEBUFFER, this.baseFbo); glClear(GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glViewport(0, 0, X_RES, Y_RES); this.world.overrideCurrentShader(null); this.world.overrideCurrentPVMatrix(null); this.world.draw(null); //Draws the world normally into the framebuffer basefbo, filling the color, normal, lighting and depth base textures this.liquidRenderer.renderLayers(this.world, X_RES, Y_RES); //Renders the liquid layers, one by one, into its respectives depth texutres glBindFramebuffer(GL_FRAMEBUFFER, this.baseFbo); //Binds the base fbo again for safeness (The liquid layers has binded their respective fbo each) nightDomeTexture.bind(); //Uses in GL_TEXTURE0 the night dome texture instead of the cubes textures from now on this.world.afterDrawTasks(); glDisable(GL_DEPTH_TEST); //Depth test is no longer needed, we are drawing a texture glEnable(GL11.GL_CULL_FACE); //We only draw a quad looking to the screen, not its backface (Invisible) int[] fbos = { this.deferredFbo, 0 }; //Only two passes of deferred rendering remaining, so we use for the second a fbo and for the third we render to the screen DeferredShaderProgram[] programs = { this.DTSP, this.DRSP }; if (this.world.isUnderwater()) { //Switching the shaders if we are underwater programs = new DeferredShaderProgram[] { this.DUTSP, this.DUFSP }; } Matrix4f temp = Matrix4f.invert(this.cam.getProjectionViewMatrix(), null); this.finalDrawManager.draw(programs, fbos, temp, this.cam.getViewMatrix(), this.cam.getProjectionMatrix(), X_RES, Y_RES); //Draw the two remaining deferred passes this.HSP.enable(); this.hud.draw(); //Draws the hud (Gray point on the center of the screen) this.HSP.disable(); TextureImpl.bindNone(); this.textManager.draw(X_RES, Y_RES); //Draws text, if needed }
From source file:kubex.KubexGame.java
License:Creative Commons License
/** * Inits the game resources (Images, pools, shaders, objects, etc.) *///w w w . ja v a2 s .c o m private void initResources() throws IOException { //Inits static pools FloatBufferPool.init(Chunk.CHUNK_DIMENSION * Chunk.CHUNK_DIMENSION * Chunk.CHUNK_DIMENSION * 2 * 6 * 6, 20); ByteArrayPool.init(Chunk.CHUNK_DIMENSION, (settings.RENDER_DISTANCE * 2 + 1) * World.HEIGHT * (settings.RENDER_DISTANCE * 2 + 1) * 2); glEnable(GL11.GL_CULL_FACE); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); glEnable(GL11.GL_BLEND); glClearColor(0.6f, 0.8f, 1.0f, 0f); //Inits shaders GL20.glUseProgram(0); textManager = new GlobalTextManager(); this.DVSP = new DepthVoxelShaderProgram(true); this.VSP = new TerrainVoxelShaderProgram(true); this.HSP = new HudShaderProgram(true); this.DTSP = this.settings.SHADOWS_ENABLED ? new DeferredTerrainShaderProgram(true) : new DeferredTerrainUnshadowShaderProgram(true); this.DRSP = this.settings.REFLECTIONS_ENABLED ? new DeferredReflectionsShaderProgram(true) : new DeferredNoReflectionsShaderProgram(true); this.DUTSP = this.settings.SHADOWS_ENABLED ? new DeferredUnderwaterTerrainShaderProgram(true) : new DeferredUnderwaterUnshadowTerrainShaderProgram(true); this.DUFSP = new DeferredUnderwaterFinalShaderProgram(true); //Inits essential objects this.TM = new TimeManager(); this.cam = new Camera(CAMERA_NEAR, CAMERA_FAR, 80f, (float) (X_RES * 3 / 4) / Y_RES); //FOV more width than height BY DESIGN, so blocks looks more "plane". Looks nicer that way, i think. this.camInvProjEnv = new CameraInverseProjEnvelope(this.cam); this.shadowsManager = new ShadowsManager(SHADOW_SPLITS, this.cam); this.liquidRenderer = new DepthPeelingLiquidRenderer(LIQUID_LAYERS); this.sunCam = new Camera(new Matrix4f()); this.sunCam.moveTo(0, 5, 0); this.sunCam.setPitch(0); this.sky = new Sky(cam, this.sunCam); File mapRoute = new File(this.settings.MAP_ROUTE); mapRoute.mkdir(); //Creates the maps folder this.fileManager = new FileManager(mapRoute, settings.RENDER_DISTANCE); this.fileManager.getSettingsFromFile(settings); //Reads default settings from settings file. this.world = new World(this.VSP, this.cam, this.sunCam, this.shadowsManager, this.sky, fileManager, this.settings); this.finalDrawManager = new FinalDrawManager(this.world, this.sky, this.shadowsManager, this.liquidRenderer, this.camInvProjEnv.getInvProjMatrix(), CAMERA_NEAR, CAMERA_FAR); this.hud = new Hud(this.HSP, X_RES, Y_RES); //Load textures here glActiveTexture(TEXTURE_FETCH[TILES_TEXTURE_LOCATION]); //GL_NEAREST for that blocky look //loads the tiles textures into a array tilesTexture = Util.loadTextureAtlasIntoTextureArray(FileLoader.loadTileImages(), GL11.GL_NEAREST, GL11.GL_NEAREST_MIPMAP_LINEAR, true, settings.ANISOTROPIC_FILTERING_ENABLED); Util.loadPNGTexture(FileLoader.loadWaterNormalImage(), TEXTURE_FETCH[WATER_NORMAL_TEXTURE_LOCATION]); //loads the water normal texture glActiveTexture(GL_TEXTURE0); nightDomeTexture = TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("images/nightdome.jpg")); //loads the nightdome //Without this, text printing using Slick-Utils doesn't work. Seems it still uses some old mode OpenGL. GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0, 0, X_RES, Y_RES); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, X_RES, Y_RES, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); //First pass deferred rendering this.baseFbo = glGenFramebuffers(); glBindFramebuffer(GL_FRAMEBUFFER, this.baseFbo); int colorTexture = glGenTextures(); int brightnessNormalsTexture = glGenTextures(); //Creates and inits the base color texture as a RGB texture glActiveTexture(TEXTURE_FETCH[BASEFBO_COLOR_TEXTURE_LOCATION]); glBindTexture(GL_TEXTURE_2D, colorTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, X_RES, Y_RES, 0, GL_RGB, GL_UNSIGNED_BYTE, (FloatBuffer) null); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0); //Creates and inits the brightness and normals texture as a RGBA texture glActiveTexture(TEXTURE_FETCH[BASEFBO_NORMALS_BRIGHTNESS_TEXTURE_LOCATION]); glBindTexture(GL_TEXTURE_2D, brightnessNormalsTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA, X_RES, Y_RES, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE, (FloatBuffer) null); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, brightnessNormalsTexture, 0); //The depth buffer of this FBO will be a texture, too. This will make depth sorting slower but we will be able to access depth values later. int baseFboDepth = glGenTextures(); glActiveTexture(TEXTURE_FETCH[BASEFBO_DEPTH_TEXTURE_LOCATION]); glBindTexture(GL_TEXTURE_2D, baseFboDepth); glTexImage2D(GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, X_RES, Y_RES, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (FloatBuffer) null); System.out.println("ERR" + GL11.glGetError()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, baseFboDepth, 0); //Set the depth texture as the default render depth target IntBuffer drawBuffers = BufferUtils.createIntBuffer(2); //Drawing to 2 textures drawBuffers.put(GL_COLOR_ATTACHMENT0); drawBuffers.put(GL_COLOR_ATTACHMENT1); drawBuffers.flip(); GL20.glDrawBuffers(drawBuffers); //Second pass deferred rendering this.deferredFbo = glGenFramebuffers(); glBindFramebuffer(GL_FRAMEBUFFER, this.deferredFbo); int deferredColorTex = glGenTextures(); //Only uses one texture, a RGBA color texture glActiveTexture(TEXTURE_FETCH[DEFERREDFBO_COLOR_TEXTURE_LOCATION]); glBindTexture(GL_TEXTURE_2D, deferredColorTex); glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA, X_RES, Y_RES, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE, (FloatBuffer) null); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, deferredColorTex, 0); drawBuffers = BufferUtils.createIntBuffer(1); drawBuffers.put(GL_COLOR_ATTACHMENT0); drawBuffers.flip(); GL20.glDrawBuffers(drawBuffers); //If shadows are enabled, we init each shadow map texture, placed in an array if (this.settings.SHADOWS_ENABLED) { int shadowTexture = glGenTextures(); glActiveTexture(TEXTURE_FETCH[SHADOW_TEXTURE_LOCATION]); glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, shadowTexture); //Creates a texture array to place the shadows in GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL14.GL_DEPTH_COMPONENT16, SHADOW_XRES, SHADOW_YRES, this.shadowsManager.getNumberSplits(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (FloatBuffer) null); System.out.println("ERR" + GL11.glGetError()); glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); //Needed to do hardware PCF comparisons via shader glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); //Needed to do hardware PCF comparisons via shader glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL14.GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); //Needed to do hardware PCF comparisons via shader this.shadowFbos = new int[this.shadowsManager.getNumberSplits()]; //Creates one framebuffer per shadow map for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) { this.shadowFbos[i] = glGenFramebuffers(); glBindFramebuffer(GL_FRAMEBUFFER, this.shadowFbos[i]); GL30.glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowTexture, 0, i); //Each framebuffer will have one texture layer (one index of the texture array created before) assigned as render target drawBuffers = BufferUtils.createIntBuffer(0); GL20.glDrawBuffers(drawBuffers); } } //Liquid layers depth generation. Equal to the shadows depth textures generation. int liquidLayers = glGenTextures(); glActiveTexture(TEXTURE_FETCH[LIQUIDLAYERS_TEXTURE_LOCATION]); glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, liquidLayers); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL14.GL_DEPTH_COMPONENT24, X_RES, Y_RES, this.liquidRenderer.getNumLayers(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (FloatBuffer) null); glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); //We will compare manually the depth in the shader, we will not perform PCF of any sort in this case glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); int currentLiquidNormalTex = glGenTextures(); glActiveTexture(KubexGame.TEXTURE_FETCH[KubexGame.CURRENT_LIQUID_NORMAL_TEXTURE_LOCATION]); glBindTexture(GL_TEXTURE_2D, currentLiquidNormalTex); glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGB, X_RES, Y_RES, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (FloatBuffer) null); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); this.liquidRenderer.initResources(liquidLayers, currentLiquidNormalTex); //Reset active texture and fbo to the default glActiveTexture(GL13.GL_TEXTURE0); glBindFramebuffer(GL_FRAMEBUFFER, 0); }
From source file:lwjake2.render.lwjgl.Main.java
License:Open Source License
/** * R_BeginFrame/*from w w w .j a v a2 s .c o m*/ */ protected void R_BeginFrame(float camera_separation) { gl_state.camera_separation = camera_separation; /* ** change modes if necessary */ if (gl_mode.modified || vid_fullscreen.modified) { // FIXME: only restart if CDS is required cvar_t ref; ref = Cvar.Get("vid_ref", "lwjgl", 0); ref.modified = true; } if (gl_log.modified) { GLimp_EnableLogging((gl_log.value != 0.0f)); gl_log.modified = false; } if (gl_log.value != 0.0f) { GLimp_LogNewFrame(); } /* ** update 3Dfx gamma -- it is expected that a user will do a vid_restart ** after tweaking this value */ if (vid_gamma.modified) { vid_gamma.modified = false; if ((gl_config.renderer & GL_RENDERER_VOODOO) != 0) { // wird erstmal nicht gebraucht /* char envbuffer[1024]; float g; g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F; Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g ); putenv( envbuffer ); Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g ); putenv( envbuffer ); */ VID.Printf(Defines.PRINT_DEVELOPER, "gamma anpassung fuer VOODOO nicht gesetzt"); } } GLimp_BeginFrame(camera_separation); /* ** go into 2D mode */ GL11.glViewport(0, 0, vid.width, vid.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, vid.width, vid.height, 0, -99999, 99999); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glColor4f(1, 1, 1, 1); /* ** draw buffer stuff */ if (gl_drawbuffer.modified) { gl_drawbuffer.modified = false; if (gl_state.camera_separation == 0 || !gl_state.stereo_enabled) { if (gl_drawbuffer.string.equalsIgnoreCase("GL_FRONT")) GL11.glDrawBuffer(GL11.GL_FRONT); else GL11.glDrawBuffer(GL11.GL_BACK); } } /* ** texturemode stuff */ if (gl_texturemode.modified) { GL_TextureMode(gl_texturemode.string); gl_texturemode.modified = false; } if (gl_texturealphamode.modified) { GL_TextureAlphaMode(gl_texturealphamode.string); gl_texturealphamode.modified = false; } if (gl_texturesolidmode.modified) { GL_TextureSolidMode(gl_texturesolidmode.string); gl_texturesolidmode.modified = false; } /* ** swapinterval stuff */ GL_UpdateSwapInterval(); // // clear screen if desired // R_Clear(); }
From source file:main.Credits.java
License:Creative Commons License
public void run(boolean initi) { FONT = Main.FONT;/* www .j av a 2s . co m*/ FONT2 = Main.FONT2; FULL = Display.isFullscreen(); if (QUALITY == 1) { WIDTH = 500; HEIGHT = 500; } init(initi); while (run) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(translate_x, translate_y, 0); if (Display.wasResized()) { RWIDTH = Display.getWidth(); RHEIGHT = Display.getHeight(); GL11.glViewport(0, 0, RWIDTH, RHEIGHT); GL11.glLoadIdentity(); } // Retrieve the "true" coordinates of the mouse. mousex = (int) (Mouse.getX() * ((float) (WIDTH) / RWIDTH) - translate_x); mousey = (int) (HEIGHT - Mouse.getY() * ((float) (HEIGHT) / RHEIGHT) - 1 - translate_y); Draw.renderthistex(new Rectangle(0, 0, WIDTH, HEIGHT), purple); logic(); render(); update(); if (Display.isCloseRequested()) { run = false; Main.run = false; } glPopMatrix(); Display.update(); Display.sync(60); } Main.RWIDTH = RWIDTH; Main.RHEIGHT = RHEIGHT; }
From source file:main.DisplayManager.java
public static void createDisplay() { ContextAttribs attribs = new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true); attribs.withForwardCompatible(true); try {/* ww w. jav a 2s . c om*/ Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT)); Display.create(new PixelFormat(), attribs); Display.setTitle("Much Game very fun"); } catch (LWJGLException ex) { Logger.getLogger(DisplayManager.class.getName()).log(Level.SEVERE, null, ex); } GL11.glViewport(0, 0, WIDTH, HEIGHT); lastFrameTime = getCurrrentTime(); }
From source file:main.java.com.YeAJG.game.Game.java
License:Open Source License
/** * Initiates Display and OpenGL, using OpenGL 3.2 *//*from w w w.j ava2 s . co m*/ private void setupOpenGL() { try { PixelFormat pixelFormat = new PixelFormat(); ContextAttribs contextAtrributes = new ContextAttribs(3, 2).withForwardCompatible(true) .withProfileCore(true); Display.setDisplayMode(new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT)); Display.setTitle(Name + " " + ConfigHandler.getVersion()); Display.create(pixelFormat, contextAtrributes); } catch (LWJGLException e) { logger.fatal(e.getMessage()); System.exit(-1); } //Sets the Background color. GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f); //Creates the Viewport. GL11.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); //Enables Depth Testing. GL11.glEnable(GL11.GL_DEPTH_TEST); //Exit on Setup Error. Game.exitOnGLError("setupOpenGL"); }
From source file:map.GameMap.java
License:Open Source License
private void renderMinimap() { int size = MINIMAP_SIZE; Texture tex = new Texture("ground"); miniMap = new Material(name + "_minimap"); int[] viewport = GLUtils.getViewport(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity();// ww w . java2s. c o m GL11.glOrtho(0, size, size, 0, -10, 10); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glViewport(0, 0, size, size); GL11.glClearColor(0.0f, 0, 0, 1.0f); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glScalef(size / tiles.length, size / tiles.length, size / tiles.length); GLUtils.glLightPos(1.0f, 1.0f, 1.0f); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_CULL_FACE); draw(null); GL11.glEnable(GL11.GL_CULL_FACE); IntBuffer addr = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(addr); tex.setID(addr.get(0)); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, size, size, 0); miniMap.setTexture(0, tex); GL11.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
public void createWindow(int width, int height, String name) { this.width = width; this.height = height; glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err)); if (glfwInit() != GL11.GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); glfwDefaultWindowHints(); // optional, the current window hints are glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); // the window will stay // hidden// www. j a va 2 s . c om glfwWindowHint(GLFW_RESIZABLE, GL11.GL_TRUE); // the window will be // resizable window = glfwCreateWindow(width, height, name, NULL, NULL); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); // glfwSetKeyCallback(window,this.keyCallback = keyCallback); glfwSetWindowSizeCallback(window, resizeCallback()); ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(window, (vidmode.asIntBuffer().get(0) - width) / 2, (vidmode.asIntBuffer().get(1) - height) / 2); glfwMakeContextCurrent(window); Graphic.instance = this; glfwSwapInterval(1); GL.createCapabilities(); setCapabilities(); glfwShowWindow(window); // Setup an XNA like background color GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0); // Map the internal OpenGL coordinate system to the entire screen GL11.glViewport(0, 0, width, height); matBuff = BufferUtils.createFloatBuffer(16); vaoId = GL30.glGenVertexArrays(); vboiId = GL15.glGenBuffers(); vboId = GL15.glGenBuffers(); tid_charmap = texManager.loadTexture("textures/charmap.png", GL13.GL_TEXTURE0); shader.setupShader(); // testQuad(); }