本文整理汇总了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);
}
示例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());
}
}
示例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
}
示例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;
}
}
示例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);
}
}
示例6: loadImage
import org.lwjgl.system.MemoryStack; //导入方法依赖的package包/类
/**
* Loads an image from a file. Supported formats are
* <ul>
* <li>JPEG baseline & 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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}