Question

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;
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top