0

I need help with gluLookAt(). I'm trying to use it after my call to glOrtho() (which I believe is correct) in an attempt to make a view down the z axis from a slightly elevated view on the y axis. From what I understand of gluLookAt() the first three parameters are where the view is from or the "eye" and the next three are where the eye is looking with the last three being the angle of view?

I have tried a lot of different settings and cannot get anything to render on the screen whatsoever and all attempts have resulted in a blank black screen. I have searched the web for whole examples in practice of its usage and cannot find anything but explanations of the function (which I think I understand but can't get to work).

I'm not going to post any of the code that I've tried because there's too many different methods that I've tried and now I'm left with a total mess of code and quite frankly I don't want to make anyones eyes bleed.

My question is, could anybody post or describe better an example of a small program that uses gluLookAt() which works

Here is the god awful code I have currently (it's only for testing):

#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <GL/glu.h>
#include <windows.h>

void init_ortho(int width, int height)

{

SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(width,height,32,SDL_OPENGL);
SDL_WM_SetCaption( "OpenGL Test", NULL );

glClearColor( 0, 0, 0, 0 );
glViewport(0, 0, 640, 480);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, width , height , 0, 0, 20 );
glMatrixMode( GL_MODELVIEW );
gluLookAt(0,0,0, 300,300, 5, 0,1,0);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);

}

int Check(int keystroke, int x)

{

if (keystroke == 65)
x += 10;

return x;

}

int main(int argc, char **argv)
{
init_ortho(640, 480);

glLoadIdentity();

int x = 300;
bool quit = false;

while (quit == false)

{

for (int i = 0; i < 300; i++)
{



if (GetAsyncKeyState(i) == -32767)
{

    x = Check(i, x);
if (x > 400)
quit = true;
    glTranslatef(x,300,10);
glColor4f(1.0,1.0,1.0,1.0);

glBegin(GL_QUADS);
glVertex3f(0,  0,0);
glVertex3f(100, 0,0);
glVertex3f(100,100,0);
glVertex3f(0, 100,0);
glEnd();

glLoadIdentity();

SDL_GL_SwapBuffers();

glClear( GL_COLOR_BUFFER_BIT );

}
}

}



SDL_Quit();

return 0;
}

1 Answers1

0

with the last three being the angle of view?

Wrong. The last parameters define in which direction the camera is "upright". Imagine a camera where you put a stick on top of it. That stick on top of it is the up vector.


Sorry to tell you this, but: The way you're doing all this is awfully wrong.

First you don't have a propper event processing loop. You need to call SDL_WaitEvent or SDL_PollEvent somewhere. Also it makes absolutely no sense to have a for 0...300 loop within the programs main loop for some animation.

Then your gluLookAt will create a view transformation that will make look edge on the rendered triangle.

There's no way to fix the code. I say start from scratch, and take a proper tutorial.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • I know this code is mostly garbage, my only concern is getting gluLookAt() to actually look at something other than a blank screen, I know I am doing that wrong in the code but I don't know how –  Dec 17 '11 at 13:29
  • Thanks for the answer, is there no way I can get gluLookAt() to work in this piece of code at all? –  Dec 17 '11 at 14:32
  • @Michael: gluLookAt is the least of your problems. You need to completely restructure your code, otherwise you'll have a hard time to have something show up properly at all. – datenwolf Dec 17 '11 at 14:44
  • If I take the call to gluLookAt() out of the code I get a quad which moves across the screen when I press the letter 'A' (when translation in the z direction is 0 -10) for the drawing of the quad –  Dec 17 '11 at 14:48
  • I've made some decent programs using SDL and OpenGL following the Lazyfoo tutorials. I just wish there was some decent tutorial or even example program I could find that uses gluLookAt() –  Dec 17 '11 at 15:04
  • @Michael: Your problem is the following: Your view pivot point is 0,0,0, and you're lokking to 300,300,5. However that ortho viewing volume is asymmetric: That 300,300,5 will be in the lower left corner of the screen. The way your triangle is placed, it will be outside the viewing volume for most of the time. – datenwolf Dec 17 '11 at 15:16
  • I see, so setting gluLookAt(300,300,0, 0,0,5, 0,0,0); should work? I've tried this and it doesn't seem to work. I'm going to start from scratch again with the NeHe tutorials. Thanks for the help –  Dec 17 '11 at 15:54