本文整理汇总了Java中org.lwjgl.opengl.GLContext.createFromCurrent方法的典型用法代码示例。如果您正苦于以下问题:Java GLContext.createFromCurrent方法的具体用法?Java GLContext.createFromCurrent怎么用?Java GLContext.createFromCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.opengl.GLContext
的用法示例。
在下文中一共展示了GLContext.createFromCurrent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWindow
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
/**
* Creates a GLFWWindow and gives it OpenGL context
*/
private void createWindow() {
// Hide the window during application initialization
Window.hint(GLFW.GLFW_VISIBLE, GL11.GL_FALSE);
// Setup MSAA 4x
Window.hint(GLFW.GLFW_SAMPLES, 4);
WINDOW.create(config.width, config.height, config.title);
// Make this thread and window the current context for OpenGL
WINDOW.makeContextCurrent();
GLContext.createFromCurrent();
// Set other specified window configurations
WINDOW.setVSyncEnabled(config.vSyncEnabled);
WINDOW.setPosition(config.position);
}
示例2: init
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
/**
* Initialize default state.
*/
private void init() {
if (glfwInit() != GL_TRUE) {
throw new IllegalStateException("GLFW failed to initialize!");
}
win = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, TITLE, 0, 0);
glfwShowWindow(win);
glfwMakeContextCurrent(win);
GLContext.createFromCurrent();
GL.createCapabilities(true);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
示例3: Window
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
public Window(String title, int width, int height) {
Window.title = title;
Window.width = width;
Window.height = height;
glfwInit();
//glfwWindowHint(GLFW_DECORATED, GL_FALSE);
window = glfwCreateWindow(width, height, title, 0, 0);
glfwMakeContextCurrent(window);
GLContext.createFromCurrent();
glfwSwapInterval(1);
keyCallback = new KeyCallback();
mousePosCallback = new MousePosCallback();
glfwSetKeyCallback(window, keyCallback);
glfwSetCursorPosCallback(window, mousePosCallback);
}
示例4: createDisplay
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
public static void createDisplay()
{
glfwInit();
glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(width, height, "", 0, 0);
glfwMakeContextCurrent(window);
GLContext.createFromCurrent();
glfwShowWindow(window);
setCursorPosCallback();
setMouseCallback();
setKeyCallback();
if (window == 0) {
throw new RuntimeException("Failed to create window");
}
GL11.glViewport(0, 0, width, height);
}
示例5: OpenGLDisplay
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
/**
* Creates a new OpenGL display.
*
* @param width The width of the display, in pixels.
* @param height The height of the display, in pixels.
* @param title The text appearing in the display's title bar.
*/
public OpenGLDisplay(int width, int height, String title) {
glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
if (glfwInit() != GL_TRUE) {
throw new IllegalStateException("Unable to initialize GLFW");
}
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
window = glfwCreateWindow(width, height, title, NULL, NULL);
if (window == NULL) {
throw new RuntimeException("Failed to create the GLFW window");
}
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2,
(GLFWvidmode.height(vidmode) - height) / 2);
glfwMakeContextCurrent(window);
glfwSwapInterval(Debug.isIgnoringFrameCap() ? 0 : 1);
glfwShowWindow(window);
GLContext.createFromCurrent();
device = new OpenGLRenderDevice(width, height);
this.target = new RenderTarget(device, width, height, 0, 0);
frameBuffer = new RenderContext(device, target);
input = new OpenGLInput(window);
audioDevice = new OpenALAudioDevice();
}
示例6: initGL
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
public static void initGL()
{
Lime.LOGGER.F("Checking GL context capabilities");
GLContext context = GLContext.createFromCurrent();
ContextCapabilities capabilities = context.getCapabilities();
if (!capabilities.GL_EXT_framebuffer_object)
{
Lime.LOGGER.C("GL_XBT_framebuffer_object not supported");
throw new IllegalStateException("GL context not capable: GL_XBT_framebuffer_object");
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
updateViewport();
Lime.LOGGER.F("GL initialized");
}
示例7: loop
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
private void loop()
{
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the ContextCapabilities instance and makes the OpenGL
// bindings available for use.
GLContext.createFromCurrent();
// Set the clear color
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while (glfwWindowShouldClose(this.window) == GL_FALSE)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
// useless code, deal with it.
for (int i = 0, k = DioriteRandomUtils.nextInt(50); i < k; i++)
{
rect(DioriteRandomUtils.getRandomDouble(- 1, 1), DioriteRandomUtils.getRandomDouble(- 1, 1), DioriteRandomUtils.getRandomDouble(- 1, 1), DioriteRandomUtils.getRandomDouble(- 1, 1), DioriteRandomUtils.getRandomDouble(0, 5));
}
glfwSwapBuffers(this.window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
if (this.stop)
{
glfwSetWindowShouldClose(this.window, GL_TRUE);
break;
}
try
{
Thread.sleep(300);
} catch (final InterruptedException e)
{
e.printStackTrace();
}
}
}
示例8: render
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
public void render() {
Engine.getEngine().setDisplay(this);
// Initialize GLFW. Most GLFW functions will not work before doing this.
if (glfwInit() != GL11.GL_TRUE)
throw new IllegalStateException("Unable to initialize GLFW");
// Configure our window
glfwDefaultWindowHints(); // optional, the current window hints are
// already the default
glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden
// after creation
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // the window will be
// resizable
// Create the window
// Get the resolution of the primary monitor
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Create a window.
sizeX = GLFWvidmode.width(vidmode);
sizeY = GLFWvidmode.height(vidmode);
Settings.getSettings().addSetting(
new Setting<Boolean>("FULLSCREEN", fullscreen));
Settings.getSettings().addSetting(
new Setting<Integer>("RESOLUTION_X", fullscreen ? GLFWvidmode
.width(vidmode) : 800));
Settings.getSettings().addSetting(
new Setting<Integer>("RESOLUTION_Y", fullscreen ? GLFWvidmode
.height(vidmode) : 600));
windowHandler = glfwCreateWindow(
fullscreen ? GLFWvidmode.width(vidmode) : 800,
fullscreen ? GLFWvidmode.height(vidmode) : 600, name,
fullscreen ? glfwGetPrimaryMonitor() : NULL, NULL);
if (windowHandler == NULL)
throw new RuntimeException("Failed to create the GLFW window");
// Make the OpenGL context current
glfwMakeContextCurrent(windowHandler);
GLContext.createFromCurrent();
// Enable v-sync
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(windowHandler);
// Setup OpenGL for use
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0, 0, fullscreen ? GLFWvidmode.width(vidmode) : 800,
fullscreen ? GLFWvidmode.height(vidmode) : 600);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, fullscreen ? GLFWvidmode.width(vidmode) : 800,
fullscreen ? GLFWvidmode.height(vidmode) : 600, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
glfwSetInputMode(windowHandler, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
GLContext.createFromCurrent();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
while (glfwWindowShouldClose(windowHandler) == GL_FALSE && !shouldStop) {
preRender();
Engine.getEngine().getPerformanceMonitor().fps++;
EventManager.getEventManager().dispatch(new RenderEvent());
postRender();
Engine.getEngine().getPerformanceMonitor().ips++;
}
Engine.getEngine().threadCleanup();
}
示例9: init
import org.lwjgl.opengl.GLContext; //导入方法依赖的package包/类
private void init() {
if (glfwInit() != GL_TRUE) {
System.err.println("Could not initialize GLFW!");
return;
}
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
window = glfwCreateWindow(width, height, "Flappy", NULL, NULL);
if (window == NULL) {
System.err.println("Could not create GLFW window!");
return;
}
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2);
glfwSetKeyCallback(window, new Input());
glfwMakeContextCurrent(window);
glfwShowWindow(window);
GLContext.createFromCurrent();
glEnable(GL_DEPTH_TEST);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
System.out.println("OpenGL: " + glGetString(GL_VERSION));
Shader.loadAll();
Matrix4f pr_matrix = Matrix4f.orthographic(-10.0f, 10.0f, -10.0f * 9.0f / 16.0f, 10.0f * 9.0f / 16.0f, -1.0f, 1.0f);
Shader.BG.setUniformMat4f("pr_matrix", pr_matrix);
Shader.BG.setUniform1i("tex", 1);
Shader.BIRD.setUniformMat4f("pr_matrix", pr_matrix);
Shader.BIRD.setUniform1i("tex", 1);
Shader.PIPE.setUniformMat4f("pr_matrix", pr_matrix);
Shader.PIPE.setUniform1i("tex", 1);
level = new Level();
}