Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在GLFW Open Gl中,当屏幕拉伸时,其创建的帧缓冲区大小不会改变_Java - Fatal编程技术网

Java 在GLFW Open Gl中,当屏幕拉伸时,其创建的帧缓冲区大小不会改变

Java 在GLFW Open Gl中,当屏幕拉伸时,其创建的帧缓冲区大小不会改变,java,Java,我有一个关于帧缓冲区的问题。我正在使用LWJGL2库用java编写一个项目。此时,将在display.class中创建显示。就在这里,当你创建自己的帧缓冲区,我在上面渲染阴影贴图时,当你拉伸窗口时,屏幕会改变缓冲区帧的大小。而且,所有这些都与帧缓冲一起工作,用于水的反射和折射。但是当我切换到LWJGL3时,我使用GLFW库创建了一个显示。默认的帧缓冲区通常会改变帧缓冲区的大小,这是当我运行自己的水或阴影帧缓冲区时,我让整个场景不会改变这个帧缓冲区的from大小 据我所知,新的帧缓冲区在解压时的屏

我有一个关于帧缓冲区的问题。我正在使用LWJGL2库用java编写一个项目。此时,将在display.class中创建显示。就在这里,当你创建自己的帧缓冲区,我在上面渲染阴影贴图时,当你拉伸窗口时,屏幕会改变缓冲区帧的大小。而且,所有这些都与帧缓冲一起工作,用于水的反射和折射。但是当我切换到LWJGL3时,我使用GLFW库创建了一个显示。默认的帧缓冲区通常会改变帧缓冲区的大小,这是当我运行自己的水或阴影帧缓冲区时,我让整个场景不会改变这个帧缓冲区的from大小

据我所知,新的帧缓冲区在解压时的屏幕大小与原来的分辨率相同。据推测,最初的屏幕分辨率是960x540,我需要解除这个权限,他说

无论我为什么添加帧缓冲区,它在拉伸时始终不会测量大小

Im尝试使用GLFW getFramebufferSize:

   public void resizeFramebuffer(int width, int height)
   {
         IntBuffer framebufferSize = BufferUtils.createIntBuffer(2);
         GLFW.nglfwGetFramebufferSize(this.window, MemoryUtil.memAddress(framebufferSize),MemoryUtil.memAddress(framebufferSize + 4);
         width = framebufferSize.get(0);
         height = framebufferSize.get(1);
         GlHelper.glViewport(0, 0, width, height);
   }
但它在默认帧缓冲区上工作。 如果有人想要,这里是我的阴影帧缓冲区对象:

        public class ShadowFrameBuffer extends FrameBuffer
        {
            private final int WIDTH;
            private final int HEIGHT;
            private int fbo;
            private int shadowMap;

            /**
             * Initialises the frame buffer and shadow map of a certain size.
             */
            public ShadowFrameBuffer(long windowId, int width, int height) 
            {
                super(windowId, width, height); 
                this.WIDTH = width;
                this.HEIGHT = height;
                this.initialiseFrameBuffer();
            }

            /**
             * Deletes the frame buffer and shadow map texture when the game closes.
             */
            @Override
            public void cleanUp() 
            {
                GlHelper.glDeleteFramebuffers(fbo);
                GlHelper.glDeleteTextures(shadowMap);
            }

            /**
             * @return The ID of the shadow map texture.
             */
            public int getShadowMap() 
            {
                return shadowMap;
            }

            /**
             * Binds the frame buffer, setting it as the current render target. Anything
             * rendered after this will be rendered to this FBO, and not to the screen.
             */
            public void bindDrawFrameBuffer()
            {
                if(GlHelperError.isFramebufferSupported())
                {
                    TextureManager.bindTexture2d(0);
                    GlHelper.glBindFramebuffers(Framebuffer.FRAMEBUFFER, fbo);
                    GlHelper.glViewport(0, 0, WIDTH, HEIGHT);
                }
            }

            /**
             * Creates the frame buffer and adds its depth attachment texture.
             */
            public void initialiseFrameBuffer() 
            {
                this.fbo = createFrameBuffer();
                this.shadowMap = createDepthBufferAttachment(WIDTH, HEIGHT);
                this.unbindFrameBuffer();
            }

            /**
             * Creates a frame buffer and binds it so that attachments can be added to
             * it. The draw buffer is set to none, indicating that there's no colour
             * buffer to be rendered to.
             * 
             * @return The newly created frame buffer's ID.
             */
            public static int createFrameBuffer() 
            {
                int frameBuffer = GlHelper.glGenFramebuffers();
                GlHelper.glBindFramebuffers(Framebuffer.FRAMEBUFFER, frameBuffer);
                GlHelper.glDrawBuffers(Framebuffer.NONE);
                GlHelper.glReadBuffer(Framebuffer.NONE);
                return frameBuffer;
            }

            /**
             * Creates a depth buffer texture attachment.
             * 
             * @param width - the width of the texture.
             * @param height - the height of the texture.
             * @return The ID of the depth texture.
             */
            private static int createDepthBufferAttachment(int width, int height) 
            {
                int texture = GlHelper.glGenTextures();
                TextureManager.bindTexture2d(texture);
                GlHelper.glTexImage2D(0, Depth.DEPTH_COMPONENT16, width, height, 0,
                        Depth.DEPTH_COMPONENT, Texture.FLOAT, (ByteBuffer) null);
                GlHelper.glTexParameteri(Texture.TEXTURE_MAG_FILTER, Texture.NEAREST);
                GlHelper.glTexParameteri(Texture.TEXTURE_MIN_FILTER, Texture.NEAREST);
                GlHelper.glTexParameteri(Texture.TEXTURE_WRAP_S, Texture.CLAMP_TO_EDGE);
                GlHelper.glTexParameteri(Texture.TEXTURE_WRAP_T, Texture.CLAMP_TO_EDGE);
                GlHelper.glFramebufferTexture(Framebuffer.FRAMEBUFFER, Depth.DEPTH_ATTACHMENT, texture, 0);
                return texture;
            }
        }
如果有人不知道什么是GlHelper,那么这个类中几乎所有的opengl方法都连接到一个类,以便不编写GL11、12、30等。当然,还有一些实用程序


请帮助力所能及的人。我将非常感激。我自己也不是开Gl的新手,但我遇到了这个问题。

我发现了我的错误所在。我使用了GLFW.nglfwGetFramebufferSize(),它获取的是屏幕上的缓冲帧大小,而不是屏幕本身。我应该使用GLFW.glfwGetWindowsSize(),这就是它的工作原理。如果任何人有相同的问题,请参阅完整代码:

public void resize()
{
    IntBuffer bufferedWidth = BufferUtils.createIntBuffer(1);
    IntBuffer bufferedHeight = BufferUtils.createIntBuffer(1);
    GLFW.glfwGetWindowSize(this.windowId, bufferedWidth, bufferedHeight);
}
然后,在对显示场景的缓冲区帧进行解耦时,需要从保存的缓冲区宽度和高度添加参数:

public void unbindFrameBuffer()
{
    Gl30.glBindFramebuffers(Framebuffer.FRAMEBUFFER, 0);
    Gl11.glViewport(0, 0, bufferedWidth.get(0), bufferedHeight.get(0));
}

我们需要确保所有这些操作都在一个while循环中进行。

我发现了我的错误所在。我使用了GLFW.nglfwGetFramebufferSize(),它获取的是屏幕上的缓冲帧大小,而不是屏幕本身。我应该使用GLFW.glfwGetWindowsSize(),这就是它的工作原理。如果任何人有相同的问题,请参阅完整代码:

public void resize()
{
    IntBuffer bufferedWidth = BufferUtils.createIntBuffer(1);
    IntBuffer bufferedHeight = BufferUtils.createIntBuffer(1);
    GLFW.glfwGetWindowSize(this.windowId, bufferedWidth, bufferedHeight);
}
然后,在对显示场景的缓冲区帧进行解耦时,需要从保存的缓冲区宽度和高度添加参数:

public void unbindFrameBuffer()
{
    Gl30.glBindFramebuffers(Framebuffer.FRAMEBUFFER, 0);
    Gl11.glViewport(0, 0, bufferedWidth.get(0), bufferedHeight.get(0));
}

我们需要确保所有这些操作都在while循环中进行。

只是一个提示,不要使用
BufferUtils
,更喜欢
MemUtils
MemUtils
之间的区别是什么?只是一个提示,不要使用
BufferUtils
,首选
MemUtils
缓冲utils和
MemUtils
之间的区别是什么?