SlaLouis
Posts: 3
Joined: Mon May 20, 2013 9:03 pm

Developing for Pi in Visual Studio

Mon Jun 10, 2013 9:42 pm

It's been a while since I coded in a non-managed language... I'm looking to do work with OpenGL ES 2.0 to develop a graphical application for the Pi (started with Java, but it's far too slow for anything complex). The problem is, I don't want to develop ON the Pi.

Can anyone point me to a tutorial or guide for setting up a visual studio environment that allows me to develop for the Pi? I'd like to be able to develop, debug, and iterate on windows, using Visual C++, then be able to package the product for deployment to the Pi.

With my very rusted knowledge of makefiles and such, it's difficult to find a guide that encompasses what I need. I've been googling for the better part of 3 hours now, and only have vague notions of ARM emulators and command line compilers that sound miserable.

So, how do I...
(a) Set up a visual studio environment to work with OpenGL ES 2.0
(b) Create a project that builds/runs in both Windows and RPi
(c) Ensure that the API versions match between platforms (if necessary)

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Developing for Pi in Visual Studio

Tue Jun 11, 2013 7:37 am

http://visualgdb.com/tutorials/raspberry/

Running the same code on the Raspi and Windows might
be harder , Cygwin would perhaps be a solution.

OpenGL ES emulators are available from ARM and others.
http://soulbuzz.net/?p=225

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

RoyLongbottom
Posts: 334
Joined: Fri Apr 12, 2013 9:27 am
Location: Essex, UK
Contact: Website

Re: Developing for Pi in Visual Studio

Thu Jun 13, 2013 9:22 pm

The following is supposed to allow development of OpenGL ES programs on a PC. A problem is that Radeon graphics seems to be needed to run. It looks as though there might be incompatibilities with ARM OpenGL, like some EGL includes are different.

http://developer.amd.com/tools-and-sdks ... gl-es-sdk/

I have tried this with Windows and Linux and will try again soon. I have converted my Android OpenGL benchmark to run on the Pi and details will be included with those for my other benchmarks in another post.

http://www.raspberrypi.org/phpBB3/viewt ... 31&t=44080

My procedure is to edit the source code under Windows and copy it into the Pi via LAN. It compiles in a few seconds via a make command.

arturo777
Posts: 28
Joined: Sat Mar 24, 2012 10:02 am

Re: Developing for Pi in Visual Studio

Sat Jun 15, 2013 9:38 pm

Check out the ANGLE Project - Almost Native Graphics Layer Engine.

https://code.google.com/p/angleproject/
The goal of ANGLE is to allow Windows users to seamlessly run WebGL and other OpenGL ES 2.0 content by translating OpenGL ES 2.0 API calls to DirectX 9 API calls.
This will handle the graphics, you could probably use SDL for input etc. I can also verify that ANGLE compiles with VS 2012.

ffelagund
Posts: 30
Joined: Wed Nov 21, 2012 7:53 pm

Re: Developing for Pi in Visual Studio

Sun Aug 11, 2013 10:09 am

My setup is the next:
a) First I setup a external drive to hold the project files, and plug it into the windows machine. (dont program directly on the raspi SD. It's sooooo slow)
b) mount that driver in the raspi with sambaclient
c) create the normal visual studio project files
d) create a Makefile for the linux side. This could be very simple. I'm currently using something like the one I'd attached at the end of this post.
e) download putty package, the complete one, not just putty.exe. There it comes a command line utility called plink. This utility logs via ssh into a machine (your raspi) and launchs a command. This is my line
"C:\Program Files (x86)\PuTTY\plink.exe" -P MySSHPort -pw MyPassword -X myUserName@MyRaspiIP "cd /home/myusername/projectFolder/ && make -f Makefile all 2>&1 | perl /usr/bin/gccfilt.pl"
I usually setup the ssh server in a non default port, that's why I specify -P mySSHPort
You also have to specify your raspi user/pass/ip
The command changes the directory where my Makefile lies and than launches it, redirecting all output to an script (easy to find on internet) that translates gcc error format on visual studio format, so I can dbl click on an error and visual studio will bring me to the line and column where the error is.

Now, to execute this command you have two choice:
a) your visual studio project must be a NMAKE project, and the plink command line must be place in the build events section
b) your visual studio project could be a normal visual studio, but you can configure a menu entry (Tools->External Tools) to launch the command line. The best point on this option is that you can also build with visual studio's compiler for a multiplatform solution. (with proper #ifdefs of course)

I have 3 command lines, one build, one for clean and one for rebuild.

The only problem is the debugging. You cant debug directly in visual studio. You can do via ssh and using directly GDB, or using remote gdb debugging, using an IDE like eclipe or codeblocks.

This solution seems involved, but once you setup the system, programming is very comfortable.


Makefile:
OBJS=main.o
OBJS+=othersourcefiles.o

BIN=executable.bin

CFLAGS+= -Wall -Wno-reorder -O3

LDFLAGS+=-L$(SDKSTAGE)/opt/vc/lib/ -L./ -lGLESv2 -lEGL -lbcm_host

INCLUDES+=-I$(SDKSTAGE)/opt/vc/include/ -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux

.PRECIOUS: obj/*.o
.SECONDARY: $(OBJS)
all: $(BIN) $(LIB)

%.o: %.c
# @rm -f $@
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

%.o: %.cpp
# @rm -f $@
$(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $@

%.bin: $(OBJS)
$(CXX) -o $@ $(OBJS) $(LDFLAGS)

%.a: $(OBJS)
$(AR) r $@ $^

clean:
for i in $(OBJS); do (if test -e "$$i"; then ( rm $$i ); fi ); done
@rm -f $(BIN) $(LIB)

Xys
Posts: 7
Joined: Wed Apr 02, 2014 9:33 pm

Re: Developing for Pi in Visual Studio

Fri Apr 11, 2014 2:31 pm

ffelagund wrote:My setup is the next:
a) First I setup a external drive to hold the project files, and plug it into the windows machine. (dont program directly on the raspi SD. It's sooooo slow)
b) mount that driver in the raspi with sambaclient
c) create the normal visual studio project files
d) create a Makefile for the linux side. This could be very simple. I'm currently using something like the one I'd attached at the end of this post.
e) download putty package, the complete one, not just putty.exe. There it comes a command line utility called plink. This utility logs via ssh into a machine (your raspi) and launchs a command. This is my line
"C:\Program Files (x86)\PuTTY\plink.exe" -P MySSHPort -pw MyPassword -X myUserName@MyRaspiIP "cd /home/myusername/projectFolder/ && make -f Makefile all 2>&1 | perl /usr/bin/gccfilt.pl"
I usually setup the ssh server in a non default port, that's why I specify -P mySSHPort
You also have to specify your raspi user/pass/ip
The command changes the directory where my Makefile lies and than launches it, redirecting all output to an script (easy to find on internet) that translates gcc error format on visual studio format, so I can dbl click on an error and visual studio will bring me to the line and column where the error is.

Now, to execute this command you have two choice:
a) your visual studio project must be a NMAKE project, and the plink command line must be place in the build events section
b) your visual studio project could be a normal visual studio, but you can configure a menu entry (Tools->External Tools) to launch the command line. The best point on this option is that you can also build with visual studio's compiler for a multiplatform solution. (with proper #ifdefs of course)

I have 3 command lines, one build, one for clean and one for rebuild.

The only problem is the debugging. You cant debug directly in visual studio. You can do via ssh and using directly GDB, or using remote gdb debugging, using an IDE like eclipe or codeblocks.

This solution seems involved, but once you setup the system, programming is very comfortable.


Makefile:
OBJS=main.o
OBJS+=othersourcefiles.o

BIN=executable.bin

CFLAGS+= -Wall -Wno-reorder -O3

LDFLAGS+=-L$(SDKSTAGE)/opt/vc/lib/ -L./ -lGLESv2 -lEGL -lbcm_host

INCLUDES+=-I$(SDKSTAGE)/opt/vc/include/ -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux

.PRECIOUS: obj/*.o
.SECONDARY: $(OBJS)
all: $(BIN) $(LIB)

%.o: %.c
# @rm -f $@
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

%.o: %.cpp
# @rm -f $@
$(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $@

%.bin: $(OBJS)
$(CXX) -o $@ $(OBJS) $(LDFLAGS)

%.a: $(OBJS)
$(AR) r $@ $^

clean:
for i in $(OBJS); do (if test -e "$$i"; then ( rm $$i ); fi ); done
@rm -f $(BIN) $(LIB)



Can you write the steps in simpler way or show a tutorial or something. My project is to build a C++ program and run it on the pi,
I am desperate to make it work. I have been trying for a month now Ihave tried the mono comand and mono complete command, but it didnt work for some reason I can't understand the file not being transfered in binary or something.Then I tried the VisualVGD but also it requires new ssh connection which never works .can you help me ?
Thanks in advance

ffelagund
Posts: 30
Joined: Wed Nov 21, 2012 7:53 pm

Re: Developing for Pi in Visual Studio

Fri Apr 11, 2014 2:58 pm

The process can't be really simpler :/ To facilitate the process I only can do a step by step guide using screenshots, but I dont have time for that :/

Seriously, it can't take you a month setup the steps I put in my post :) Just go slow, step by step and being sure what you are doing at each point. Its easy, really.

Xys
Posts: 7
Joined: Wed Apr 02, 2014 9:33 pm

Re: Developing for Pi in Visual Studio

Fri Apr 11, 2014 4:42 pm

ffelagund wrote:The process can't be really simpler :/ To facilitate the process I only can do a step by step guide using screenshots, but I dont have time for that :/

Seriously, it can't take you a month setup the steps I put in my post :) Just go slow, step by step and being sure what you are doing at each point. Its easy, really.
First Thanks for replying
ok can you explain a bit more i will ask about what i cant understand
a) First I setup a external drive to hold the project files, and plug it into the windows machine. (dont program directly on the raspi SD. It's sooooo slow)
what external device like a flash memory or something I connect my pi to my laptop via SSH connection

b) mount that driver in the raspi with sambaclient
Where should I install the samba client
d) create a Makefile for the linux side. This could be very simple. I'm currently using something like the one I'd attached at the end of this post.
[i]making that makefile needs a software or what I dont get the code at the end of your post[/i]
e) download putty package, the complete one, not just putty.exe.
I already use PuTTy to work on my pi, So what is the complete PuTTy [/i

and The last point is I am building a C++ program with opencv so it has libraries and so I get a debug file how to execute the file is it by transfering to the pi and running the executable file?

Thanks for your patience

ffelagund
Posts: 30
Joined: Wed Nov 21, 2012 7:53 pm

Re: Developing for Pi in Visual Studio

Tue Apr 15, 2014 9:57 am

Xys wrote:First Thanks for replying
ok can you explain a bit more i will ask about what i cant understand
a) First I setup a external drive to hold the project files, and plug it into the windows machine. (dont program directly on the raspi SD. It's sooooo slow)
what external device like a flash memory or something I connect my pi to my laptop via SSH connection
Yes, I suggest to use a shared drive that could be accesible by your development machine and the Pi. I'd preffer not use directly the Pi's memory card to avoid the high read/write cycles that happens in a compilation/linking process during development.
Xys wrote:b) mount that driver in the raspi with sambaclient
Where should I install the samba client
You should install sambaclient in the Pi. Samba client is an utility to share drives across a network, so the development machine could access to it. Just mount natively the drive in the Pi and share to your Windows using samba. You can get samba using apt-get.
Xys wrote:d) create a Makefile for the linux side. This could be very simple. I'm currently using something like the one I'd attached at the end of this post.
making that makefile needs a software or what I dont get the code at the end of your post
A makefile is nothing more than a text file that holds the rules to build a project. It's an ancient system and I don't like it very much, but it's widely supported and is a sort of standard in linux systems. You can create it with a regular text editor (but keep in mind that tabs and whitespaces are relevant for that kind of files) At the end of my original post is the makefile I'd used to compile my project. It's quite generic.
Xys wrote:e) download putty package, the complete one, not just putty.exe.
I already use PuTTy to work on my pi, So what is the complete PuTTy

and The last point is I am building a C++ program with opencv so it has libraries and so I get a debug file how to execute the file is it by transfering to the pi and running the executable file?
To run the executable, if you need visual output, just keep a putty console open, and after the compilation process, simply run it. If your application does not produce more than text based outputs, just run it like you compile the process: use plink to launch the command from in Visual Studio.

If you get lost with the makefile, just replace it by a simple script with all needed commands to compile your project (all gcc/g++ commands)
About samba configuration, well, if you can't get through it, I only can say that if you are working with a Pi, samba is a key knowledge because allows you to access in a bidirectional way to the files and folders managed by the Pi. There are many good basic tutorials through the internet about this matter :)

Return to “OpenGLES”