1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- opengl.qdoc -->
<title>Qt 4.8: OpenGL Example (ActiveQt)</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<div class="breadcrumb toolblock">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<!-- Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>OpenGL Example (ActiveQt)</li>
</ul>
</div>
</div>
<div class="content mainContent">
<h1 class="title">OpenGL Example (ActiveQt)</h1>
<span class="subtitle"></span>
<!-- $$$activeqt/opengl-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="activeqt-opengl-glbox-cpp.html">activeqt/opengl/glbox.cpp</a></li>
<li><a href="activeqt-opengl-glbox-h.html">activeqt/opengl/glbox.h</a></li>
<li><a href="activeqt-opengl-globjwin-cpp.html">activeqt/opengl/globjwin.cpp</a></li>
<li><a href="activeqt-opengl-globjwin-h.html">activeqt/opengl/globjwin.h</a></li>
<li><a href="activeqt-opengl-main-cpp.html">activeqt/opengl/main.cpp</a></li>
<li><a href="activeqt-opengl-opengl-pro.html">activeqt/opengl/opengl.pro</a></li>
</ul>
<p>The OpenGL example demonstrates the use of the default factory and <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>(), and the implementation of an additional COM interface using <a href="qaxbindable.html">QAxBindable</a> and <a href="qaxaggregated.html">QAxAggregated</a>. The server executable can run both as an ActiveX server and as a stand-alone application.</p>
<p>The ActiveX control in this example uses the QGlWidget class in Qt to render an OpenGL scene in an ActiveX. The control exposes a few methods to change the scene.</p>
<p>The application uses the default factory as provided by the QAXFACTORY_DEFAULT macro to expose the <tt>GLBox</tt> widget as an ActiveX control.</p>
<pre class="cpp"> <span class="preprocessor">#include <QAxFactory></span>
<a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a>( GLBox<span class="operator">,</span>
<span class="string">"{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}"</span><span class="operator">,</span>
<span class="string">"{33b051af-bb25-47cf-a390-5cfd2987d26a}"</span><span class="operator">,</span>
<span class="string">"{8c996c29-eafa-46ac-a6f9-901951e765b5}"</span><span class="operator">,</span>
<span class="string">"{2c3c183a-eeda-41a4-896e-3d9c12c3577d}"</span><span class="operator">,</span>
<span class="string">"{83e16271-6480-45d5-aaf1-3f40b7661ae4}"</span>
)</pre>
<p>The implementation of <tt>main</tt> initializes the <a href="qapplication.html">QApplication</a> object, and uses <tt>QAxFactory::isServer()</tt> to determine whether or not it is appropriate to create and show the application interface.</p>
<pre class="cpp"> <span class="comment">/*
The main program is here.
*/</span>
<span class="type">int</span> main( <span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv )
{
<span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setColorSpec( <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>CustomColor );
<span class="type"><a href="qapplication.html">QApplication</a></span> a(argc<span class="operator">,</span>argv);
<span class="keyword">if</span> ( <span class="operator">!</span><span class="type"><a href="qglformat.html">QGLFormat</a></span><span class="operator">::</span>hasOpenGL() ) {
<a href="qtglobal.html#qWarning">qWarning</a>( <span class="string">"This system has no OpenGL support. Exiting."</span> );
<span class="keyword">return</span> <span class="operator">-</span><span class="number">1</span>;
}
<span class="keyword">if</span> ( <span class="operator">!</span><span class="type"><a href="qaxfactory.html">QAxFactory</a></span><span class="operator">::</span>isServer() ) {
GLObjectWindow w;
w<span class="operator">.</span>resize( <span class="number">400</span><span class="operator">,</span> <span class="number">350</span> );
w<span class="operator">.</span>show();
<span class="keyword">return</span> a<span class="operator">.</span>exec();
}
<span class="keyword">return</span> a<span class="operator">.</span>exec();
}</pre>
<p>The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">QGLWidget</a> class to be able to render OpenGL, and from <a href="qaxbindable.html">QAxBindable</a>.</p>
<pre class="cpp"> <span class="preprocessor">#include <QAxBindable></span>
<span class="keyword">class</span> GLBox : <span class="keyword">public</span> <span class="type"><a href="qglwidget.html">QGLWidget</a></span><span class="operator">,</span>
<span class="keyword">public</span> <span class="type"><a href="qaxbindable.html">QAxBindable</a></span>
{
Q_OBJECT</pre>
<p>The class reimplements the <a href="qaxbindable.html#createAggregate">QAxBindable::createAggregate</a>() function from <a href="qaxbindable.html">QAxBindable</a> to return the pointer to a <a href="qaxaggregated.html">QAxAggregated</a> object.</p>
<pre class="cpp"> <span class="keyword">public</span>:
GLBox( <span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">*</span> parent<span class="operator">,</span> <span class="keyword">const</span> <span class="type">char</span><span class="operator">*</span> name <span class="operator">=</span> <span class="number">0</span> );
<span class="operator">~</span>GLBox();
<span class="type"><a href="qaxaggregated.html">QAxAggregated</a></span> <span class="operator">*</span>createAggregate();
<span class="keyword">public</span> <span class="keyword">slots</span>:
<span class="type">void</span> setXRotation( <span class="type">int</span> degrees );</pre>
<p>The rest of the class declaration and the implementation of the OpenGL rendering is identical to the original "box" example.</p>
<p>The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt> system header, in which the <tt>IObjectSafety</tt> COM interface is defined.</p>
<pre class="cpp"> <span class="preprocessor">#include <objsafe.h></span></pre>
<p>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance to subclass the <a href="qaxaggregated.html">QAxAggregated</a> class, and to implement the IObjectSafety interface.</p>
<pre class="cpp"> <span class="keyword">class</span> ObjectSafetyImpl : <span class="keyword">public</span> <span class="type"><a href="qaxaggregated.html">QAxAggregated</a></span><span class="operator">,</span>
<span class="keyword">public</span> IObjectSafety
{
<span class="keyword">public</span>:</pre>
<p>The class declares a default constructor, and implements the queryInterface function to support the IObjectSafety interface.</p>
<pre class="cpp"> ObjectSafetyImpl() {}
<span class="type">long</span> queryInterface( <span class="keyword">const</span> <span class="type"><a href="quuid.html">QUuid</a></span> <span class="operator">&</span>iid<span class="operator">,</span> <span class="type">void</span> <span class="operator">*</span><span class="operator">*</span>iface )
{
<span class="operator">*</span>iface <span class="operator">=</span> <span class="number">0</span>;
<span class="keyword">if</span> ( iid <span class="operator">=</span><span class="operator">=</span> IID_IObjectSafety )
<span class="operator">*</span>iface <span class="operator">=</span> (IObjectSafety<span class="operator">*</span>)<span class="keyword">this</span>;
<span class="keyword">else</span>
<span class="keyword">return</span> E_NOINTERFACE;
AddRef();
<span class="keyword">return</span> S_OK;
}</pre>
<p>Since every COM interface inherits <tt>IUnknown</tt> the <tt>QAXAGG_IUNKNOWN</tt> macro is used to provide the default implementation of the <tt>IUnknown</tt> interface. The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt> and <tt>Release</tt> to the interface returned by the controllingUnknown() function.</p>
<pre class="cpp"> QAXAGG_IUNKNOWN;</pre>
<p>The implementation of the <tt>IObjectSafety</tt> interface provides the caller with information about supported and enabled safety options, and returns <tt>S_OK</tt> for all calls to indicate that the ActiveX control is safe.</p>
<pre class="cpp"> HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid<span class="operator">,</span> DWORD <span class="operator">*</span>pdwSupportedOptions<span class="operator">,</span> DWORD <span class="operator">*</span>pdwEnabledOptions )
{
<span class="operator">*</span>pdwSupportedOptions <span class="operator">=</span> INTERFACESAFE_FOR_UNTRUSTED_DATA <span class="operator">|</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER;
<span class="operator">*</span>pdwEnabledOptions <span class="operator">=</span> INTERFACESAFE_FOR_UNTRUSTED_DATA <span class="operator">|</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER;
<span class="keyword">return</span> S_OK;
}
HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid<span class="operator">,</span> DWORD pdwSupportedOptions<span class="operator">,</span> DWORD pdwEnabledOptions )
{
<span class="keyword">return</span> S_OK;
}
};</pre>
<p>The implementation of the <tt>createAggregate()</tt> function just returns a new <tt>ObjectSafetyImpl</tt> object.</p>
<pre class="cpp"> <span class="type"><a href="qaxaggregated.html">QAxAggregated</a></span> <span class="operator">*</span>GLBox<span class="operator">::</span>createAggregate()
{
<span class="keyword">return</span> <span class="keyword">new</span> ObjectSafetyImpl();
}</pre>
<p>To build the example you must first build the <a href="qaxserver.html">QAxServer</a> library. Then run <tt>qmake</tt> and your make tool in <tt>examples/activeqt/wrapper</tt>.</p>
<p>The <a href="qaxserver-demo-opengl.html">demonstration</a> requires your WebBrowser to support ActiveX controls, and scripting to be enabled.</p>
<p>In contrast to the other <a href="qaxserver.html">QAxServer</a> examples Internet Explorer will not open a dialog box to ask the user whether or not the scripting of the GLBox control should be allowed (the exact browser behaviour depends on the security settings in the Internet Options dialog).</p>
<pre class="cpp"> <SCRIPT LANGUAGE="JavaScript">
function setRot( form )
{
GLBox.setXRotation( form.XEdit.value );
GLBox.setYRotation( form.YEdit.value );
GLBox.setZRotation( form.ZEdit.value );
}
</SCRIPT>
<p />
An OpenGL scene:<br />
<object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
CODEBASE="http://qt.nokia.com/demos/openglax.cab">
[Object not available! Did you forget to build and register the server?]
</object><br />
<form>
Rotate the scene:<br />
X:<input type="edit" ID="XEdit" value="0" /><br />
Y:<input type="edit" name="YEdit" value="0" /><br />
Z:<input type="edit" name="ZEdit" value="0" /><br />
<input type="button" value="Set" onClick="setRot(this.form)" />
</form></pre>
</div>
<!-- @@@activeqt/opengl -->
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.</p>
<br />
<p>
The documentation provided herein is licensed under the terms of the
<a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
License version 1.3</a> as published by the Free Software Foundation.</p>
<p>
Documentation sources may be obtained from <a href="http://www.qt-project.org">
www.qt-project.org</a>.</p>
<br />
<p>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. <a title="Privacy Policy"
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>
|