简体   繁体   English

在lwjgl / opengl中的3D场景上绘制2D叠加层

[英]Drawing a 2d overlay over a 3d scene in lwjgl/opengl

I'm trying to draw a hud that displays the fps of the application over the top of a 3d scene. 我试图绘制一个在3d场景顶部显示应用程序fps的外观。 I know the answer to this question has something to do with changing the initialization code, and switching it back. 我知道这个问题的答案与更改初始化代码并将其切换回有关。 You know, this stuff: 你知道,这些东西:

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);

This is the code i need to render the 2d part of the screen. 这是我需要渲染屏幕2d部分的代码。 On a related note, i'm having a hard time understanding what all of this code does, and haven't found a good resource on it. 与此相关的是,我很难理解所有这些代码的功能,也没有找到很好的资源。 Can anyone point me in the right direction. 谁能指出我正确的方向。 Most tutorials don't include the setup code, i think they assume people know what to use(But i don't!). 大多数教程不包含安装代码,我认为它们假设人们知道使用什么(但是我不知道!)。

I am using these methods: 我正在使用以下方法:

public static void make3D() {

    glPopAttrib();
    glPushAttrib(GL_ENABLE_BIT);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // FOV = Field of View
    // Aspect ration
    // zNear and zFar (Viewing range)
    gluPerspective(FOV,(float) SCREEN_WIDTH / SCREEN_HEIGHT,0.1f,1000f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}

For changing to 3D view, and 用于切换到3D视图,以及

public static void make2D() {

    glPopAttrib();
    glPushAttrib(GL_ENABLE_BIT);

    glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT,0,-1,1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}

for changing to 2D view. 用于更改为2D视图。

Java doesnt seem to have any problem with this, please correct me if i'm wrong ! Java似乎对此没有任何问题,如果我错了,请纠正我!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM