PDA

View Full Version : Newb Question - OpenGL



theduck
25-01-2005, 10:38 PM
Hello,

I (FreePascal+OGL noob) can't get this tutorial to work!!!!!
Can anybody help me? The rotating doesn't work!!!!!!!

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

I have translated it into Pascal, and I can't get it to work... :(

I am using the FPC (FreePascal Compiler) and OpenGL for this.

I have been using this as a basic Template:
So it would be appreciated greatly if you could tell me where to put the rotating code in with my template.
(Nothing else compiles right for OpenGL templates... :'( ....)

//OPEN-GL TEMPLATE///////
//DUCK ENTERPRISES 2005/
//COLIN DRAKE//////////
//////////////////////
Program Tutor02;/////
////////////////////
Uses GL, GLUT;/////
//////////////////
//declaration of constants and variables


//program initialization



//misc



//list creation



//drawing
//
//
//callback
Procedure reshape(width, height : LongInt); stdcall;
Var aspect : glFloat;
Begin
aspect := width/height;
//setup new projection matrix which depends on window size
glMatrixMode(GL_PROJECTION); //switch to projection-matrix
glLoadIdentity; //setup standard matrix
glFrustum(-1.0*aspect, 1.0*aspect, 1.0, -1.0, 1.0, 20.0);//setup viewing matrix

glMatrixMode(GL_MODELVIEW); //switch back to the modelview-matrix
glLoadIdentity; //setup standard matrix
End;


//CREATE EVERYTHING
Procedure draw; stdcall;
Begin


//clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);

//do some drawing
glBegin(GL_QUADS); //draw something with 4 vertexes

glColor3f(1.0,0.0,0.0); //color
glVertex3f(-0.8, -0.5, -2.0); //first vertex

glColor3f(0.0,1.0,0.0); //color
glVertex3f(-0.0, 0.5, -2.0); //second vertex

glColor3f(0.0,0.0,1.0); //color
glVertex3f( 0.0, 0.5, -2.0); //...

glColor3f(0.0,1.0,0.0); //color
glVertex3f( 0.8, -0.5, -2.0);

glEnd; //thats four vertexes, so it draws it!!

glFlush; //tell OpenGL to flush internal buffers
//glSwapBuffers; //we actually don't use the double-buffer
End;


//START UP CODE
Begin
//OpenGL and GLUT initialization
glutInit(@argc, argv);
glutCreateWindow('My First OpenGL Application');

//callback registration
glutDisplayFunc(@draw);
glutReshapeFunc(@reshape);


//MAIN LOOP
//glutMainLoop
glutMainLoop;



End.



Thanks!

Paulius
25-01-2005, 11:13 PM
Every vertex you pass first gets transformed (multiplied) by the current modelview matrix. It is illegal to modify any OpenGl matrix inside a glbegin glend block, other then that you can put it wherever you want before passing verticies you want transformed as long as modelview matrix is selected.

theduck
26-01-2005, 02:40 AM
Thanks a lot! I got it now! 8) :P