Skip to main content
gamedev.net
🔒 Locked

Quick beginner problem

Started by sand_man 2 replies 750+ views
Original Post
sand_man
sand_man
when i set the x value of

glTranslatef(0.0f,0.0f,-1.0f);
lower than -1.0f, i cant see the polygon. when it is set to 1.0f and the polygon rotates away from the screen where the furthest part of the polygon disappears. It's like the screen isnt being rendered further out only close up. I'm not sure what is wrong with my code. Could it be because I'm using SDL to set it up?

#include <SDL/SDL.h>
#include <gl/gl.h>

#define scrX 1024
#define scrY 768
#define scrZ 32

SDL_Event event;

void init(void)
{
  SDL_Init(SDL_INIT_VIDEO);
  SDL_SetVideoMode(scrX, scrY, scrZ, SDL_OPENGL|SDL_HWSURFACE);

  glViewport(0, 0, scrX, scrY);
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClearDepth(1.0f);
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);
  glMatrixMode(GL_PROJECTION);
  glMatrixMode(GL_MODELVIEW);				
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void process(void)
{
  float spd = 0.0f;
  int done = 0;
  while(!done){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-1.0f);
    glRotatef(spd, 1.0f, 0.0f, 0.0f);

    glBegin(GL_TRIANGLES);
        glColor3f(1.0f,0.0f,0.0f);
        glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
        glColor3f(0.0f,1.0f,0.0f);
        glVertex3f(-1.0f,-1.0f, 1.0f);			// Left Of Triangle (Front)
        glColor3f(0.0f,0.0f,1.0f);
        glVertex3f( 1.0f,-1.0f, 1.0f);			// Right Of Triangle (Front)

        glColor3f(1.0f,0.0f,0.0f);
        glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
        glColor3f(0.0f,1.0f,0.0f);
        glVertex3f( 1.0f,-1.0f, 1.0f);			// Left Of Triangle (Right)
        glColor3f(0.0f,0.0f,1.0f);
        glVertex3f( 1.0f,-1.0f, -1.0f);			// Right Of Triangle (Right)
        
        glColor3f(1.0f,0.0f,0.0f);    
        glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
        glColor3f(0.0f,1.0f,0.0f);
        glVertex3f( 1.0f,-1.0f, -1.0f);			// Left Of Triangle (Back)
        glColor3f(0.0f,0.0f,1.0f);
        glVertex3f(-1.0f,-1.0f, -1.0f);			// Right Of Triangle (Back)
        
        glColor3f(1.0f,0.0f,0.0f);
        glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
        glColor3f(0.0f,1.0f,0.0f);
        glVertex3f(-1.0f,-1.0f,-1.0f);			// Left Of Triangle (Left)
        glColor3f(0.0f,0.0f,1.0f);
        glVertex3f(-1.0f,-1.0f, 1.0f);			// Right Of Triangle (Left)
    glEnd();

    spd += .05f;
    
    SDL_GL_SwapBuffers();
    SDL_PollEvent(&event);
    if(event.key.keysym.sym == SDLK_ESCAPE)
    done = 1;
  }
}

int main(int argc, char *argv[])
{
  init();
  process();

  SDL_Quit();
  return(0);
}

Thanks...
Ytinasni
Ytinasni
My guess would be that you're falling off the back of your z-buffer.
burst
burst
Hey man,

I'm pretty sure it's because you're not setting up your perspective. The function you need to call is gluPerspective(). I would suggest making a App_Resize() function that allows you to readjust your window coordinates every time the window resizes as well as your perspective. Check this out for a reference:

[SOURCE]bool CWcGL::GL_Resize(int _nWidth, int _nHeight){	glViewport(0, 0, _nWidth, _nHeight);					// Set the WcGL viewport															glMatrixMode(GL_PROJECTION);							// Set the GL Matrix mode to projection	glLoadIdentity();										// Set the identity matrix	GLfloat fAspect = (float)(_nWidth)/(float)(_nHeight);	// Calculate the aspect ratio of the width & height of the display	gluPerspective( 45.0f, fAspect, 0.1f, 200.0f );		// Set the display perspective	glMatrixMode( GL_MODELVIEW );							// Set the WcGL viewport	glLoadIdentity();										// Set the identity matrix	return true;}[/SOURCE]
[/source]

Hope This Helps

~Brian

[Edited by - burst on October 29, 2004 11:36:47 PM]
"One must learn to follow before one can lead."
sand_man
sand_man
Thanks guys


[Edited by - sand_man on October 30, 2004 12:05:44 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.