- var
- Mesh : TAll3DSMesh;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DC:= GetDC(Handle);
- Application.OnIdle:= IdleHandler;
- if not InitOpenGL then Application.Terminate;
- RC:= CreateRenderingContext( DC,
- [opDoubleBuffered],
- 32,
- 24,
- 0,0,0,
- 0);
- ActivateRenderingContext(DC, RC);
- SetupGL;
- Init;
- Mesh := TAll3DSMesh.Create(Nil);
- Mesh.LoadFromFile('mesh\Wuerfel.3DS');
- Mesh.TexturePath := 'mesh\tex';
- Counter := 0;
- end;
- procedure TForm1.Render;
- const
- mat_specular : Array[0..3] of GlFloat = (0.5, 0.5, 0.5, 0.5);
- mat_shininess : Array[0..0] of GlFloat = (1.0);
- mat_ambient : Array[0..3] of GlFloat = (0.7, 0.7, 0.7, 1.0);
- mat_diffuse : Array[0..3] of GlFloat = (0.7, 0.8, 0.7, 1.0);
- light_position : Array[0..3] of GlFloat = (2.0, 10.0, 4.0, 1.0);
- light_ambient : Array[0..3] of GlFloat = (0.9, 0.9, 0.9, 1.0);
- light_diffuse : Array[0..3] of GlFloat = (0.7, 0.7, 0.7, 1.0);
- begin
- //
- glMaterialfv(GL_FRONT, GL_SPECULAR, @mat_specular[0]);
- glMaterialfv(GL_FRONT, GL_SHININESS, @mat_shininess[0]);
- glMaterialfv(GL_FRONT, GL_AMBIENT, @mat_ambient[0]);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, @mat_diffuse[0]);
- glLightfv(GL_LIGHT0, GL_AMBIENT, @light_ambient[0]);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, @light_diffuse[0]);
- glLightfv(GL_LIGHT0, GL_POSITION, @light_position[0]);
- glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0);
- glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.001);
- glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.004);
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);
- glTranslatef(0, 0, -1.5);
- glRotatef(-(Counter/10),0,1,0);
- glRotatef(-80,1,0,0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity;
- glColor3f(1.0,1.0,1.0);
- Mesh.Render;
- SwapBuffers(DC);
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- DeactivateRenderingContext;
- DestroyRenderingContext(RC);
- ReleaseDC(Handle, DC);
- Mesh.Destroy;
- end;