当前位置: 首页>>代码示例>>Java>>正文


Java GLContext.createFromCurrent方法代码示例

本文整理汇总了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);
   }
 
开发者ID:camilne,项目名称:open-world,代码行数:20,代码来源:Application.java

示例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);
}
 
开发者ID:DeadRunningOnTray,项目名称:Prepare4LudumDare,代码行数:19,代码来源:Game.java

示例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);
}
 
开发者ID:JulianThijssen,项目名称:Boids,代码行数:17,代码来源:Window.java

示例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);
}
 
开发者ID:dantetam,项目名称:civgame,代码行数:25,代码来源:DisplayManager.java

示例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();
}
 
开发者ID:BennyQBD,项目名称:2DPlatformer,代码行数:40,代码来源:OpenGLDisplay.java

示例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");
}
 
开发者ID:LoDoMa,项目名称:Lime,代码行数:29,代码来源:Window.java

示例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();
        }

    }
}
 
开发者ID:Diorite,项目名称:Diorite-old,代码行数:44,代码来源:Main.java

示例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();
}
 
开发者ID:spanishtech,项目名称:RGGE-Engine,代码行数:77,代码来源:Display.java

示例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();
}
 
开发者ID:TheCherno,项目名称:Flappy,代码行数:42,代码来源:Main.java


注:本文中的org.lwjgl.opengl.GLContext.createFromCurrent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。