List of usage examples for org.lwjgl.opengl GL11 GL_TRUE
int GL_TRUE
To view the source code for org.lwjgl.opengl GL11 GL_TRUE.
Click Source Link
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
public boolean windowShouldClose() { return glfwWindowShouldClose(window) == GL11.GL_TRUE; }
From source file:me.ukl.api.util.TextureUtil.java
License:MIT License
public static void loadTextureMipmap(int tex, int[] rgb, int width, int height) { IntBuffer rgbBuf = BufferUtils.createIntBuffer(rgb.length); rgbBuf.put(rgb);/* w w w . ja va 2 s. c o m*/ rgbBuf.flip(); bind(tex); //If OpenGL30, use glGenerateMipmap, else use the GL_GENERATE_MIPMAP tex param if (RenderUtil.GL_30) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf); } }
From source file:mwisbest.openbase.opengl.TextureLoader.java
License:Open Source License
private TextureImplementation getTexture(InputStream in, String resourceName, int target, int minFilter, int magFilter, boolean flipped, int[] transparent) throws IOException { // create the texture ID for this texture ByteBuffer textureBuffer;/* w w w . ja v a2 s .co m*/ LoadableImageData imageData = ImageDataFactory.getImageDataFor(resourceName); textureBuffer = imageData.loadImage(new BufferedInputStream(in), flipped, transparent); int textureID = createTextureID(); TextureImplementation texture = new TextureImplementation(resourceName, target, textureID); // bind this texture GL11.glEnable(target); GL11.glBindTexture(target, textureID); int width; int height; int texWidth; int texHeight; ImageData.Format format; width = imageData.getWidth(); height = imageData.getHeight(); format = imageData.getFormat(); texture.setTextureWidth(imageData.getTexWidth()); texture.setTextureHeight(imageData.getTexHeight()); texWidth = texture.getTextureWidth(); texHeight = texture.getTextureHeight(); IntBuffer temp = BufferUtils.createIntBuffer(16); GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp); int max = temp.get(0); if (texWidth > max || texHeight > max) throw new IOException("Attempt to allocate a texture to big for the current hardware"); int srcPixelFormat = format.getOGLType(); texture.setWidth(width); texture.setHeight(height); texture.setImageFormat(format); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30 || capabilities.GL_EXT_framebuffer_object || capabilities.GL_ARB_framebuffer_object || capabilities.OpenGL14) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, GL11.GL_POLYGON_BIT); if (capabilities.OpenGL30) GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); else if (capabilities.GL_EXT_framebuffer_object) EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); else if (capabilities.GL_ARB_framebuffer_object) ARBFramebufferObject.glGenerateMipmap(GL11.GL_TEXTURE_2D); else if (capabilities.OpenGL14) GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } // produce a texture from the byte buffer GL11.glTexImage2D(target, 0, this.dstPixelFormat, get2Fold(width), get2Fold(height), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
From source file:net.betabears.the2dlibrary.graphics.DisplayHandler.java
public void init(final DisplaySettings ds) { this.ds = ds; glfwSetErrorCallback(new GLFWErrorCallback() { @Override//ww w . j a v a 2 s .c om public void invoke(int error, long description) { LOGGER.log(Level.SEVERE, "GLFW error occurred. Error code: {0}. Description {1}", new Object[] { error, description }); ev.post(new ExitEvent()); } }); if (glfwInit() != GL11.GL_TRUE) { LOGGER.log(Level.SEVERE, "Unable to initialize "); ev.post(new ExitEvent()); } window = glfwCreateWindow(ds.getWidth(), ds.getHeight(), "A game", 0L, 0L); if (window == 0) { LOGGER.log(Level.SEVERE, "Unable to create window."); ev.post(new ExitEvent()); } glfwSetFramebufferSizeCallback(window, new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { ds.setWidth(width); ds.setHeight(height); GL11.glViewport(0, 0, width, height); } }); glfwSetKeyCallback(window, new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { ev.post(new KeyEvent(window, key, scancode, action, mods)); } }); glfwMakeContextCurrent(window); GLContext.createFromCurrent(); }
From source file:net.smert.frameworkgl.Window.java
License:Apache License
public void create() { // Update the configuration Configuration config = Fw.config; config.fullscreenEnabled = fullscreen; config.vSyncEnabled = vSync;/*from w w w . j av a 2 s . c om*/ // Setup variables long monitor = GLFW.glfwGetPrimaryMonitor(); GLFWvidmode videoMode = null; if (fullscreen) { // Attempt to find a matching full screen compatible mode videoMode = findVideoMode(monitor, config.fullscreenWidth, config.fullscreenHeight, config.fullscreenRefreshRate, config.framebufferRedBits, config.framebufferGreenBits, config.framebufferBlueBits); if (videoMode == null) { log.warn("Didn't find a fullscreen display mode for the requested resolution: " + "Width: {}px Height: {}px Refresh Rate: {}hz Red Bits: {} Green Bits: {} Blue Bits: {}", config.fullscreenWidth, config.fullscreenHeight, config.fullscreenRefreshRate, config.framebufferRedBits, config.framebufferGreenBits, config.framebufferBlueBits); } } // Either a full screen mode wasn't requested or we couldn't find one that matched our settings if (videoMode == null) { GLFWvidmode desktopVideoMode = getDesktopVideoMode(monitor); videoMode = new GLFWvidmode(); videoMode.setBlueBits(desktopVideoMode.getBlueBits()); videoMode.setGreenBits(desktopVideoMode.getGreenBits()); videoMode.setHeight(config.desktopHeight); videoMode.setRedBits(desktopVideoMode.getRedBits()); videoMode.setRefreshRate(desktopVideoMode.getRefreshRate()); videoMode.setWidth(config.desktopWidth); } // Reset window hints to defaults before setting them GLFW.glfwDefaultWindowHints(); GLFW.glfwWindowHint(GLFW.GLFW_ALPHA_BITS, videoMode.getBlueBits()); GLFW.glfwWindowHint(GLFW.GLFW_BLUE_BITS, videoMode.getBlueBits()); GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, config.requestedOpenglMajorVersion); GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, config.requestedOpenglMinorVersion); GLFW.glfwWindowHint(GLFW.GLFW_DEPTH_BITS, config.framebufferDepthBits); GLFW.glfwWindowHint(GLFW.GLFW_GREEN_BITS, videoMode.getGreenBits()); GLFW.glfwWindowHint(GLFW.GLFW_RED_BITS, videoMode.getRedBits()); GLFW.glfwWindowHint(GLFW.GLFW_REFRESH_RATE, videoMode.getRefreshRate()); GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, (fullscreen) ? GL11.GL_FALSE : ((config.desktopResizable) ? GL11.GL_TRUE : GL11.GL_FALSE)); if ((config.requestedOpenglMajorVersion >= 3) && (config.requestedOpenglMinorVersion >= 0)) { GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, (config.forwardCompatible) ? GL11.GL_TRUE : GL11.GL_FALSE); } if (((config.requestedOpenglMajorVersion == 3) && (config.requestedOpenglMinorVersion >= 2)) || (config.requestedOpenglMajorVersion >= 4)) { GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, (config.coreProfile) ? GLFW.GLFW_OPENGL_CORE_PROFILE : GLFW.GLFW_OPENGL_COMPAT_PROFILE); } else { GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_ANY_PROFILE); } GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, config.framebufferSamples); GLFW.glfwWindowHint(GLFW.GLFW_SRGB_CAPABLE, (config.framebufferSrgb) ? GL11.GL_TRUE : GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_STENCIL_BITS, config.framebufferStencilBits); GLFW.glfwWindowHint(GLFW.GLFW_STEREO, (config.framebufferStereo) ? GL11.GL_TRUE : GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GL11.GL_FALSE); // Create new window long fullscreenMonitor = (fullscreen) ? monitor : MemoryUtil.NULL; long newWindow = GLFW.glfwCreateWindow(videoMode.getWidth(), videoMode.getHeight(), config.windowTitle, fullscreenMonitor, window); if (newWindow == MemoryUtil.NULL) { throw new WindowException("Failed to create the GLFW window"); } log.info( "Created window with display mode: " + "Width: {}px Height: {}px Refresh Rate: {}hz Red Bits: {} Green Bits: {} Blue Bits: {}", videoMode.getWidth(), videoMode.getHeight(), videoMode.getRefreshRate(), videoMode.getRedBits(), videoMode.getGreenBits(), videoMode.getBlueBits()); // Destroy old window and callback if (window != MemoryUtil.NULL) { GLFW.glfwDestroyWindow(window); cursorPosCallback.release(); keyCallback.release(); mouseButtonCallback.release(); scrollCallback.release(); windowSizeCallback.release(); Fw.input.clearNextState(); } // Resize resize(videoMode.getWidth(), videoMode.getHeight()); // Create GL context GLFW.glfwMakeContextCurrent(newWindow); GLContext.createFromCurrent(); // Set the window location if (!fullscreen) { if ((config.desktopLocationX != -1) && (config.desktopLocationY != -1)) { GLFW.glfwSetWindowPos(newWindow, config.desktopLocationX, config.desktopLocationY); } else { // We can't reuse desktopVideoMode from above since after // we switch out of full screen it would be the full screen // video mode and not the current desktop. GLFWvidmode desktopVideoMode = getDesktopVideoMode(monitor); int x = (desktopVideoMode.getWidth() - config.desktopWidth) / 2; int y = (desktopVideoMode.getHeight() - config.desktopHeight) / 2; GLFW.glfwSetWindowPos(newWindow, x, y); } } // Turn on/off vsync if (vSync) { GLFW.glfwSwapInterval(1); } else { GLFW.glfwSwapInterval(0); } // Events GLFW.glfwSetCursorPosCallback(newWindow, cursorPosCallback = new GLFWCursorPosCallback() { @Override public void invoke(long window, double x, double y) { Fw.input.handleMouseMoveEvent(x, y); } }); GLFW.glfwSetKeyCallback(newWindow, keyCallback = new GLFWKeyCallback() { @Override public void invoke(long window, int key, int scancode, int action, int mods) { Fw.input.addKeyboardEvent(key, mods, scancode, action != GLFW.GLFW_RELEASE); } }); GLFW.glfwSetMouseButtonCallback(newWindow, mouseButtonCallback = new GLFWMouseButtonCallback() { @Override public void invoke(long window, int button, int action, int mods) { Fw.input.addMouseEvent(button, mods, action != GLFW.GLFW_RELEASE); } }); GLFW.glfwSetScrollCallback(newWindow, scrollCallback = new GLFWScrollCallback() { @Override public void invoke(long window, double xoffset, double yoffset) { Fw.input.handleMouseScrollEvent(xoffset, yoffset); } }); GLFW.glfwSetWindowSizeCallback(newWindow, windowSizeCallback = new GLFWWindowSizeCallback() { @Override public void invoke(long window, int width, int height) { resize(width, height); } }); // Show the window GLFW.glfwShowWindow(newWindow); // Save window window = newWindow; // Hide/unhide the cursor Fw.input.updateInputMode(); }
From source file:net.smert.frameworkgl.Window.java
License:Apache License
public boolean isCloseRequested() { return (GLFW.glfwWindowShouldClose(window) == GL11.GL_TRUE); }
From source file:net.smert.frameworkgl.Window.java
License:Apache License
public boolean isFocused() { return (GLFW.glfwGetWindowAttrib(window, GLFW.GLFW_FOCUSED) == GL11.GL_TRUE); }
From source file:net.smert.frameworkgl.Window.java
License:Apache License
public void init() { if (initialized) { return;/*from w ww. j a va2s .c o m*/ } GLFW.glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackThrow()); if (GLFW.glfwInit() != GL11.GL_TRUE) { GLFW.glfwTerminate(); throw new WindowException("Unable to initialize GLFW"); } initialized = true; }
From source file:opengl.test.object.object.java
protected final void vertexShader(String file) { this.vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); GL20.glShaderSource(this.vertexID, object.sourceLoader(file)); GL20.glCompileShader(this.vertexID); if (GL20.glGetShaderi(this.vertexID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile vertexShader"); }/*from w w w.j ava 2 s . c o m*/ GL20.glAttachShader(this.programID, this.vertexID); }
From source file:opengl.test.object.object.java
protected final void fragmentShader(String file) { this.fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); GL20.glShaderSource(this.fragmentID, object.sourceLoader(file)); GL20.glCompileShader(this.fragmentID); if (GL20.glGetShaderi(this.fragmentID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) { throw new RuntimeException("Khong the compile fragmentShader"); }/*from w w w . j av a 2s . co m*/ GL20.glAttachShader(this.programID, this.fragmentID); }