User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Fast pixel acces (noob)

Fri Mar 29, 2013 3:28 pm

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.
Apple say... Monkey do !!

Gomoto
Posts: 126
Joined: Tue Feb 12, 2013 1:21 am

Re: Fast pixel acces (noob)

Fri Mar 29, 2013 9:51 pm

I would recommend sdl or gtk library. There are many tutorials available (google).

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast pixel acces (noob)

Sat Mar 30, 2013 9:15 am

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
--
Gordons projects: https://projects.drogon.net/

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Fast pixel acces (noob)

Sat Mar 30, 2013 12:14 pm

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.
Apple say... Monkey do !!

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Fast pixel acces (noob)

Sat Mar 30, 2013 12:22 pm

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
--
Gordons projects: https://projects.drogon.net/

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Fast pixel acces (noob)

Sat Mar 30, 2013 1:54 pm

Thanks again but got it sorted, had to put -lSDL in the build command.

Cheers
Apple say... Monkey do !!

Return to “C/C++”