當前位置: 首頁>>代碼示例>>Java>>正文


Java GLFW.glfwSetWindowSizeCallback方法代碼示例

本文整理匯總了Java中org.lwjgl.glfw.GLFW.glfwSetWindowSizeCallback方法的典型用法代碼示例。如果您正苦於以下問題:Java GLFW.glfwSetWindowSizeCallback方法的具體用法?Java GLFW.glfwSetWindowSizeCallback怎麽用?Java GLFW.glfwSetWindowSizeCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.lwjgl.glfw.GLFW的用法示例。


在下文中一共展示了GLFW.glfwSetWindowSizeCallback方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createWindow

import org.lwjgl.glfw.GLFW; //導入方法依賴的package包/類
protected void createWindow()
{
	// the window will stay hidden after creation
	GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);

	// Configure GLFW
	GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
	GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
	GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
	GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE,
			GLFW.GLFW_OPENGL_CORE_PROFILE);

	// Create the window
	this.handle = GLFW.glfwCreateWindow(this.width, this.height, this.title,
			MemoryUtil.NULL, MemoryUtil.NULL);
	if (this.handle == MemoryUtil.NULL)
	{
		throw new RuntimeException("Failed to create the GLFW window");
	}

	//Create the input context
	//this.inputEngine = new InputEngine(this);

	//Setup a size callback.
	GLFW.glfwSetWindowSizeCallback(this.handle, (window, w, h) ->
	{
		int prevW = this.width;
		int prevH = this.height;
		this.width = w;
		this.height = h;
		this.onWindowSizeChanged.notifyListeners(new int[]{
				this.width, this.height, prevW, prevH
		});
	});

	//Setup a position callback
	GLFW.glfwSetWindowPosCallback(this.handle, (window, xpos, ypos) -> {
		int prevX = this.x;
		int prevY = this.y;
		this.x = xpos;
		this.y = ypos;
		this.onWindowPosChanged.notifyListeners(new int[]{
				this.x, this.y, prevX, prevY
		});
	});

	this.makeWindowCentered();

	// Make the OpenGL context current
	GLFW.glfwMakeContextCurrent(this.handle);

	// Enable v-sync
	GLFW.glfwSwapInterval(this.vsync ? 1 : 0);

	// 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 GLCapabilities instance and makes the OpenGL
	// bindings available for use.
	GL.createCapabilities();

	System.out.println("OPENGL " + GL11.glGetString(GL11.GL_VERSION));

	// Set the clear color
	GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	//Enable depth testing
	GL11.glEnable(GL11.GL_DEPTH_TEST);

	//Set current viewport
	this.view = new View(this);
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:73,代碼來源:Window.java


注:本文中的org.lwjgl.glfw.GLFW.glfwSetWindowSizeCallback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。