修复我的 opengl 渲染功能

发布于 2024-12-09 01:54:02 字数 2702 浏览 0 评论 0原文

我将其用作 lwjgl 游戏渲染函数的一部分。它不会在屏幕上渲染任何内容,但我不知道出了什么问题。该程序已经绘制了一个高级的纹理立方体世界,这将是为了选择玩家正在查看的那个世界。这可能是我缺少的一些愚蠢的设置。我尝试在渲染循环的所有不同时间运行它,以及摆弄一些设置。空间坐标绝对是对的。

目前,我只是想让它在选定的立方体上渲染一个白色方块。

        GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    System.out.println("coords: "+left+" "+bottom+" "+back);
    GL11.glColor3f(255f, 255f, 255f);
    //left
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex3f(left, bottom, back);
    GL11.glVertex3f(left, bottom, front);
    GL11.glVertex3f(left, top, front);
    GL11.glVertex3f(left, top, back);
    //right
    GL11.glVertex3f(right, bottom, front);
    GL11.glVertex3f(right, bottom, back);
    GL11.glVertex3f(right, top, back);
    GL11.glVertex3f(right, top, front);
    //top
    GL11.glVertex3f(left, top, front);
    GL11.glVertex3f(right, top, front);
    GL11.glVertex3f(right, top, back);
    GL11.glVertex3f(left, top, back);
    //front
    GL11.glVertex3f(left, bottom, front);
    GL11.glVertex3f(right, bottom, front);
    GL11.glVertex3f(right, top, front);
    GL11.glVertex3f(left, top, front);
    //back
    GL11.glVertex3f(right, bottom, back);
    GL11.glVertex3f(left, bottom, back);
    GL11.glVertex3f(left, top, back);
    GL11.glVertex3f(right, top, back);
    //bottom
    GL11.glVertex3f(right, bottom, front);
    GL11.glVertex3f(left, bottom, front);
    GL11.glVertex3f(left, bottom, back);
    GL11.glVertex3f(right, bottom, back);
    GL11.glEnd();
    GL11.glPopMatrix();

以及我所有的初始化程序,其中一些在运行上面之前我禁用了,还有一些我省略了,因为它们很容易准备/反转。我无法发布完整的代码,因为它太长了,这个游戏的图形引擎已经在开发中。

    GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE,GL11.GL_MODULATE);
    GL11.glClearColor(0.47f,0.55f,1.0f, 0.0f); 
    GL11.glClearDepth(1.0f); 
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_ALPHA_TEST);
        GL11.glEnable( GL13.GL_MULTISAMPLE );
        GL11.glEnable( GL13.GL_SAMPLE_ALPHA_TO_COVERAGE );
        GL11.glAlphaFunc(GL11.GL_GREATER, (float) 0.01);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glTexParameterf( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

I'm using this as a portion of a rendering function for my lwjgl game. It doesn't render anything to the screen, but I can't figure out what's messed up. The program already draws an advanced world of textured cubes, this will be to select the one the player is looking at. It's probably some dumb setting I'm missing. I've tried running it at all different times of the rendering loop, as well as fiddling with a few settings. The spatial coordinates are definitely right.

At the moment, I'm just trying to get it to render a white square over the selected cubes.

        GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    System.out.println("coords: "+left+" "+bottom+" "+back);
    GL11.glColor3f(255f, 255f, 255f);
    //left
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex3f(left, bottom, back);
    GL11.glVertex3f(left, bottom, front);
    GL11.glVertex3f(left, top, front);
    GL11.glVertex3f(left, top, back);
    //right
    GL11.glVertex3f(right, bottom, front);
    GL11.glVertex3f(right, bottom, back);
    GL11.glVertex3f(right, top, back);
    GL11.glVertex3f(right, top, front);
    //top
    GL11.glVertex3f(left, top, front);
    GL11.glVertex3f(right, top, front);
    GL11.glVertex3f(right, top, back);
    GL11.glVertex3f(left, top, back);
    //front
    GL11.glVertex3f(left, bottom, front);
    GL11.glVertex3f(right, bottom, front);
    GL11.glVertex3f(right, top, front);
    GL11.glVertex3f(left, top, front);
    //back
    GL11.glVertex3f(right, bottom, back);
    GL11.glVertex3f(left, bottom, back);
    GL11.glVertex3f(left, top, back);
    GL11.glVertex3f(right, top, back);
    //bottom
    GL11.glVertex3f(right, bottom, front);
    GL11.glVertex3f(left, bottom, front);
    GL11.glVertex3f(left, bottom, back);
    GL11.glVertex3f(right, bottom, back);
    GL11.glEnd();
    GL11.glPopMatrix();

AND all my initializers, some of which i disabled before running the above, and some of which I omitted because they were easy to prepare/reverse. I can't post the full code because it is too long, the graphics engine for this game is HEAVY in development already.

    GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE,GL11.GL_MODULATE);
    GL11.glClearColor(0.47f,0.55f,1.0f, 0.0f); 
    GL11.glClearDepth(1.0f); 
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_ALPHA_TEST);
        GL11.glEnable( GL13.GL_MULTISAMPLE );
        GL11.glEnable( GL13.GL_SAMPLE_ALPHA_TO_COVERAGE );
        GL11.glAlphaFunc(GL11.GL_GREATER, (float) 0.01);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glTexParameterf( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沩ん囻菔务 2024-12-16 01:54:02
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glLoadIdentity();

您将模型视图矩阵重置为恒等,因此任何视图转换(对齐/定位“相机”)都会被覆盖。从技术上讲,您正在“默认”视图中进行绘制,并且您是否应该使用可能在查看体积范围之外的透视投影。

GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glLoadIdentity();

You're resetting the modelview matrix to identity, thus any view transformations (aligning/positioning "the camera") are overridden. Technically you're drawing in a "default" view and should you use a perspective projection probably outside the viewing volume's bounds.

左岸枫 2024-12-16 01:54:02

我自己解决了这个问题,我计算的坐标是错误的,但花了一段时间才弄清楚,因为它在游戏中看起来大部分都很好。

为了保护版权,我不得不在这里省略很多重要的代码,但我怀疑有人会发现我发现的错误。

I solved this myself, I was calculating coordinates wrong, but it took a while to figure that out since it appeared mostly fine ingame.

I had to leave out a lot of the important code here for sake of copyright, but I doubt anyone would have spotted the bug I found.

自此以后,行同陌路 2024-12-16 01:54:02

您启用纹理,但不为顶点提供任何纹理坐标。您也不给它们法线,所以我希望您不要启用照明。

根据您关于初始化程序的陈述(“其中一些我在运行上面之前禁用了,其中一些我省略了”),您确实应该发布渲染此立方体时 GL 所处的状态,或者在发布之前亲自检查它。您甚至可能在调整引擎所做的所有状态更改时自己发现错误。

一般来说,您应该从显式初始化代码中降级,并始终在渲染之前立即设置所需的所有状态,因为这可以防止出现您不知道 GL 实际处于哪个状态的奇怪情况。永远记住,OpenGL 是一个状态机。

You enable texturing, but don't give your vertices any texture coordinates. You also don't give them normals, so I hope you don't enable lighting.

Based on your statements about the initializers ("some of which i disabled before running the above, and some of which I omitted") you should really post the state in which the GL is when rendering this cube, or before posting check it yourself. It may be that you even find the error yourself when fiddling out all the state changes your engine makes.

In general you should rather degrade from explicit initialization code and always set all the states you need immediately before rendering, as this prevents such strange things where you don't know in which state the GL really is. Always remember, OpenGL is a state machine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文