|
//---------------------------------------------------------------------------
#ifndef Unit8H
#define Unit8H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "TOpenGLAPPanel.h"
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class Tfm3D : public TForm
{
__published: // IDE-managed Components
TOpenGLAPPanel *OpenGLPanel1;
void __fastcall OpenGLPanel1Resize(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall OpenGLPanel1Paint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall Tfm3D (TComponent* Owner);
void __fastcall openglinit ();
void __fastcall openglresize();
};
//---------------------------------------------------------------------------
extern PACKAGE Tfm3D *fm3D;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit8.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "TOpenGLAPPanel"
#pragma resource "*.dfm"
Tfm3D *fm3D;
//---------------------------------------------------------------------------
__fastcall Tfm3D::Tfm3D(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall Tfm3D::openglinit()
{
glViewport(0,0,(GLsizei)OpenGLPanel1->Width,(GLsizei)OpenGLPanel1->Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( OpenGLPanel1->Height==0)
gluPerspective(45, (GLdouble)OpenGLPanel1->Width, 1.0, 2000.0);
else
gluPerspective(45, (GLdouble)OpenGLPanel1->Width/
(GLdouble)OpenGLPanel1->Height,1.0, 2000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glClearColor(0.0,0.0,0.0,1.0);
}
//---------------------------------------------------------------------------
void __fastcall Tfm3D::openglresize()
{
glViewport(0,0,(GLsizei)OpenGLPanel1->Width,(GLsizei)OpenGLPanel1->Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( OpenGLPanel1->Height==0)
gluPerspective(45, (GLdouble)OpenGLPanel1->Width, 1.0, 2000.0);
else
gluPerspective(45, (GLdouble)OpenGLPanel1->Width/(GLdouble)OpenGLPanel1->Height,1.0, 2000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//---------------------------------------------------------------------------
void __fastcall Tfm3D::OpenGLPanel1Resize(TObject *Sender)
{
openglresize();
}
//---------------------------------------------------------------------------
void __fastcall Tfm3D::FormCreate(TObject *Sender)
{
Show();
}
//---------------------------------------------------------------------------
int DrawGLScene(GLvoid) // Here's where we do all the drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen and depth buffer
glLoadIdentity(); // Reset the current modelview matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move left 1.5 units and into the screen 6.0
glBegin(GL_TRIANGLES); // Drawing using triangles
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top of triangle (front)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f(-1.0f,-1.0f, 1.0f); // Left of triangle (front)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f( 1.0f,-1.0f, 1.0f); // Right of triangle (front)
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top of triangle (right)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f( 1.0f,-1.0f, 1.0f); // Left of triangle (right)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f( 1.0f,-1.0f, -1.0f); // Right of triangle (right)
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top of triangle (back)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f( 1.0f,-1.0f, -1.0f); // Left of triangle (back)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f(-1.0f,-1.0f, -1.0f); // Right of triangle (back)
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top of triangle (left)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f(-1.0f,-1.0f,-1.0f); // Left of triangle (left)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f(-1.0f,-1.0f, 1.0f); // Right of triangle (left)
glEnd(); // Finished Drawing The Triangle
glLoadIdentity(); // Reset the current modelview matrix
glTranslatef(1.5f,0.0f,-6.0f); // Move right 1.5 units and into the screen 6.0
glColor3f(0.5f,0.5f,1.0f); // Set the color to blue one time only
glBegin(GL_QUADS); // Draw a quad
glColor3f(0.0f,1.0f,0.0f); // Set the color to green
glVertex3f( 1.0f, 1.0f,-1.0f); // Top right of the quad (top)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top left of the quad (top)
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom left of the quad (top)
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom right of the quad (top)
glColor3f(1.0f,0.5f,0.0f); // Set the color to orange
glVertex3f( 1.0f,-1.0f, 1.0f); // Top right of the quad (bottom)
glVertex3f(-1.0f,-1.0f, 1.0f); // Top left of the quad (bottom)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom left of the quad (bottom)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom right of the quad (bottom)
glColor3f(1.0f,0.0f,0.0f); // Set the color to red
glVertex3f( 1.0f, 1.0f, 1.0f); // Top right of the quad (front)
glVertex3f(-1.0f, 1.0f, 1.0f); // Top left of the quad (front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom left of the quad (front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom right of the quad (front)
glColor3f(1.0f,1.0f,0.0f); // Set the color to yellow
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom left of the quad (back)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom right of the quad (back)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top right of the quad (back)
glVertex3f( 1.0f, 1.0f,-1.0f); // Top left of the quad (back)
glColor3f(0.0f,0.0f,1.0f); // Set the color to blue
glVertex3f(-1.0f, 1.0f, 1.0f); // Top right of the quad (left)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top left of the quad (left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom left of the quad (left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom right of the quad (left)
glColor3f(1.0f,0.0f,1.0f); // Set the color to violet
glVertex3f( 1.0f, 1.0f,-1.0f); // Top right of the quad (right)
glVertex3f( 1.0f, 1.0f, 1.0f); // Top left of the quad (right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom left of the quad (right)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom right of the quad (right)
glEnd();
glFlush();
}
void __fastcall Tfm3D::OpenGLPanel1Paint(TObject *Sender)
{
DrawGLScene();
}
//---------------------------------------------------------------------------
|