mod: changed text file to html, so that it can be included on website
This commit is contained in:
parent
0b758f82ef
commit
bab5b383b6
|
@ -0,0 +1,87 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenAL Tutoral</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
|
||||
<meta name="author" content="Brian Matzon">
|
||||
<meta name="description" content="Basic sound using OpenAL">
|
||||
</head>
|
||||
<body>
|
||||
<h1 align="center">Array Conversion<br>
|
||||
<font size="-1">(by Brian Matzon <<a href="mailto:brian@matzon.dk">brian@matzon.dk</a>>)</font><br>
|
||||
</h1>
|
||||
<b>1.0 About this document</b><br>
|
||||
This document describes the typical rules for converting arrays often used in
|
||||
C/C++ OpenAL (and indeed OpenGL too) code.<br>
|
||||
It is not bullet proof, but should handle most cases.<br>
|
||||
<br>
|
||||
<b>1.1 Array to ByteBuffer<br>
|
||||
</b>When using an array of some data type in C/C++
|
||||
you will typically convert that<br>
|
||||
to the corresponding ByteBuffer type. ie:<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>ALfloat
|
||||
floatv[3];</tt></p>
|
||||
<p>becomes</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
FloatBuffer floatv = createFloatBuffer(3);</tt></p>
|
||||
<p>In this example, <tt>createFloatBuffer</tt>
|
||||
is this utility method:</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
public FloatBuffer createFloatBuffer(int size) {<br>
|
||||
|
||||
//allocate bytebuffer, using 4 bytes per float<br>
|
||||
|
||||
ByteBuffer temp = ByteBuffer.allocateDirect(4*size);<br>
|
||||
|
||||
temp.order(ByteOrder.nativeOrder());<br>
|
||||
|
||||
<br>
|
||||
|
||||
return temp.asFloatBuffer();<br>
|
||||
}</tt></p>
|
||||
<p>
|
||||
<b>1.2 Examples</b><br>
|
||||
Using the above FloatBuffer, you would typically use it like this (examples
|
||||
taken from altest.c/ALTest.java):</p>
|
||||
<p>
|
||||
<b>1.2.1 Example 1</b></p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
alGetListenerfv(AL_POSITION, floatv);</tt></p>
|
||||
<p>
|
||||
becomes</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
al.getListenerfv(AL.POSITION, Sys.getDirectBufferAddress(floatv));</tt></p>
|
||||
<p><b>1.2.2 Example 2</b></p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
if (floatv[0] != 100.0)) {</tt></p>
|
||||
<p>becomes:</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
if (floatv.get(0) != 100.0f) {</tt></p>
|
||||
<p><b>1.2.3 Example 3</b></p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
alGetListener3f(AL_POSITION, &floatv[0], <br>
|
||||
|
||||
&floatv[1], <br>
|
||||
|
||||
&floatv[2]);</tt></p>
|
||||
<p>becomes</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
al.getListener3f(AL.POSITION, Sys.getDirectBufferAddress(floatv), <br>
|
||||
|
||||
Sys.getDirectBufferAddress(floatv) + 4, <br>
|
||||
|
||||
Sys.getDirectBufferAddress(floatv) + 8);</tt></p>
|
||||
<p>the last case is a bit special, since we start of by getting the base
|
||||
address of the buffer, and then add the datatype size to the base address<br>
|
||||
to get the address of that specific index. This is just how it has to
|
||||
be in Java.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,45 +0,0 @@
|
|||
Author: Brian Matzon <brian@matzon.dk>
|
||||
|
||||
When converting C/C++ OpenAL code to Java the following
|
||||
conversion rules, typically apply:
|
||||
|
||||
When using an array of some data type in C/C++ you will typically convert that
|
||||
to the corresponding ByteBuffer type. ie:
|
||||
ALfloat floatv[3];
|
||||
becomes
|
||||
FloatBuffer floatv = createFloatBuffer(3);
|
||||
|
||||
In this example, createFloatBuffer is this utility method:
|
||||
public FloatBuffer createFloatBuffer(int size) {
|
||||
//allocate bytebuffer, using 4 bytes per float
|
||||
ByteBuffer temp = ByteBuffer.allocateDirect(4*size);
|
||||
temp.order(ByteOrder.nativeOrder());
|
||||
|
||||
return temp.asFloatBuffer();
|
||||
}
|
||||
|
||||
Using the above FloatBuffer, you would typically use it like this:
|
||||
(examples taken from altest.c/ALTest.java):
|
||||
example 1:
|
||||
alGetListenerfv(AL_POSITION, floatv);
|
||||
becomes
|
||||
al.getListenerfv(AL.POSITION, Sys.getDirectBufferAddress(floatv));
|
||||
|
||||
example 2:
|
||||
if (floatv[0] != 100.0)) {
|
||||
becomes:
|
||||
if (floatv.get(0) != 100.0f) {
|
||||
|
||||
example 3:
|
||||
alGetListener3f(AL_POSITION, &floatv[0],
|
||||
&floatv[1],
|
||||
&floatv[2]);
|
||||
becomes
|
||||
al.getListener3f(AL.POSITION, Sys.getDirectBufferAddress(floatv),
|
||||
Sys.getDirectBufferAddress(floatv) + 4,
|
||||
Sys.getDirectBufferAddress(floatv) + 8);
|
||||
|
||||
the last case is a bit special, since we start of by getting the base
|
||||
address of the buffer, and then add the datatype size to the base address
|
||||
to get the address of that specific index. This is just how it has to
|
||||
be in Java.
|
Loading…
Reference in New Issue