677 679














Open GL Super Bible:Visual Basic and 4GL-Based OpenGL Programming















To access the contents, click the chapter and section titles.


Open GL Super Bible


(Publisher: Macmillan Computer Publishing)

Author(s): Waite group Press

ISBN: 1571690735

Publication Date: 08/01/96



function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)==
'4')
); }
function
bookMarkit() {varurl="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();

}

 




Previous
Table of Contents
Next




Now for Some Action
The code above is all that is needed to display our OpenGL images. For this example, though, we have added some animation. Recall that we put a timer on the form in Figure 23-6, and set the interval to 200 milliseconds. Every time this timer fires, our function will make the rendering context for our OCX current, rotate the viewing matrix by 5?, and then clean up by making the rendering context not current. Finally, we tell the control to repaint, which we can do indirectly by calling the Delphi function Invalidate(). In Delphi, because all OCXs are windows, any command or message you can send a window can also easily be sent to an OCX. See Listing 23-6.

Listing 23-6 Timer code to produce the rotating teapot

procedure TMain.Timer1Timer(Sender: TObject);
begin
// Make rendering context current, then
// rotate the scene somewhat
gl.MakeCurrent();
gl.Rotate(5.0,0.0,1.0,0.5);
gl.MakeNotCurrent();

// Repaint the OCX
gl.Invalidate();
end;

Figure 23-7 shows the output from our OpenGL Delphi program.


Figure 23-7  Output from Delphi OpenGL program
Some Notes About the Source
The WaiteGL OCX was written with Visual C++ and uses MFC version 4.0. This new version of Visual C++ makes OCX development a breeze and will likely spawn dozens of useful and reusable OLE custom controls. The purpose of this chapter is not to explain how to develop OCX controls. We wanted to present one that uses OpenGL, to let you do OpenGL graphics from within Visual Basic, Delphi, or any other environment that supports OCXs.

Nevertheless, the source code for this control is included on the CD in the subdirectory for this chapter. The code was originally generated by the Microsoft Control Wizard and is fully commented. In addition, the methods and flags are separated into four source files to make maintenance easier. The file ocxgl.cpp contains wrappers for all the gl library functions; similarly, ocxgl contains the glu library functions. The file ocxaux.cpp also contains wrappers for the AUX library wireframe and solid objects, such as the teapot. Finally, ocxflags.cpp contains the access functions that retrieve the OpenGL flags and other defines.
The main file of the project is WaiteGLCtl.cpp, which is the code responsible for setting up the rendering context and firing the setup and painting events. Also, any of the wiggle or OpenGL GDI-related functions are wrapped here. In addition, there are accessor functions that will return the device and rendering contexts directly, in case you need them for your own low-level code.
Note that the OCX uses the DLL versions of MFC. For your convenience, the redistributable portions are in the \REDIST subdirectory, as well.
Summary
In this chapter we have discussed the possibilities and challenges of using OpenGL from some popular visual development environments. Although direct low-level access to the API is certainly possible from any of these environments, a much easier means of access is provided in the form of an OCX control. Most of the sample programs from this book can easily be implemented in a 4GL using this OCX, and for your benefit some are provided in the supplementary examples.




Previous
Table of Contents
Next














 


Use of this site is subject to certain Terms & Conditions, Copyright 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.












Wyszukiwarka

Podobne podstrony:
679 (2)
Nuestro Circulo 679 LA NOCHE EN QUE EL CÍRCULO FUE INTERNACIONAL, 29 de agosto de 2015
677 (2)
README (679)
674 679
675 677
679 Likwidacja środka trwałego
Dz U Nr 67, poz 679
679,16,artykul
Nuestro Circulo 677 AJEDREZ Y FILOSOFÍA, 15 de agosto de 2015

więcej podobnych podstron