Fix hard-coded screen size; increase number of pixels.
#include <GLES/gl.h>
#include "SDL.h"
-Pixel::Pixel(void) {
- this->x = (rand() / (float)RAND_MAX) * 320.0;
- this->y = (rand() / (float)RAND_MAX) * 400.0;
+Pixel::Pixel(SDL_Surface* screen) {
+ this->x = (rand() / (float)RAND_MAX) * screen->w;
+ this->y = (rand() / (float)RAND_MAX) * screen->h;
this->vx = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
this->vy = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
this->lastupdate = SDL_GetTicks();
float x, y;
float vx, vy;
- Pixel(void);
+ Pixel(SDL_Surface* screen);
~Pixel(void);
void accel(float x, float y);
void update();
#include "SDL.h"
#include "PDL.h"
#include "Pixel.h"
-#define NPIXELS 2000
+
+#define NPIXELS 2500
+#define SCREENW 320
+#define SCREENH 480
SDL_Surface* screen; // Screen surface
Uint16 mx, my;
glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrthof(0.0f, 320.0f, 400.0f, 0.0f, -1.0f, 1.0f);
+ glOrthof(0.0f, (float)screen->w, (float)screen->h, 0.0f, -1.0f, 1.0f);
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
// Initialize vertices
glVertexPointer(3, GL_FLOAT, 0, vertices);
// Center cursor
- mx = 160;
- my = 200;
+ mx = screen->w / 2;
+ my = screen->h / 2;
// Initialize pixel objects
pixels = new Pixel*[NPIXELS];
for (int x = 0; x < NPIXELS; x++) {
- pixels[x] = new Pixel();
+ pixels[x] = new Pixel(screen);
}
}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
// Set the video mode to full screen with OpenGL-ES support
- screen = SDL_SetVideoMode(320, 400, 0, SDL_OPENGL);
+ screen = SDL_SetVideoMode(SCREENW, SCREENH, 0, SDL_OPENGL);
if (!screen) {
printf("Could not initialize video!\n");
exit(1);
}
printf("width: %d, height, %d\n", screen->w, screen->h);
+ printf("Starting up with %d pixels\n", NPIXELS);
#if WIN32
// Load the desktop OpenGL-ES emulation library
SDL_WaitEvent(NULL);
while (SDL_PollEvent(&Event)) {
switch (Event.type) {
- // List of keys that have been pressed
- case SDL_KEYDOWN:
- switch (Event.key.keysym.sym) {
- // Escape forces us to quit the app
- // this is also sent when the user makes a back gesture
- case SDLK_ESCAPE:
- Event.type = SDL_QUIT;
- break;
- default:
- break;
- }
- break;
case SDL_MOUSEMOTION:
mx = Event.motion.x;
my = Event.motion.y;