Changing the Viewpoint - OpenGL and Cg

  • Follow


Hello Everyone,

I am new to OpenGL and Cg. I am trying to draw a triangle strip on the
screen.  The vertex program just gets the position, changes the color
of the triangle and renders it on the screen. It comes fine, except
that I am unable to change the position of the camera(viewpoint). The
gluLookAt() function doesn't seem to work.  Can anyone please tell me
what am I missing. Here's the code:

void Draw (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity ();							
        
        gluLookAt(0.0f, 0.0f, -200.0f, 0.0f, 0.0f, 0.0f, 0, 1, 0);

	cgGLEnableProfile(cgVertexProfile);					
	cgGLBindProgram(cgProgram);

	//gluLookAt(0.0f, 0.0f, -200.0f, 0.0f, 0.0f, 0.0f, 0, 1, 0); 
        // I tried inserting it in between the Cg enable and disable
profiles

	glColor3f(0.0f,0.0f,1.0f);
	glBegin(GL_TRIANGLE_STRIP);
		glVertex2f(0.1,0.0);
		glVertex2f(0.3,0.5);
		glVertex2f(0.5,0.0);
		glVertex2f(0.7,0.5);
	glEnd();
	
	cgGLDisableProfile(cgVertexProfile);

	glFlush ();
}

Thank you,

Sriram
0
Reply absriram 7/10/2004 1:46:35 AM

> Hello Everyone,
>
> I am new to OpenGL and Cg. I am trying to draw a triangle strip on the
> screen.  The vertex program just gets the position, changes the color
> of the triangle and renders it on the screen. It comes fine, except
> that I am unable to change the position of the camera(viewpoint). The
> gluLookAt() function doesn't seem to work.  Can anyone please tell me
> what am I missing. Here's the code:

>snip/
Hi Sriram,
Since Cg uses the pure/untransformed vertex-data ,you need to tell it inside
the vertex-program to transform the vertex-data via the MODELVIEW Matrix.
(for OpenGL you rather need the pure modelview matrix than the combined
modelview/projectionmatrix).
IIRC you have to upload it as a parameter to your vertex-program and apply
it inside of it.

you may wanna take a look at NeHe's Tut.47 to see how they managed it:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=47

hth psy


0
Reply Sebastian 7/10/2004 6:57:05 AM


1 Replies
285 Views

(page loaded in 0.034 seconds)

Similiar Articles:













7/18/2012 4:32:38 PM


Reply: