Page 1 of 1

Fast pixel acces (noob)

Posted: Fri Mar 29, 2013 3:28 pm
by davef21370
It's a long time since I used C, been messing with Python since I got the Pi and that's been okay but now I need some speed so C is the answer.

I need to know how to open a window to draw into and the fastest way to draw pixels. Ideally this would in the terminal just to gain a bit more speed but not essential.

Any help appreciated.
Noob... be gentle ;)

Dave.

Re: Fast pixel acces (noob)

Posted: Fri Mar 29, 2013 9:51 pm
by Gomoto
I would recommend sdl or gtk library. There are many tutorials available (google).

Re: Fast pixel acces (noob)

Posted: Sat Mar 30, 2013 9:15 am
by gordon@drogon.net
davef21370 wrote:It's a long time since I used C, been messing with Python since I got the Pi and that's been okay but now I need some speed so C is the answer.

I need to know how to open a window to draw into and the fastest way to draw pixels. Ideally this would in the terminal just to gain a bit more speed but not essential.

Any help appreciated.
Noob... be gentle ;)

Dave.
SDL will either open an X window that you can poke pixels into, or use the consoel framebuffer, so you get the best of both worlds.

-Gordon

Re: Fast pixel acces (noob)

Posted: Sat Mar 30, 2013 12:14 pm
by davef21370
Thanks all, I've gone down the SDL route and fallen at the first hurdle while following the tutorial at http://www.sdltutorials.com/sdl-tutorial-basics

I'm getting the error:
undefined reference to 'SDL_PollEvent'

and here's the code (checked and rechecked)

Code: Select all

#include "CApp.h"
#include "CApp_OnInit.cpp"
#include "CApp_OnEvent.cpp"
#include "CApp_OnLoop.cpp"
#include "CApp_OnRender.cpp"
#include "CApp_OnCleanup.cpp"

CApp::CApp() {
	Running = true;
}

int CApp::OnExecute() {
	if (OnInit() == false) {
		return -1;
	}
	
	SDL_Event Event;
	
	while (Running) {
		while (SDL_PollEvent(&Event)) {
			OnEvent(&Event);
		}
		OnLoop();
		OnRender();
	}
	OnCleanup();
	return 0;
}

int main(int argc, char* argv[]) {
	CApp theApp;
	
	return theApp.OnExecute();
}
again, any help much appreciated.
Dave.

edit.. I'm using Geany and not sure about where it looks for libs and stuff.

Re: Fast pixel acces (noob)

Posted: Sat Mar 30, 2013 12:22 pm
by gordon@drogon.net
davef21370 wrote:Thanks all, I've gone down the SDL route and fallen at the first hurdle while following the tutorial at http://www.sdltutorials.com/sdl-tutorial-basics

I'm getting the error:
undefined reference to 'SDL_PollEvent'

and here's the code (checked and rechecked)

Code: Select all

#include "CApp.h"
#include "CApp_OnInit.cpp"
#include "CApp_OnEvent.cpp"
#include "CApp_OnLoop.cpp"
#include "CApp_OnRender.cpp"
#include "CApp_OnCleanup.cpp"

CApp::CApp() {
	Running = true;
}

int CApp::OnExecute() {
	if (OnInit() == false) {
		return -1;
	}
	
	SDL_Event Event;
	
	while (Running) {
		while (SDL_PollEvent(&Event)) {
			OnEvent(&Event);
		}
		OnLoop();
		OnRender();
	}
	OnCleanup();
	return 0;
}

int main(int argc, char* argv[]) {
	CApp theApp;
	
	return theApp.OnExecute();
}
again, any help much appreciated.
Dave.

edit.. I'm using Geany and not sure about where it looks for libs and stuff.
Looks a bit c++ey to me... All my SDL stuff has been in pure C.

If you want an example, then navigate to: https://git.drogon.net/?p=rtb;a=blob;f= ... Keyboard.c

One thing to remember: the Pi is 16 bits per pixel. If you initialise SDL as 8 or 32 then it will work, but it will be very slow.

-Gordon

Re: Fast pixel acces (noob)

Posted: Sat Mar 30, 2013 1:54 pm
by davef21370
Thanks again but got it sorted, had to put -lSDL in the build command.

Cheers