Main Page   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

MDICuberille.cpp

00001 //---------------------------------------------------------------------------
00002 
00003 #include <vcl.h>
00004 #pragma hdrstop
00005 
00006 #include "MDICuberille.h"
00007 #include "MDIEdit.h"
00008 #include "MDIFrame.h"
00009 //---------------------------------------------------------------------------
00010 #pragma package(smart_init)
00011 #pragma resource "*.dfm"
00012 TCuberilleForm *CuberilleForm;
00013 //---------------------------------------------------------------------------
00014 __fastcall TCuberilleForm::TCuberilleForm(TComponent* Owner)
00015         : TForm(Owner)
00016 {
00017 }
00018 //---------------------------------------------------------------------------
00019 void __fastcall TCuberilleForm::SetPixelFormatDescriptor()
00020 {
00021     PIXELFORMATDESCRIPTOR pfd = {
00022         sizeof(PIXELFORMATDESCRIPTOR),
00023         1,
00024         PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
00025         PFD_TYPE_RGBA,
00026         24,
00027         0,0,0,0,0,0,
00028         0,0,
00029         0,0,0,0,0,
00030         32,
00031         0,
00032         0,
00033         PFD_MAIN_PLANE,
00034         0,
00035         0,0,
00036     };
00037     PixelFormat = ChoosePixelFormat(hdc, &pfd);
00038     SetPixelFormat(hdc, PixelFormat, &pfd);
00039 }
00040 
00041 //---------------------------------------------------------------------
00042 void __fastcall TCuberilleForm::FormClose(TObject *Sender, TCloseAction &Action)
00043 {
00044 Action=caFree;
00045 FrameForm->Cuberille->Checked = false;
00046 }
00047 //---------------------------------------------------------------------
00048 void __fastcall TCuberilleForm::FormCreate(TObject *Sender)
00049 {
00050     int i,a;
00051 
00052     hdc = GetDC(Handle);
00053     SetPixelFormatDescriptor();
00054     hrc = wglCreateContext(hdc);
00055     if(hrc == NULL) ShowMessage("Could not create DC!");
00056     wglMakeCurrent(hdc, hrc);
00057 
00058     w = ClientWidth;
00059     h = ClientHeight;
00060 
00061     glEnable(GL_DEPTH_TEST);
00062     glEnable(GL_CULL_FACE);
00063 
00064     glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
00065     glOrtho (-50.0,50.0,-50.0,50.0,-50.0,50.0);
00066 
00067     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00068     glFlush();
00069     SwapBuffers(hdc);
00070     FormResize(Sender);
00071 }
00072 //---------------------------------------------------------------------
00073 void __fastcall TCuberilleForm::FormResize(TObject *Sender)
00074 {
00075         PrepareGLWindow();
00076         PaintGL();
00077 }
00078 //---------------------------------------------------------------------------
00079 void __fastcall TCuberilleForm::FormPaint(TObject *Sender)
00080 {
00081         PaintGL();
00082 }
00083 //---------------------------------------------------------------------------
00084 void __fastcall TCuberilleForm::PaintGL()
00085 {
00086         float i;
00087 
00088         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00089         PrepareGLWindow();
00090         glColor3f(0.6f,0.6f,0.6f);
00091         glLineWidth(3.0f);
00092         glBegin(GL_LINE_STRIP);
00093         glVertex3f(-50,-50,0);
00094         glVertex3f(50,-50,0);
00095         glVertex3f(50,50,0);
00096         glVertex3f(-50,50,0);
00097         glVertex3f(-50,-50,0);
00098         glEnd();
00099 
00100 
00101 //        glDrawPixels(sizeX, sizeY, GL_RGB, GL_UNSIGNED_BYTE,
00102 //                     color+(sizeX*sizeY*TrackBar->Position));
00103                         // we use unsigned byte (char) to meet speed issues.
00104                         // 16 bit data (__int16) slows down drawing to much.
00105 
00106         glFlush();
00107         SwapBuffers(hdc);
00108 }
00109 
00110 void __fastcall TCuberilleForm::PrepareGLWindow()
00111 {
00112         wglMakeCurrent(hdc, hrc);
00113 
00114         GLfloat nRange = 50.0;
00115 
00116         w = ClientWidth-200;
00117         h = ClientHeight;
00118 
00119         if(h == 0) h = 1;
00120         if(w == 0) w = 1;
00121 
00122         glViewport(200, 0, w, h);
00123 
00124         glMatrixMode(GL_PROJECTION);
00125         glLoadIdentity();
00126 
00127         if (w <= h)
00128         {        glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
00129                 glPixelZoom((float)w/(float)sizeX, (float)w/(float)sizeY);}
00130          else
00131         {        glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
00132                 glPixelZoom((float)h/(float)sizeX, (float)h/(float)sizeY);}
00133 
00134         glRasterPos2d(-50,-50);
00135         glMatrixMode(GL_MODELVIEW);
00136         glLoadIdentity();
00137 }
00138 //---------------------------------------------------------------------------
00139 
00140 void __fastcall TCuberilleForm::FormActivate(TObject *Sender)
00141 {
00142         PaintGL();        
00143 }
00144 //---------------------------------------------------------------------------
00145 

Generated on Thu Jan 23 06:17:37 2003 for Vol by doxygen1.2.18