We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
OpenGL Capabilities (Read 1225 times)
OpenGL Capabilities
Jun 19th, 2008, 4:03am
 
I'm working on a 2D project that involves 2-3 large images (1390x768 or so) with alpha channels plus a lot of smaller shapes and (if I can) images. It's starting to get kind of slow (15fps or worse on a 2.2ghz).

I'm guessing that all the processing is on the CPU when using PImage (CPU is at 95% the whole time) and was wondering if OpenGL could somehow be applied to strictly 2D situations, so I could take advantage of the GPU.

If so, how is something as simple as layering 1390x768 PNGs done?

I'm not all that experienced in the graphical side of programming but it seems crazy that I'm having trouble working with a few large images when most games have hundreds of polygon faces visible at once each with their own texture that's scaled, lit, and angled all in realtime PLUS alpha-blended sprites of explosions or what have you.
Re: OpenGL Capabilities
Reply #1 - Jun 19th, 2008, 12:57pm
 
> wondering if OpenGL could somehow be applied to strictly 2D situations

z = 0; 8)

actually, opengl has 2d equivalents of all the 3d methods like:

glVertex2d(0.5, 0.0);

and processing will have its equivalents.

just place your camera so it's looking along the z axis and draw away.

can't see any examples here (but i didn't look very hard):
http://processing.org/learning/3d/

(i wrote something last night that was 5 1024x1024 textures moving over each other with additive blending and it ran at 115 fps on my laptop. was written in C but it gives you an idea)
Re: OpenGL Capabilities
Reply #2 - Jun 20th, 2008, 4:13am
 
Thanks for the response, I've been burying my head in some code and getting in over my head ever since.

It would be a amazingly huge help if you or someone else give me the OpenGL equivalent of the following code, any chance of that happening?

http://www.paulpritchard.ca/rtt/opengl.zip (includes the two images and the code below)

Code:

// Will making this OpenGL speed things up?

PImage imgGradient, imgWorld;

void setup() {
size(1390, 720);
imgGradient = loadImage("grad.gif"); //both of these images are 1390x720
imgWorld = loadImage("worldsm.png"); //imgWorld has an alpha mask
}

void draw() {
image(imgGradient,0,0);
image(imgWorld,0,0);
// Things will be going on in front of these two
}


This is just an incredibly simple version of what I've been working on in 2d. The final product will be an animated world map with sprites popping up, stats flashing by, and basically a whole lot of movement on top of these hi-res images.
Re: OpenGL Capabilities
Reply #3 - Jun 20th, 2008, 7:04am
 
I don't know OpenGL enough to really help, but if the blend is static, I would either do it once and for all or do the blend in setup() and use the resulting PImage in the draw() routine.
I wonder why you use a Gif image for the gradient...
Re: OpenGL Capabilities
Reply #4 - Jun 20th, 2008, 1:53pm
 
For the gradient, I tried some of the pixel-setting functions found here (non-Open GL mind you) and they were incredibly slow so I stuck with the GIF, which seemed quickest.

Ideally the Alpha Blending would be continuous, as there are also a couple things going on between the gradient and the world map images.
Re: OpenGL Capabilities
Reply #5 - Jun 20th, 2008, 11:22pm
 
i've reduced the screen size (my laptop isn't that wide) and drawn a rectangle between the two image layers and another on top of them just to show it can be done.

NB drawing order is important - furthest away items must be drawn first.

Code:

// Will making this OpenGL speed things up?
// yes!

import processing.opengl.*;

PImage imgGradient, imgWorld;

void setup() {
size(1024, 768, OPENGL);
imgGradient = loadImage("grad.gif");
imgWorld = loadImage("worldsm.png");
}

void draw() {
// background
image(imgGradient,0,0);

// rectangle between layers
rect(156, 260, 200, 200);

// world
image(imgWorld,0,0);

// rectangle on top
rect(668, 260, 200, 200);
}
Re: OpenGL Capabilities
Reply #6 - Jun 23rd, 2008, 5:41am
 
Wow, just adding

Code:

import processing.opengl.*;


and

Code:

size(1024, 768, OPENGL);


to my original code made things 10x faster (with the exception of one shape that I was going to get rid of anyways)!

Thanks a million.
Page Index Toggle Pages: 1