PDA

View Full Version : Why doesnt this work? OpenGL code...



theduck
27-01-2005, 12:40 AM
why doesn't this work?
it dont rotate or change color!

//OPEN-GL TEMPLATE///////
//DUCK ENTERPRISES 2005//
//COLIN DRAKE////////////

Program Tutor02;

Uses GL, GLUT;




////////////////////////////////////////////////////////////////////////////////declaration of constants and variables
var rtri:Extended;
var myvar1:Extended;
var new_t:integer;
var done:integer;
////////////////////////////////////////////////////////////////////////////////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

if new_t=0 then
begin
myvar1:=1.0;
new_t:=1;
end;

//Reminder: To Create Tris, glB Flag is: GL_TRIANGLES
//Reminder: To Create Quads, glB Flag is: GL_QUADS

//clear the color buffer

glClear(GL_COLOR_BUFFER_BIT); //clear the screen or window

myvar1:=myvar1-0.01;
rtri:=rtri+1;

glRotatef(rtri,1.0,1.0,1.0);

//do some drawing
glBegin(GL_TRIANGLES); //draw something with 4 vertexes
glColor3f(myvar1,0.0,0.0); //color
glVertex3f(-0.8, -0.5, -2.0); //first vertex
glColor3f(0.0,0.0,myvar1); //color
glVertex3f(-0.0, 0.5, -2.0); //second vertex
glColor3f(0.0,myvar1,0.0); //color
glVertex3f( 0.8, -0.5, -2.0); //third vertex
glEnd; //thats 3 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

myvar1:=1.0;
//OpenGL and GLUT initialization
glutInit(@argc, argv);
glShadeModel(GL_SMOOTH);
glutCreateWindow('My First OpenGL Application');

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


////////////////////////////////////////////////////////////////////////////////MAIN LOOP
while done=0 do
begin
glutMainLoop; //<<Render...
glutDisplayFunc(@draw);
glutReshapeFunc(@reshape);
end;

End.

Paulius
27-01-2005, 08:54 AM
glutDisplayFunc only gets called when the window needs to be redrawn. You can call glutPostRedisplay tell glut that the window needs to be redisplayed.

theduck
29-01-2005, 01:56 AM
Ummm... it still doesn't work... :(

Robert Kosek
29-01-2005, 02:09 AM
Check your "D:\fpc\source\packages\extra\opengl\examples" directory for a GLUTDEMO. Be sure it's on your drive letter ... it works well. You need GLUT's DLL to run, in your directory.