Complete newbie question about glTranslatef(...)

Here is the code I use :

#import "MyOpenGLView.h"

#include <OpenGL/gl.h>

@implementation MyOpenGLView

- (void) drawRect: (NSRect) bounds
{
    glClearColor( 0, 0, 0, 0 ) ;
    glClear( GL_COLOR_BUFFER_BIT ) ;
	
    glColor3f( 0.0f, 1.0f, 0.0f ) ;
	//glTranslatef(-1.5f, 0.0f, -6.0f);
	
    glBegin( GL_TRIANGLES ) ;
    {
        glVertex3f( -1.0f, 1.0f, 0.0f ) ;
        glVertex3f( 1.0f, 1.0f, 0.0f ) ;
        glVertex3f( 0.0f, -1.0f, 0.0f ) ;
    }
    glEnd() ;
	
    glFlush() ;
}

@end

Does anybody know why the triangle is no longer displayed as soon as I uncomment the glTranslatef(-1.5f, 0.0f, -6.0f); line ?

I apologize if this question seems completely trivial, I began OpenGL only a few days ago…

Thanks in advance

What’s your projection transform set to (via glMatrixMode( GL_PROJECTION ) )?

Possibilities:

  • The projection transform is set such that a z of -6 goes through the screen and past the camera.
  • The projection transform is set such that a z of -6 is farther out than the max z allowed and ends up clipped.
  • The projection transform is set such that -1.5 in the x direction is past the screen.
  • Combinations of the above 3. :slight_smile:

Quick way of finding out: try doing a glTranslatef with just one dimension at a time and see what you get.

–mcn

Well, first of all thanks for answering my post so quickly :smiley:
As to glMatrixMode(GL_PROJECTION), I have not used this function yet (I am using the Apple OpenGL tutorial with Xcode, that does not really bother to give details about OpenGL functions :frowning: )…
I tried to change the glTranslate() values one by one. glTranslatef(-1.5f, 0.0f, 0.0f) lets the triangle appear, while glTranslatef(0.0f, 0.0f, -6.0f) effectively makes it disappear :confused: What do I need to do now ?

Thanks for the answers

Unfortunately I don’t remember what the default transform is, but experiment with the Z value (try 0.5, -0.5, 1, -1, etc) and see what happens.

–mcn

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.