jint problem with NDK - android-ndk

I'm trying to make my first native function with NDK and I'm in trouble with very basic stuff.
Please consider the following c code:
#include <jni.h>
#include <string.h>
JNIEXPORT jint JNICALL Java_eu_elevelcbt_sm_YCrCbUtils_toARGB(
JNIEnv* env, jbyteArray src, jintArray out, jint width, jint height){
jbyte *c_src = (*env)->GetByteArrayElements(env, src, NULL);
jint *c_out = (*env)->GetDirectBufferAddress(env, out);
if (c_out==NULL)
return -1;
int length = width * height;
int co;
unsigned int color;
for (co=0; co<length; co++) {
color = c_src[co] & 0xFF;
color = 0xFF000000 | (color<<16) | (color<<8) | color;
c_out[co] = color;
}
(*env)->ReleaseByteArrayElements(env, src, c_src, 0);
return 0;
}
JNIEXPORT jint JNICALL Java_eu_elevelcbt_sm_YCrCbUtils_sum(jint a, jint b){
return a+b;
}
and the following Java class:
public class YCrCbUtils {
public native int toARGB(byte[] src, int[] out, final int width, final int height);
public native int sum(int a, int b);
static {
System.loadLibrary("yuv");
}
}
Problem 1: If I call the second function
Log.v("DBG", "sum is: " + new YCrCbUtils().sum(10, 5));
This is what I get: "sum is 1079199776" !!!! WHY?!??!? :(
If I try calling first function like this:
int[] colors = new int[size.width * size.height]; // where width=800 and height=480
new YCrCbUtils().toARGB(data, colors, size.width, size.height); // data is a byte[]
I get a SIGSEGV error...
HELP please!!!
PS: my dev environment is MAC OSX Snow Leopard, NDK-r5b. My runtime env is Nexus One 2.3.3

...ok I'm stupid...
My methods signatures were WRONG... They always must have "JNIEnv* env, jobject obj" as first two members... well I spend an afternoon on this but the good thing is that now I'll never forget it!
Also, on my first method I had to change
jint *c_out = (*env)->GetDirectBufferAddress(env, out);
with
jint *c_out = (*env)->GetIntArrayElements(env, out, NULL);
as the previous one was returning a NULL pointer

Related

opencv trackbar not showing

include
#include <opencv/highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
Mat srimg, deimg;
int max_brightness = 100;
int slider_b = (max_brightness / 2);
void on_change_brightness(int, void*)
{
int brightness = slider_b - (max_brightness / 2);
deimg = srimg + Scalar::all(brightness);
imshow("Girl", deimg);
}
int main()
{
srimg = imread("lenna.PNG");
imshow("girl", srimg);
createTrackbar("Track", "Window", &slider_b, max_brightness,on_change_brightness);
waitKey();
return EXIT_SUCCESS;
}
Note:: when I run the code it works well no error, but the track bar does not show up, and to my knowledge everything should be fine.
According to OpenCV documentation,
int createTrackbar(const string& trackbarname, const string& winname,
int* value, int count, TrackbarCallback onChange=0, void* userdata=0)
Thus, your window name should be "Girl"
I think the line
createTrackbar("Track", "Window", &slider_b, max_brightness,on_change_brightness);
should instead be
createTrackbar("Track", "Girl", &slider_b, max_brightness,on_change_brightness);
and the line
imshow("girl", srimg);
should instead be
imshow("Girl", srimg);
to keep a common window name.
If this doesn't work out, try
namedWindow("Girl", 1);
above the createTrackbar function.
Source: Example

Android Camera output using ndk-blurry result

http://postimg.org/image/btd4u4esx/
Hi,
This is the output image(black keyboard with white background) of a code that i modified from one of android samples. I want to take byte data from java file and send it to cpp using jni as unsigned character and and i am trying to display the video frames i receive using open cv mat.
JAVA CODE:
native int Fibonacci( byte[] n,int width, int height );
static {
System.loadLibrary( "CopyofHDRViewFinder" );
}
#Override
public void run() {
// y = 0.299*r + 0.587*g + 0.114*b
Log.v(TAG, "enter in imageSaver! Format is: " + mImage.getFormat());
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
int heigth=mImage.getHeight();
int width=mImage.getWidth();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
int a=Fibonacci(bytes,width,heigth);
int pixelsize=mImage.getWidth()*mImage.getHeight();
System.out.println("framewidth:"+mImage.getWidth());
System.out.println("frameheight:"+mImage.getHeight());
System.out.println("totalnumberofpixels:"+pixelsize);
System.out.println("lastpixelvalue:"+a);
then the CPP code:(jni)
JNIEXPORT jint JNICALL Java_com_example_android_hdrviewfinder_HdrViewfinderActivity3_00024ImageSaver_Fibonacci
(JNIEnv *env, jobject obj, jbyteArray array, jint width, jint height)
{
i=i+1;
int len = env->GetArrayLength (array);
unsigned char* img = new unsigned char[len];
env->GetByteArrayRegion (array, 0, len-1, reinterpret_cast<jbyte*>(img));
const cv::Mat hdrimg(height,width, CV_8UC1, img);
char buffer[50];
int ab=sprintf(buffer,"/storage/emulated/0/Android/IMAGE%d.jpg",i);
cv::imwrite(buffer, hdrimg);
/*cv::namedWindow("HDRImage");
cv::imshow("HDRImage", hdrimg);
cv::waitKey(0);*/
printf("\n %d", width);
printf("\n %d", height);
int a;
for(int i=0;i<width*height;i++)
{
a=(int)img[i];
}
int c=width*height;
return a;
}
This returns proper pixel values from 0 to 255. my issue is not that. when i check the image it looks blurry and totally horrible, but still i cant deduce that its a keyboard slightly. Anyone has seen similar results? Help, if you can..

error C2079: 'room::goldC' uses undefined class 'goldContainer'

i'm trying to create a room which has a goldContainer
The goldContainer is defined in a separate .h file.
When i'm trying to compile it says
error C2079: 'room::goldC' uses undefined class 'goldContainer'
The class voor room:
#pragma once
#include <SFML\Graphics.hpp>
#include "screenSettings.h"
#include "floorplanPatch.h"
#include "floorplanPatchContainer.h"
#include "enemyContainer.h"
#include "goldContainer.h"
class goldContainer;
class room{
public:
room(int themenr, floorplanPatchContainer &f);
void draw(sf::RenderWindow &window);
int getStartPoint();
int getEndPoint();
void addFloorplanPatch(int x, int y, int type, floorplanPatch *patch);
bool isSolid(sf::Vector2f position);
void addEnemy();
static const int FLOOR_TEXTURE1 = 0;
static const int FLOOR_TEXTURE2 = 1;
static const int FLOOR_TEXTURE3 = 2;
static const int FLOOR_TEXTURE4 = 3;
static const int WALL = 4;
static const int OBSTACLE = 5;
static const int COSMETIC = 6;
int floorplan[xAs][yAs];
enemyContainer* getEnemyContainer();
void room::addEnemy(int health);
private:
enemyContainer ec;
int startPoint = 1 + rand() % (yAs - 2);
int endPoint = 1 + rand() % (yAs - 2);
sf::RectangleShape rectangle{ sf::Vector2f{ tileSizeX, tileSizeY } };
sf::Texture wall;
sf::Texture obstacle;
sf::Texture floor1;
sf::Texture floor2;
sf::Texture floor3;
sf::Texture floor4;
sf::Texture cosmetic;
void drawBackgroundTile(sf::RenderWindow &window, int i, int x, int y);
goldContainer goldC;
};
it has class goldContainer; on line 8 otherwise it generates error code 2146.
Could someone maybe explain how to solve this error and/or why this occurs.
#pragma once
#include "gold.h"
#include "sound.h"
#include "player.h"
class player;
class room;
class goldContainer{
public:
goldContainer();
~goldContainer();
void checkPickedUp(player &player);
void draw(sf::RenderWindow &window);
void addGold(int amount, sf::Vector2f position, sf::Vector2f size);
void clearAllGold();
private:
std::vector<gold* > goldDrops;
sound goldPickup{ "sounds\\goldPickup.wav" };
};
I think it might be a circular depedency trough:
^->goldContainer->player->roomContainer->room->|
|<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-< v
Let me show you the problem domain:
class Moon;
class Sun
{
void Rotate(Moon);
};
Now, you implement Sun::Rotate, without giving any class declaration (not forward declaration):
void Sun::Rotate(Moon m) // Error C2027
{
}
What you can do:
Ensure that before Sun::Rotate gets into compilation phase, Moon is declared (i.e. known to compiler by now). You need not to implement any method of Moon, just declare.
Example:
class Moon;
class Sun
{
void Rotate(Moon);
};
// Let it come by now
class Moon
{
public:
void PleaseRotate();
};
// Moon is known
void Sun::Rotate(Moon m)
{
m.PleaseRotate(); // It need not to be implemented by now.
}
Note that Moon::PleaseRotate definition would be resolved by linker, and hence its implementation is not needed before Sun::Rotate.

VC++ does not show output

I am new to VC++ and its been a few times now, and this is the third program that does not give output even after it is build succesfully.
#include <AFXWIN.H>
#include <math.h>
#define PI 3.1415926
#define SEGMENTS 500
class CMyApp : public CWinApp {
public:
virtual BOOL InitInstance();
};
class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT, CPoint);
DECLARE_MESSAGE_MAP();
};
CMyApp myAPP;
BOOL CMyApp::InitInstance() {
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow(SW_MAXIMIZE);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow() {
Create(NULL,"The Hello Application",WS_OVERLAPPEDWINDOW);
}
void CMainWindow::OnPaint() {
CRect rect;
int nWidth = rect.Width();
int nHeight = rect.Height();
CPaintDC dc (this);
CPoint aPoint[SEGMENTS];
for (int i =0; i < SEGMENTS; i++){
aPoint[i].x = ((i*nWidth)/SEGMENTS );
aPoint[i].y= (int)((nHeight/2)* (1-(sin((2*PI*i)/SEGMENTS))));
}
dc.Polyline(aPoint, SEGMENTS);
UpdateData(false);
}
The above program should give Sine curve as the output, except that I get a blank window. And I don't know why does it happen. If it helps, I am using VC++ 6.0
The problem is probably that the rectangle you use to get the width and height is not initialized. You have to get the rectangle from somewhere, see e.g. CWnd::GetClientRect.

Looking for code samples for Direct3D tessellation

I am trying to learn how to use the Direct3D function D3DXTessellateRectPatch:
msdn.microsoft.com/en-us/library/bb205471(v=VS.85).aspx
I have found the MSDN documentation quite useful and have been able to implement tessellation of a
single rectangle patch.
I am now trying to tesselate a mesh that consists of thirty two bicubic Bezier 3D patches (the Utah teapot).
I have tried a simple approach - tesselate each Bezier curve individually, then join the vertices and
indices appropriately, taking into account vertex offsets, to create a tessellated merged mesh.
However, this does not quite seem to have the desired result.
If anyone has hints on this problem or, even better, code samples, much appreciated.
Specifically, I have checked:
Www.directxtutorial.com
http://www.amazon.com/Introduction-Game-Programming-Direct-9-0c/dp/1598220160/
And another Direct3D reference, as well as Google.
Thank you and look forward to your advice/pointers.
Yours
Misha
Tim C Schroeder has been a huge help and suggested I use ID3DXPatchMesh. Here is some sample code that generates a tessellated teapot (place in file tester.cpp):
// Main D3DX framework from www.directxtutorial.com (free section)
#include <assert.h>
#include <stdio.h>
// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
// define the screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
// include the Direct3D Library files
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
// global declarations
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPD3DXMESH mesh = NULL; // define the mesh pointer
// function prototypes
void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);
void init_graphics(void);
struct vertex_data
{
D3DXVECTOR3 position;
DWORD color;
};
#define FVF_VERTEX_DATA (D3DFVF_XYZ | D3DFVF_DIFFUSE)
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "WindowClass";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL, "WindowClass", "Our Direct3D Program",
WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
initD3D(hWnd);
MSG msg;
while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
break;
render_frame();
}
cleanD3D();
return msg.wParam;
}
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
init_graphics();
d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE); // turn off the 3D lighting
d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // turn off culling
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE); // turn on the z-buffer
}
// this is the function used to render a single frame
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->BeginScene();
d3ddev->SetFVF(FVF_VERTEX_DATA);
// set the view transform
D3DXMATRIX matView; // the view transform matrix
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (0.0f, 8.0f, 25.0f), // the camera position
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView); // set the view transform to matView
// set the projection transform
D3DXMATRIX matProjection; // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45), // the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f, // the near view-plane
100.0f); // the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection); // set the projection
// set the world transform
static float index = 0.0f; index+=0.03f; // an ever-increasing float value
D3DXMATRIX matRotateY; // a matrix to store the rotation for each triangle
D3DXMatrixRotationY(&matRotateY, index); // the rotation matrix
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateY)); // set the world transform
if (mesh) mesh->DrawSubset(0);
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
if (mesh) mesh->Release();
d3ddev->Release();
d3d->Release();
}
#define MAX_PATCHES 1000
#define POINTS_PER_PATCH 16
int num_patches = -1;
int patches[MAX_PATCHES][POINTS_PER_PATCH];
void B_patch(int ii, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p)
{
assert(ii < MAX_PATCHES);
patches[ii][0] = a-1;
patches[ii][1] = b-1;
patches[ii][2] = c-1;
patches[ii][3] = d-1;
patches[ii][4] = e-1;
patches[ii][5] = f-1;
patches[ii][6] = g-1;
patches[ii][7] = h-1;
patches[ii][8] = i-1;
patches[ii][9] = j-1;
patches[ii][10] = k-1;
patches[ii][11] = l-1;
patches[ii][12] = m-1;
patches[ii][13] = n-1;
patches[ii][14] = o-1;
patches[ii][15] = p-1;
assert(POINTS_PER_PATCH==16);
}
#define MAX_POINTS 1000
int num_points = -1;
D3DXVECTOR3 points[MAX_POINTS];
void B_point(int ii, double x, double y, double z)
{
ii--;
assert(ii < MAX_POINTS);
points[ii].x = x;
/*** Y AND Z FLIPPED ***/
points[ii].y = z;
points[ii].z = y;
}
// BEGIN http://www.sjbaker.org/teapot/teaset.tgz
/*
* The file input.c -- Juhana Kouhia, jk87377#cs.tut.fi, Oct. 25, 1991
*
* Load_patch(filename, patches, vertices);
* char *filename; int *patches, *vertices;
* A sample program to read Bezier patches in.
* Returns count of patches and vertices.
* User defined subroutines:
* B_patch(ii, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
* int ii, a, b, ..., p;
* Defines one Bezier patch with index number ii,
* indexes to points are in a, b, c, ..., p.
* B_point(ii, x, y, z);
* int ii; double x, y, z;
* Defines one point with index number ii.
*/
#include <stdio.h>
// Modified to work with g++
void Load_patch(char *filename, int *patches, int *vertices)
{
int ii;
float x,y,z;
int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
FILE *fp;
if (!(fp = fopen(filename,"r"))) {
fprintf(stderr,"Load_patch: Can't open %s\n",filename);
exit(1);
}
(void)fscanf(fp,"%i\n",patches);
for (ii = 0; ii < *patches; ii++) {
(void)fscanf(fp,"%i, %i, %i, %i,",&a,&b,&c,&d);
(void)fscanf(fp,"%i, %i, %i, %i,",&e,&f,&g,&h);
(void)fscanf(fp,"%i, %i, %i, %i,",&i,&j,&k,&l);
(void)fscanf(fp,"%i, %i, %i, %i\n",&m,&n,&o,&p);
B_patch(ii, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
}
(void)fscanf(fp,"%i\n",vertices);
for (ii = 1; ii <= *vertices; ii++) {
(void)fscanf(fp,"%f, %f, %f\n",&x,&y,&z);
B_point(ii, (double)x,(double)y,(double)z);
}
}
// END http://www.sjbaker.org/teapot/teaset.tgz
// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
// load patch
char filename[255];
sprintf(filename,"teapot");
Load_patch(filename,&num_patches,&num_points);
printf("Loaded patch %s with %d patches and %d vertices.\n",
filename,num_patches,num_points);
// create declarator from FVF
D3DVERTEXELEMENT9 inDecl[MAX_FVF_DECL_SIZE];
if (!SUCCEEDED(D3DXDeclaratorFromFVF(FVF_VERTEX_DATA,inDecl)))
assert(FALSE);
// create patch mesh
LPD3DXPATCHMESH p_mesh;
D3DXPATCHINFO info;
info.PatchType = D3DXPATCHMESH_RECT;
info.Degree = D3DDEGREE_CUBIC;
info.Basis = D3DBASIS_BEZIER;
if (!SUCCEEDED(D3DXCreatePatchMesh(&info,num_patches,num_points,0,inDecl,d3ddev,&p_mesh)))
assert(FALSE);
assert(p_mesh->GetControlVerticesPerPatch()==POINTS_PER_PATCH);
// copy vertices
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
if (!SUCCEEDED(p_mesh->GetVertexBuffer(&v_buffer)))
assert(FALSE);
struct vertex_data* vertex_data = NULL;
DWORD number_of_vertices=p_mesh->GetNumVertices();
assert(number_of_vertices==num_points);
if (!SUCCEEDED(v_buffer->Lock(0,number_of_vertices*sizeof(struct vertex_data),(void **)&vertex_data,D3DLOCK_DISCARD)))
assert(FALSE);
for (int i=0; i<num_points; i++)
{
vertex_data[i].position.x = points[i].x;
vertex_data[i].position.y = points[i].y;
vertex_data[i].position.z = points[i].z;
vertex_data[i].color = D3DCOLOR_XRGB(255,0,0);
}
v_buffer->Unlock();
v_buffer->Release();
// copy indices
LPDIRECT3DINDEXBUFFER9 i_buffer = NULL;
if (!SUCCEEDED(p_mesh->GetIndexBuffer(&i_buffer)))
assert(FALSE);
D3DINDEXBUFFER_DESC i_buffer_desc;
if (!SUCCEEDED(i_buffer->GetDesc(&i_buffer_desc)))
assert(FALSE);
assert(i_buffer_desc.Size==num_patches*POINTS_PER_PATCH*sizeof(WORD));
WORD* index_data = NULL;
if (!SUCCEEDED(i_buffer->Lock(0,0,(void **)&index_data,D3DLOCK_DISCARD)))
assert(FALSE);
int idx=0;
for (int i=0; i<num_patches; i++)
{
for (int j=0; j<POINTS_PER_PATCH; j++)
{
index_data[idx] = patches[i][j];
idx++;
}
}
i_buffer->Unlock();
i_buffer->Release();
// create mesh for tesselation
FLOAT fTessLevel=1.0f;
DWORD Adaptive=FALSE;
DWORD NumTriangles,NumVertices;
if (!SUCCEEDED(p_mesh->GetTessSize(fTessLevel,Adaptive,&NumTriangles,&NumVertices)))
assert(FALSE);
if (!SUCCEEDED(D3DXCreateMeshFVF(NumTriangles,NumVertices,D3DXMESH_MANAGED,FVF_VERTEX_DATA,d3ddev,&mesh)))
assert(FALSE);
// tesselate
assert(Adaptive==FALSE);
if (!SUCCEEDED(p_mesh->Tessellate(fTessLevel,mesh)))
assert(FALSE);
printf("Generated tesselated mesh with %d triangles, %d vertices\n",NumTriangles,NumVertices);
p_mesh->Release();
}
The teapot data (place in file teapot) is (from http://www.sjbaker.org/teapot/teaset.tgz):
32
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
4,17,18,19,8,20,21,22,12,23,24,25,16,26,27,28
19,29,30,31,22,32,33,34,25,35,36,37,28,38,39,40
31,41,42,1,34,43,44,5,37,45,46,9,40,47,48,13
13,14,15,16,49,50,51,52,53,54,55,56,57,58,59,60
16,26,27,28,52,61,62,63,56,64,65,66,60,67,68,69
28,38,39,40,63,70,71,72,66,73,74,75,69,76,77,78
40,47,48,13,72,79,80,49,75,81,82,53,78,83,84,57
57,58,59,60,85,86,87,88,89,90,91,92,93,94,95,96
60,67,68,69,88,97,98,99,92,100,101,102,96,103,104,105
69,76,77,78,99,106,107,108,102,109,110,111,105,112,113,114
78,83,84,57,108,115,116,85,111,117,118,89,114,119,120,93
121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136
124,137,138,121,128,139,140,125,132,141,142,129,136,143,144,133
133,134,135,136,145,146,147,148,149,150,151,152,69,153,154,155
136,143,144,133,148,156,157,145,152,158,159,149,155,160,161,69
162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177
165,178,179,162,169,180,181,166,173,182,183,170,177,184,185,174
174,175,176,177,186,187,188,189,190,191,192,193,194,195,196,197
177,184,185,174,189,198,199,186,193,200,201,190,197,202,203,194
204,204,204,204,207,208,209,210,211,211,211,211,212,213,214,215
204,204,204,204,210,217,218,219,211,211,211,211,215,220,221,222
204,204,204,204,219,224,225,226,211,211,211,211,222,227,228,229
204,204,204,204,226,230,231,207,211,211,211,211,229,232,233,212
212,213,214,215,234,235,236,237,238,239,240,241,242,243,244,245
215,220,221,222,237,246,247,248,241,249,250,251,245,252,253,254
222,227,228,229,248,255,256,257,251,258,259,260,254,261,262,263
229,232,233,212,257,264,265,234,260,266,267,238,263,268,269,242
270,270,270,270,279,280,281,282,275,276,277,278,271,272,273,274
270,270,270,270,282,289,290,291,278,286,287,288,274,283,284,285
270,270,270,270,291,298,299,300,288,295,296,297,285,292,293,294
270,270,270,270,300,305,306,279,297,303,304,275,294,301,302,271
306
1.4,0.0,2.4
1.4,-0.784,2.4
0.784,-1.4,2.4
0.0,-1.4,2.4
1.3375,0.0,2.53125
1.3375,-0.749,2.53125
0.749,-1.3375,2.53125
0.0,-1.3375,2.53125
1.4375,0.0,2.53125
1.4375,-0.805,2.53125
0.805,-1.4375,2.53125
0.0,-1.4375,2.53125
1.5,0.0,2.4
1.5,-0.84,2.4
0.84,-1.5,2.4
0.0,-1.5,2.4
-0.784,-1.4,2.4
-1.4,-0.784,2.4
-1.4,0.0,2.4
-0.749,-1.3375,2.53125
-1.3375,-0.749,2.53125
-1.3375,0.0,2.53125
-0.805,-1.4375,2.53125
-1.4375,-0.805,2.53125
-1.4375,0.0,2.53125
-0.84,-1.5,2.4
-1.5,-0.84,2.4
-1.5,0.0,2.4
-1.4,0.784,2.4
-0.784,1.4,2.4
0.0,1.4,2.4
-1.3375,0.749,2.53125
-0.749,1.3375,2.53125
0.0,1.3375,2.53125
-1.4375,0.805,2.53125
-0.805,1.4375,2.53125
0.0,1.4375,2.53125
-1.5,0.84,2.4
-0.84,1.5,2.4
0.0,1.5,2.4
0.784,1.4,2.4
1.4,0.784,2.4
0.749,1.3375,2.53125
1.3375,0.749,2.53125
0.805,1.4375,2.53125
1.4375,0.805,2.53125
0.84,1.5,2.4
1.5,0.84,2.4
1.75,0.0,1.875
1.75,-0.98,1.875
0.98,-1.75,1.875
0.0,-1.75,1.875
2.0,0.0,1.35
2.0,-1.12,1.35
1.12,-2.0,1.35
0.0,-2.0,1.35
2.0,0.0,0.9
2.0,-1.12,0.9
1.12,-2.0,0.9
0.0,-2.0,0.9
-0.98,-1.75,1.875
-1.75,-0.98,1.875
-1.75,0.0,1.875
-1.12,-2.0,1.35
-2.0,-1.12,1.35
-2.0,0.0,1.35
-1.12,-2.0,0.9
-2.0,-1.12,0.9
-2.0,0.0,0.9
-1.75,0.98,1.875
-0.98,1.75,1.875
0.0,1.75,1.875
-2.0,1.12,1.35
-1.12,2.0,1.35
0.0,2.0,1.35
-2.0,1.12,0.9
-1.12,2.0,0.9
0.0,2.0,0.9
0.98,1.75,1.875
1.75,0.98,1.875
1.12,2.0,1.35
2.0,1.12,1.35
1.12,2.0,0.9
2.0,1.12,0.9
2.0,0.0,0.45
2.0,-1.12,0.45
1.12,-2.0,0.45
0.0,-2.0,0.45
1.5,0.0,0.225
1.5,-0.84,0.225
0.84,-1.5,0.225
0.0,-1.5,0.225
1.5,0.0,0.15
1.5,-0.84,0.15
0.84,-1.5,0.15
0.0,-1.5,0.15
-1.12,-2.0,0.45
-2.0,-1.12,0.45
-2.0,0.0,0.45
-0.84,-1.5,0.225
-1.5,-0.84,0.225
-1.5,0.0,0.225
-0.84,-1.5,0.15
-1.5,-0.84,0.15
-1.5,0.0,0.15
-2.0,1.12,0.45
-1.12,2.0,0.45
0.0,2.0,0.45
-1.5,0.84,0.225
-0.84,1.5,0.225
0.0,1.5,0.225
-1.5,0.84,0.15
-0.84,1.5,0.15
0.0,1.5,0.15
1.12,2.0,0.45
2.0,1.12,0.45
0.84,1.5,0.225
1.5,0.84,0.225
0.84,1.5,0.15
1.5,0.84,0.15
-1.6,0.0,2.025
-1.6,-0.3,2.025
-1.5,-0.3,2.25
-1.5,0.0,2.25
-2.3,0.0,2.025
-2.3,-0.3,2.025
-2.5,-0.3,2.25
-2.5,0.0,2.25
-2.7,0.0,2.025
-2.7,-0.3,2.025
-3.0,-0.3,2.25
-3.0,0.0,2.25
-2.7,0.0,1.8
-2.7,-0.3,1.8
-3.0,-0.3,1.8
-3.0,0.0,1.8
-1.5,0.3,2.25
-1.6,0.3,2.025
-2.5,0.3,2.25
-2.3,0.3,2.025
-3.0,0.3,2.25
-2.7,0.3,2.025
-3.0,0.3,1.8
-2.7,0.3,1.8
-2.7,0.0,1.575
-2.7,-0.3,1.575
-3.0,-0.3,1.35
-3.0,0.0,1.35
-2.5,0.0,1.125
-2.5,-0.3,1.125
-2.65,-0.3,0.9375
-2.65,0.0,0.9375
-2.0,-0.3,0.9
-1.9,-0.3,0.6
-1.9,0.0,0.6
-3.0,0.3,1.35
-2.7,0.3,1.575
-2.65,0.3,0.9375
-2.5,0.3,1.125
-1.9,0.3,0.6
-2.0,0.3,0.9
1.7,0.0,1.425
1.7,-0.66,1.425
1.7,-0.66,0.6
1.7,0.0,0.6
2.6,0.0,1.425
2.6,-0.66,1.425
3.1,-0.66,0.825
3.1,0.0,0.825
2.3,0.0,2.1
2.3,-0.25,2.1
2.4,-0.25,2.025
2.4,0.0,2.025
2.7,0.0,2.4
2.7,-0.25,2.4
3.3,-0.25,2.4
3.3,0.0,2.4
1.7,0.66,0.6
1.7,0.66,1.425
3.1,0.66,0.825
2.6,0.66,1.425
2.4,0.25,2.025
2.3,0.25,2.1
3.3,0.25,2.4
2.7,0.25,2.4
2.8,0.0,2.475
2.8,-0.25,2.475
3.525,-0.25,2.49375
3.525,0.0,2.49375
2.9,0.0,2.475
2.9,-0.15,2.475
3.45,-0.15,2.5125
3.45,0.0,2.5125
2.8,0.0,2.4
2.8,-0.15,2.4
3.2,-0.15,2.4
3.2,0.0,2.4
3.525,0.25,2.49375
2.8,0.25,2.475
3.45,0.15,2.5125
2.9,0.15,2.475
3.2,0.15,2.4
2.8,0.15,2.4
0.0,0.0,3.15
0.0,-0.002,3.15
0.002,0.0,3.15
0.8,0.0,3.15
0.8,-0.45,3.15
0.45,-0.8,3.15
0.0,-0.8,3.15
0.0,0.0,2.85
0.2,0.0,2.7
0.2,-0.112,2.7
0.112,-0.2,2.7
0.0,-0.2,2.7
-0.002,0.0,3.15
-0.45,-0.8,3.15
-0.8,-0.45,3.15
-0.8,0.0,3.15
-0.112,-0.2,2.7
-0.2,-0.112,2.7
-0.2,0.0,2.7
0.0,0.002,3.15
-0.8,0.45,3.15
-0.45,0.8,3.15
0.0,0.8,3.15
-0.2,0.112,2.7
-0.112,0.2,2.7
0.0,0.2,2.7
0.45,0.8,3.15
0.8,0.45,3.15
0.112,0.2,2.7
0.2,0.112,2.7
0.4,0.0,2.55
0.4,-0.224,2.55
0.224,-0.4,2.55
0.0,-0.4,2.55
1.3,0.0,2.55
1.3,-0.728,2.55
0.728,-1.3,2.55
0.0,-1.3,2.55
1.3,0.0,2.4
1.3,-0.728,2.4
0.728,-1.3,2.4
0.0,-1.3,2.4
-0.224,-0.4,2.55
-0.4,-0.224,2.55
-0.4,0.0,2.55
-0.728,-1.3,2.55
-1.3,-0.728,2.55
-1.3,0.0,2.55
-0.728,-1.3,2.4
-1.3,-0.728,2.4
-1.3,0.0,2.4
-0.4,0.224,2.55
-0.224,0.4,2.55
0.0,0.4,2.55
-1.3,0.728,2.55
-0.728,1.3,2.55
0.0,1.3,2.55
-1.3,0.728,2.4
-0.728,1.3,2.4
0.0,1.3,2.4
0.224,0.4,2.55
0.4,0.224,2.55
0.728,1.3,2.55
1.3,0.728,2.55
0.728,1.3,2.4
1.3,0.728,2.4
0.0,0.0,0.0
1.5,0.0,0.15
1.5,0.84,0.15
0.84,1.5,0.15
0.0,1.5,0.15
1.5,0.0,0.075
1.5,0.84,0.075
0.84,1.5,0.075
0.0,1.5,0.075
1.425,0.0,0.0
1.425,0.798,0.0
0.798,1.425,0.0
0.0,1.425,0.0
-0.84,1.5,0.15
-1.5,0.84,0.15
-1.5,0.0,0.15
-0.84,1.5,0.075
-1.5,0.84,0.075
-1.5,0.0,0.075
-0.798,1.425,0.0
-1.425,0.798,0.0
-1.425,0.0,0.0
-1.5,-0.84,0.15
-0.84,-1.5,0.15
0.0,-1.5,0.15
-1.5,-0.84,0.075
-0.84,-1.5,0.075
0.0,-1.5,0.075
-1.425,-0.798,0.0
-0.798,-1.425,0.0
0.0,-1.425,0.0
0.84,-1.5,0.15
1.5,-0.84,0.15
0.84,-1.5,0.075
1.5,-0.84,0.075
0.798,-1.425,0.0
1.425,-0.798,0.0
Finally, to compile using mingw on Ubuntu 10.04 amd64 with proper software installed:
#!/bin/bash
rm tester.exe > /dev/null 2>&1
i586-mingw32msvc-g++ tester.cpp -o tester.exe -fcheck-new -Idxsdk/DXSDK/Include -ld3d9 dxsdk/DXSDK/Lib/x86/d3dx9.lib

Resources