Compile c++ top

Hey!
I’ve started to study how to write cpp externals. The classes are very nice and very clear( i was amazed to see there are ‘raw’ gl commands on the TOP example!). I think this is the best way to port material from cinder or OFW( they also have their own wrappers but underneath there are just raw gl commands).
However, I’ve only worked with OSX and its IDE Xcode to make c++ based apps, I am super super new to visual studio( probably 2 hours now :slight_smile: ). Sorry if the questions are very noob-ish!

So far what I’ve tried to do: I tried to open the TOP example on visual studio express c++. There was a window to asked met o upgrade the files and suggested me the overwrite them. So in the end I have this VS 2010 compatible project. So i try to run in debug mode and i get this error:
1>c:\users\efe\desktop\top\TOP_CPlusPlusBase.h(60): error C2146: syntax error : missing ‘;’ before identifier ‘mainWindowHandle’
1>c:\users\efe\desktop\top\TOP_CPlusPlusBase.h(60): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\efe\desktop\top\TOP_CPlusPlusBase.h(60): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

which comes from ths TOP_CPlusPlusBase header on the next line:
HWND mainWindowHandle;

might this problem be because I upgraded the version of the project and overwrote it? is there any place where i can download the original files? The other headers seem to be OK. There were some warnings because of the GLint to int conversion but that is fine.

any ideas how to fix this?

thanks!!!

-emmanuel

Its complaining that the type HWND is undefined. That type is defined in <windows.h>, so if you add

#include <windows.h> to the start of the CPlusPlusBase.h it should work. I’ll add it for future builds.

Hey!
indeed, it is working, the windows header was the issue and now the compilation works like a charm.
Wow, this gl implementation is quite straight forward right? i just wrote a very simple ‘for’ loop and there you are, a cluster of lines:
::glBegin(GL_LINES);
::glLineWidth(1.0f);
for(unsigned int i=0; i<10; i++){
int x1 = rand()% outputFormat->width;
int y1 = rand()% outputFormat->height;
int x2 = rand()% outputFormat->width;
int y2 = rand()% outputFormat->height;
::glVertex2i(x1 ,y1);
::glVertex2i(x2, y2);
}
::glEnd();

I am still thinking how to port some Cinder and OFW examples into TD, any insights about it?.
Thanks for the help!

Ok, this is fun. I’ve been thinking about the best way to implement the Cinder/OFW porting and somehow i came with something like this:

We have a class called lines that will have a pair of gl vertices.
the header:

#pragma once
#include "TOP_CPlusPlusBase.h"


#include <windows.h>
#include <gl/gl.h>


class Lines
{
public:
	Lines();
	~Lines();

	virtual void draw(int _x1, int _y1, int _x2, int _y2);

	int		x1,x2,y1,y2;

};

the body of the class:

#include "Lines.h"


Lines::Lines(){
	x1 = x2 = y2 = y1 = 0;
}


Lines::~Lines(){

}


void Lines::draw(int _x1, int _y1, int _x2, int _y2){

	x1 = _x1;
	y1 = _y1;
	x2 = _x2;
	y2 = _y2;

	::glVertex2i(x1,y1);
	::glVertex2i(x2,y2);
}

and then I declare this on the TOPExample:
std::vector mLines;

then on my constructor:
mLines.push_back(Lines());

finally on the execute() function:

	::glBegin(GL_LINES);
	::glLineWidth(1.0f);

	for(unsigned int i=0;i<amount;i++){

		int _x1 = rand()% outputFormat->width;
		int _y1 = rand()% outputFormat->height;
		int _x2 = rand()% outputFormat->width;
		int _y2 = rand()% outputFormat->height;

		mLines[i].draw(_x1, _y1, _x2, _y2);
	}
	::glEnd();

	::glBegin(GL_LINE_LOOP);
	::glVertex2i(0,0);
	::glVertex2i(outputFormat -> width, outputFormat->height);
	::glEnd();

there are several things that can be improved:
1-It would be ideal to create a separate method for update. I assume it will need to be executed inside the same function as draw.
2-To use a shared pointers and iterators, thus declaring something like:
typedef std::vector<Lines*>::iterator mIterator;

and having something like:
i->draw(_x1, _y1, _x2, _y2);

3-there is this thread I started on the cinder forum about pointers and containers, I wonder if this can be implemented with the TD externals:
forum.libcinder.org/#topic/23286000000440015

I am by no means a c++ guru so any feedback will be more than welcomed!

-emmanuel

For 2, if you are drawing a lot of data it’ll be slower to use pointers. The reason is that each pointer can point to a different part of memory, requiring a memory fetch for each draw call (which will stall the CPU).
If they are stored as objects in the vector then all the memory will be pre-cached into CPU memory as you read through the array, avoiding stalls due to a memory fetch. I avoid pointers as much as I can whenever I’m doing something that is performance sensitive. If we are thinking about the cost of filling the array, it’s also slower as a ‘new’ operation is MUCH slower than a copy of an object.

For 3, I’m not entirely clear what part you are asking about integrating into Touch, but if you are talking about boost features etc, I think you can just link your .dll with boost and it’ll work fine.

hey malcolm!
thanks for the pointers, i will keep in mind!
Is there by chance any SOP template. So far all TOP externals are textures, right? can these examples be taken as pure geometries?

No there is not currently a SOP template, although you can do a lot of stuff using the CPlusPlus CHOP to create point positions and use CHOP To SOP or other types of CHOP->SOP nodes to convert them into something usable in SOPs.