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


Java MemoryStack.stackPush方法代码示例

本文整理汇总了Java中org.lwjgl.system.MemoryStack.stackPush方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryStack.stackPush方法的具体用法?Java MemoryStack.stackPush怎么用?Java MemoryStack.stackPush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.lwjgl.system.MemoryStack的用法示例。


在下文中一共展示了MemoryStack.stackPush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTexture

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
/**
 * Loads a texture from a file at the specified path.
 *
 * @param path - File path of the texture file.
 *
 * @return A Texture built from the specified file.
 */
public static Texture loadTexture(String path) {
    ByteBuffer image;
    int width;
    int height;

    try (MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer comp = stack.mallocInt(1);

        // Load image using the STB library
        stbi_set_flip_vertically_on_load(false);
        image = stbi_load(path, w, h, comp, 4);

        if (image == null) {
            throw new RuntimeException("Failed to load a texture file! " +
                    stbi_failure_reason());
        }

        width = w.get();
        height = h.get();
    }

    return createTexture(width, height, image);
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:33,代码来源:Texture.java

示例2: updateViewPort

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
private void updateViewPort(ViewPort viewport)
{
	if (viewport == this.defaultViewPort)
	{
		//FIXME: This is a fix (hack?) for Mac's weird hack to scale windows for compatibility
		try (MemoryStack stack = MemoryStack.stackPush())
		{
			IntBuffer pWidth = stack.mallocInt(1);
			IntBuffer pHeight = stack.mallocInt(1);

			GLFW.glfwGetFramebufferSize(this.window.handle(), pWidth, pHeight);
			GL11.glViewport(0, 0, pWidth.get(0), pHeight.get(0));
		}
	}
	else
	{
		GL11.glViewport(viewport.getX(), viewport.getY(),
				viewport.getWidth(), viewport.getHeight());
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:21,代码来源:View.java

示例3: makeWindowCentered

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
public void makeWindowCentered()
{
	// Get the thread stack and push a new frame
	try (MemoryStack stack = MemoryStack.stackPush())
	{
		IntBuffer pWidth = stack.mallocInt(1); // int*
		IntBuffer pHeight = stack.mallocInt(1); // int*

		// Get the window size passed to glfwCreateWindow
		GLFW.glfwGetWindowSize(this.handle, pWidth, pHeight);

		this.width = pWidth.get(0);
		this.height = pHeight.get(0);

		// Get the resolution of the primary monitor
		GLFWVidMode vidmode = getCurrentVideoMode();

		// Center the window
		GLFW.glfwSetWindowPos(
				this.handle,
				this.x = ((vidmode.width() - this.width) / 2),
				this.y = ((vidmode.height() - this.height) / 2)
		);
	} // the stack frame is popped automatically
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:26,代码来源:Window.java

示例4: readVorbis

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
private ShortBuffer readVorbis(String resource, int bufferSize, STBVorbisInfo info) throws Exception {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        vorbis = Utils.ioResourceToByteBuffer(resource, bufferSize);
        IntBuffer error = stack.mallocInt(1);
        long decoder = stb_vorbis_open_memory(vorbis, error, null);
        if (decoder == NULL) {
            throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
        }

        stb_vorbis_get_info(decoder, info);

        int channels = info.channels();

        int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);

        pcm = MemoryUtil.memAllocShort(lengthSamples);

        pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
        stb_vorbis_close(decoder);

        return pcm;
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:24,代码来源:SoundBuffer.java

示例5: Texture

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
public Texture(ByteBuffer image) {
	try (MemoryStack stack = MemoryStack.stackPush()) {
		IntBuffer w = stack.mallocInt(1);
           IntBuffer h = stack.mallocInt(1);
           IntBuffer avChannels = stack.mallocInt(1);

           ByteBuffer decodedImage = stbi_load_from_memory(image, w, h, avChannels, 4);

           this.width = w.get();
           this.height = h.get();

           this.id = glGenTextures();
           Loader.textures.add(id);
           glBindTexture(GL_TEXTURE_2D, this.id);

           glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
           glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage);
           glGenerateMipmap(GL_TEXTURE_2D);
	}
}
 
开发者ID:nickclark2016,项目名称:JavaGraphicsEngine,代码行数:24,代码来源:Texture.java

示例6: loadImage

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
/**
 * Loads an image from a file. Supported formats are
 * <ul>
 * <li>JPEG baseline &amp; progressive (12 bpc/arithmetic not supported, same as stock IJG lib</li>
 * <li>PNG 1/2/4/8-bit-per-channel (16 bpc not supported)</li>
 * <li>TGA (not sure what subset, if a subset)</li>
 * <li>BMP non-1bpp, non-RLE</li>
 * <li>PSD (composited view only, no extra channels, 8/16 bit-per-channel)</li>
 * <li>GIF (*comp always reports as 4-channel)</li>
 * <li>HDR (radiance rgbE format)</li>
 * <li>PIC (Softimage PIC)</li>
 * <li>PNM (PPM and PGM binary only)</li>
 * </ul>
 * @param path path to the file
 * @return {@link ImageData} with info about the image
 * @see org.lwjgl.stb.STBImage STBImage, image decoder
 */
public static ImageData loadImage(final File path) {
    ImageData data = new ImageData();
    try(MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer x = stack.ints(0),
                  y = stack.ints(0),
               comp = stack.ints(0);
        data.data = org.lwjgl.stb.STBImage.stbi_load(path.getAbsolutePath(), x, y, comp, 0);
        if(data.data == null) throw new RuntimeException(org.lwjgl.stb.STBImage.stbi_failure_reason());
        data.width = x.get();
        data.height = y.get();
        data.components = comp.get();
        data.clear = o -> {
            org.lwjgl.stb.STBImage.stbi_image_free(o.data);
            return null;
        };
    }
    return data;
}
 
开发者ID:melchor629,项目名称:Java-GLEngine,代码行数:36,代码来源:ImageIO.java

示例7: loadTexture

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
/**
 * Load texture from file.
 *
 * @param path File path of the texture
 *
 * @return Texture from specified file
 */
public static Texture loadTexture(String path) {
    ByteBuffer image;
    int width, height;
    try (MemoryStack stack = MemoryStack.stackPush()) {
        /* Prepare image buffers */
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer comp = stack.mallocInt(1);

        /* Load image */
        stbi_set_flip_vertically_on_load(true);
        image = stbi_load(path, w, h, comp, 4);
        if (image == null) {
            throw new RuntimeException("Failed to load a texture file!"
                                       + System.lineSeparator() + stbi_failure_reason());
        }

        /* Get width and height of image */
        width = w.get();
        height = h.get();
    }

    return createTexture(width, height, image);
}
 
开发者ID:SilverTiger,项目名称:lwjgl3-tutorial,代码行数:32,代码来源:Texture.java

示例8: setUniform

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
/**
 * Sets the uniform variable at the specified location.
 *
 * @param location - Uniform location.
 * @param value - Value to set at the specified location.
 */
public void setUniform(String location, Matrix4f value) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        FloatBuffer floatBuffer = stack.mallocFloat(4*4);
        value.get(floatBuffer);
        glUniformMatrix4fv(uniformLocations.get(location), false, floatBuffer);
    }
}
 
开发者ID:brokenprogrammer,项目名称:Mass,代码行数:14,代码来源:ShaderProgram.java

示例9: setUniform

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
public void setUniform(String uniformName, Matrix4fc matrix)
{
	try (MemoryStack stack = MemoryStack.stackPush())
	{
		FloatBuffer fb = stack.mallocFloat(16);
		matrix.get(fb);
		GL20.glUniformMatrix4fv(this.findUniformLocation(uniformName), false, fb);
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:10,代码来源:Program.java

示例10: apply

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
@Override
public void apply(Program program, Matrix4fc value)
{
	int location = program.findUniformLocation(this.getName());
	try (MemoryStack stack = MemoryStack.stackPush())
	{
		FloatBuffer fb = stack.mallocFloat(16);
		value.get(fb);
		GL20.glUniformMatrix4fv(location, false, fb);
	}
}
 
开发者ID:andykuo1,项目名称:candlelight,代码行数:12,代码来源:PropertyMat4.java

示例11: setUniform

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
public void setUniform(String uniformName, Matrix4f value) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        // Dump the matrix into a float buffer
        FloatBuffer fb = stack.mallocFloat(16);
        value.get(fb);
        glUniformMatrix4fv(uniforms.get(uniformName), false, fb);
    }
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:9,代码来源:ShaderProgram.java

示例12: setUniform

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
public void setUniform(String uniformName, Matrix4f[] matrices) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        int length = matrices != null ? matrices.length : 0;
        FloatBuffer fb = stack.mallocFloat(16 * length);
        for (int i = 0; i < length; i++) {
            matrices[i].get(16 * i, fb);
        }
        glUniformMatrix4fv(uniforms.get(uniformName), false, fb);
    }
}
 
开发者ID:lwjglgamedev,项目名称:lwjglbook,代码行数:11,代码来源:ShaderProgram.java

示例13: setUniform

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
/**
 * Sets the uniform variable for specified location.
 *
 * @param location Uniform location
 * @param value    Value to set
 */
public void setUniform(int location, Matrix4f value) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        FloatBuffer buffer = stack.mallocFloat(4 * 4);
        value.toBuffer(buffer);
        glUniformMatrix4fv(location, false, buffer);
    }
}
 
开发者ID:SilverTiger,项目名称:lwjgl3-tutorial,代码行数:14,代码来源:ShaderProgram.java

示例14: getDPI

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
@Override
public double getDPI() {
    try(MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer width = stack.ints(0), height = stack.ints(0);
        glfwGetMonitorPhysicalSize(glfwGetPrimaryMonitor(), width, height);
        GLFWVidMode mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        return mode.width() / (width.get(0) / 25.4);
    }
}
 
开发者ID:melchor629,项目名称:Java-GLEngine,代码行数:10,代码来源:LWJGLWindow.java

示例15: getWindowSize

import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
@Override
public Size getWindowSize() {
    try(MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer width = stack.ints(0), height = stack.ints(0);
        glfwGetWindowSize(window, width, height);
        return new Size(width.get(), height.get());
    }
}
 
开发者ID:melchor629,项目名称:Java-GLEngine,代码行数:9,代码来源:LWJGLWindow.java


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