1
\$\begingroup\$

I've written a basic program so I can make sure I'm properly learning VBOs before converting my 3d game's rendering to them.

Essentially, this question is why changing the perspective is the GL setup code stops my triangle from rendering:

GLU.gluPerspective(60f, (width/height), 0.1f, 200.0f);

Wihout that code, the triangle renders as expected. With it, only an empty screen is visible. I tried changing the triangle vertices but nothing worked. This may help explain why the VBO rendering isn't working in my game.

I've spent more time reading about gluPerspective but I'm not catching why it prevents the images from rendering.

My display/gl init code:

// Init display
Display.setResizable(true);
Display.setTitle( Game.name );
Display.setVSyncEnabled(true);
Display.setDisplayMode(new DisplayMode(Game.GAME_WIDTH, Game.GAME_HEIGHT));

// Set viewport
PixelFormat pixelFormat = new PixelFormat();
ContextAttribs contextAtrributes = new ContextAttribs(3, 0);
Display.create(pixelFormat, contextAtrributes);
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

GLU.gluPerspective(60f, ((float) Display.getWidth() / (float) Display.getHeight()), 0.1f, 200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

I have a simple triangle drawing class that uses and interleaved VBO

triangleTesselator.addVertex(-0.5f, -0.5f, 0f);
triangleTesselator.addColor(1, 0, 0);

triangleTesselator.addVertex(+0.5f, -0.5f, 0f);
triangleTesselator.addColor(0, 1, 0);

triangleTesselator.addVertex(+0.5f, +0.5f, 0f);
triangleTesselator.addColor(0, 0, 1);

triangleTesselator.render();

I also tried several different vertex coords thinking the 0 was behind the clipping (near) plane of the perspective but that didn't work.

Update: I've added a basic camera system to this rendering test app, and after looking around a bit I've found the rendered cube behind me...

\$\endgroup\$
2
  • \$\begingroup\$ Can you provide any other code? With this I can't see what GL capabilities you are using, which may or may not make a difference. \$\endgroup\$
    – Pandacoder
    Commented Dec 7, 2013 at 8:07
  • \$\begingroup\$ Added the rest of my gl init code to the question \$\endgroup\$
    – BotskoNet
    Commented Dec 7, 2013 at 8:09

1 Answer 1

0
\$\begingroup\$

Ok, I can't get your triangle tessellator to work for me at all, but that doesn't mean it doesn't work.

The issue I see is that it is outside your view. Your perspective's near plane is at 0.1f, and you are trying to draw at 0. You need to translate -z (-1 for example), and that should make it visible again.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks, I discovered the same few pieces of info as you did. The coords had the square/triangle rendering behind me. \$\endgroup\$
    – BotskoNet
    Commented Dec 7, 2013 at 8:25
  • \$\begingroup\$ P.S. the tesselator class doesn't actually tesselate anything in this stripped down demo of mine, just trying to prove my VBO code works before continuing replacing my game renderer (the real tesselator! heh) with it \$\endgroup\$
    – BotskoNet
    Commented Dec 7, 2013 at 8:27
  • \$\begingroup\$ Go figure. I actually went and threw in some immediate mode code to test the Z idea I got. \$\endgroup\$
    – Pandacoder
    Commented Dec 7, 2013 at 8:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .