Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 06-16-2005, 07:51 AM
Gman4pwnu Gman4pwnu is offline
Banned
Join Date: Jan 2004
Posts: 434
Gman4pwnu is on a distinguished road
Send a message via AIM to Gman4pwnu
Why? its half the size gambet, only 102 lines total...
NPC Code:

#include <stdlib.h>
#include <iostream>
#if defined(_MSC_VER)
#include "SDL.h"
#else
#include "SDL/SDL.h"
#endif

SDL_Surface *screen;
#define PUTPIXEL(x,y,c) \
((unsigned int*)screen->pixels)[(x) + (y) * (screen->pitch / 4)] = (c);

int SWIDTH=1280, SHEIGHT=1024;

void render()
{
// Lock surface if needed
if (SDL_MUSTLOCK(screen))
if (SDL_LockSurface(screen) < 0)
return;

// Ask SDL for the time in milliseconds
int tick = SDL_GetTicks();

// Declare a couple of variables
int i, j, yofs, ofs;

// Draw to screen
yofs = 0;
for (i = 0; i < SHEIGHT; i++)
{
for (j = 0, ofs = yofs; j < SWIDTH; j++, ofs++)
{
((unsigned int*)screen->pixels)[ofs] = i * i + j * j + tick;
}
yofs += screen->pitch / 4;
}
PUTPIXEL(10, 10, 0xff0000);
PUTPIXEL(11, 10, 0xff0000);
PUTPIXEL(10, 11, 0xff0000);
PUTPIXEL(11, 11, 0xff0000);
// Unlock if needed
if (SDL_MUSTLOCK(screen))
SDL_UnlockSurface(screen);

// Tell SDL to update the whole screen
SDL_UpdateRect(screen, 0, 0, SWIDTH, SHEIGHT);
}


// Entry point
int main(int argc, char *argv[])
{
std::cout << "Lance Leone you gonna get raped.";
// Initialize SDL's subsystems - in this case, only video.
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}

// Register SDL_Quit to be called at exit; makes sure things are
// cleaned up when we quit.
atexit(SDL_Quit);

// Attempt to create a 640x480 window with 32bit pixels.
// screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
screen = SDL_SetVideoMode(SWIDTH, SHEIGHT, 32, SDL_SWSURFACE);

// If we fail, return error.
if ( screen == NULL )
{
fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}

// Main loop: loop forever.
while (1)
{
// Render stuff
render();

// Poll for events, and handle the ones we care about.
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_KEYUP:
// If escape is pressed, return (and thus, quit)
if (event.key.keysym.sym == SDLK_ESCAPE)
return 0;
break;
case SDL_QUIT:
return(0);
}
}
}
return 0;
}

Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.