Jump to content
  • Advertisement
Sign in to follow this  
nicmenz

glFrustum doesn't work?

This topic is 4011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! I want to change the parameters of glFrustum () at run-time using keyboard input. I call the glCanvas.repaint () method after a key was pressed to update the screen. However, my problem is: No matter what value I change, the Utah-Teapot remains unchanged 8( What do I wrong? My Display () method: GL gl = d.getGL (); gl.glClear (GL.GL_COLOR_BUFFER_BIT); //gl.glMatrixMode(GL.GL_PROJECTION); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); gl.glFrustum (m_fLeft, m_fRight, m_fBottom, m_fTop, m_fNear, m_fFar); gl.glEnd (); gl.glFlush (); This is how I initialize the values: private static float m_fLeft = -1f; private static float m_fRight = 1f; private static float m_fBottom = 1f; private static float m_fTop = -1f; private static float m_fNear = 1f; private static float m_fFar = 5f; Is it right to initialize those values from -1 to +1? I read that near and far values have to be positive. But when they are positive, the screen remains empty. When I change them to be negative, I see an object, but it remains unchanged whatever values I use *desperate* Thanks alot, Nick

Share this post


Link to post
Share on other sites
Advertisement
Near and far clip plane values are the distance along the negative Z-axis where you want the clip planes. Meaning if you specify the clip planes at 1 and 5, the visible depth range is -1 to -5.

The code you posted though makes no sense to me. Calling glFrustum just before glEnd suggests you have a glBegin somewhere before that, but calling glFrustum, or any other matrix function, within a glBegin/glEnd pair is not valid. Also, calling glFlush right after glEnd suggests it's at the end of the drawing function, which means any previous drawing won't be affected by whatever change you make after it has been drawn.

Is that really the correct code? I don't see where you draw anything at all, so difficult to say really. Post the real code.

Share this post


Link to post
Share on other sites
hi,

sorry for the crappy code, here's the whole program (whichs draws *nothing*)


public class Frustrum extends JFrame implements
GLEventListener,
KeyListener
{
private static float m_fWidth = 800f;
private static float m_fHeight = 600f;
private static GLCanvas m_glCanvas = new GLCanvas ();
@SuppressWarnings ("unused")
private static GLUT m_glGlut = new GLUT ();
@SuppressWarnings ("unused")
private static GLU m_glGlu = new GLU ();

private static float m_fLeft = -1f;
private static float m_fRight = 1f;
private static float m_fBottom = 1f;
private static float m_fTop = -1f;
private static float m_fNear = 1f;
private static float m_fFar = 5f;

// ----------------------------------------------------------------------------
Frustrum ()
{
super ("Virtueller Trackball");
}
// ----------------------------------------------------------------------------
private void run (String[] args)
{
setTitle ("Aufgabe 1");
setSize ((int)m_fWidth, (int)m_fHeight);
setLocation (0, 0);
setUndecorated (false);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

m_glCanvas.addGLEventListener (this);
m_glCanvas.addKeyListener (this);
getContentPane ().add (m_glCanvas);

setVisible (true);
}
// ----------------------------------------------------------------------------
public static void main (String[] args)
{
new Frustrum ().run (args);
}
// ----------------------------------------------------------------------------
public void init (GLAutoDrawable d)
{
GL gl = d.getGL ();
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
}
// ----------------------------------------------------------------------------
public void display (GLAutoDrawable d)
{
GL gl = d.getGL ();
gl.glClear (GL.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glFrustum (m_fLeft, m_fRight, m_fBottom, m_fTop, m_fNear, m_fFar);
m_glGlut.glutSolidTeapot(0.5);
gl.glFlush ();
}
// ----------------------------------------------------------------------------
public void reshape (GLAutoDrawable d, int x, int y, int w, int h)
{
}
// ----------------------------------------------------------------------------
public void displayChanged (GLAutoDrawable d, boolean b1, boolean b2)
{
}
// ----------------------------------------------------------------------------
@Override
public void keyPressed(KeyEvent e)
{
//System.out.println(e.getKeyChar());
final float STEP_SIZE = 0.1f;

switch (e.getKeyChar())
{
case 'n':
m_fNear -= STEP_SIZE;
break;
case 'f':
m_fFar -= STEP_SIZE;
break;
case 'l':
m_fLeft -= STEP_SIZE;
break;
case 'r':
m_fRight -= STEP_SIZE;
break;
case 'b':
m_fBottom -= STEP_SIZE;
break;
case 't':
m_fTop -= STEP_SIZE;
break;
case 'N':
m_fNear += STEP_SIZE;
break;
case 'F':
m_fFar += STEP_SIZE;
break;
case 'L':
m_fLeft += STEP_SIZE;
break;
case 'R':
m_fRight += STEP_SIZE;
break;
case 'B':
m_fBottom += STEP_SIZE;
break;
case 'T':
m_fTop += STEP_SIZE;
break;
default:
break;
}
String s = "";
s += "Left : " + m_fLeft + "\n";
s += "Right : " + m_fRight + "\n";
s += "Bottom: " + m_fBottom + "\n";
s += "Top : " + m_fTop + "\n";
s += "Near : " + m_fNear + "\n";
s += "Far : " + m_fFar + "\n";
System.out.println(s);
m_glCanvas.repaint();
}
// ----------------------------------------------------------------------------
@Override
public void keyReleased(KeyEvent e)
{
}
// ----------------------------------------------------------------------------
@Override
public void keyTyped(KeyEvent e)
{
}
}


Share this post


Link to post
Share on other sites
Your depth range is Z=[-1, -5], and you're drawing the teapot at Z=0 which is outside the depth range. Translate it -2 or -3 units along the Z-axis so it's within the depth range.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!