Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Gay OO argh

Name: Anonymous 2009-11-11 7:03

I suppose I better learn one of them gay OO business oriented to be able to code inane custom apps for some corporate...

I come from the C demoscene school, so using OO and especially using stuff like .NET or JVM to me is like pulling my eyes out with a spoon; but the world changes nobody cares about pure performance anymore it seems. I gotta go with the flow...

So, which is the lesser of two evils for someone like me?
C# or Java?
(or any other you might suggest)

Name: Anonymous 2009-11-13 6:13

>>33
this is for you my love


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

#define DEFAULT_XRES             1024
#define DEFAULT_YRES             768

#define MAX_CIRCLE_ANGLE        512
#define HALF_MAX_CIRCLE_ANGLE         (MAX_CIRCLE_ANGLE/2)
#define QUARTER_MAX_CIRCLE_ANGLE     (MAX_CIRCLE_ANGLE/4)
#define MASK_MAX_CIRCLE_ANGLE         (MAX_CIRCLE_ANGLE - 1)
#define PI                 3.14159265358979323846f

float fast_cossin_table[MAX_CIRCLE_ANGLE];

__inline__ float fastcos(float x) {
    int i;
    i = (int)(x * HALF_MAX_CIRCLE_ANGLE / PI);
       if (i < 0) {
        return fast_cossin_table[((-i) + QUARTER_MAX_CIRCLE_ANGLE)&MASK_MAX_CIRCLE_ANGLE];
    } else {
        return fast_cossin_table[(i + QUARTER_MAX_CIRCLE_ANGLE)&MASK_MAX_CIRCLE_ANGLE];
       }
    printf("0");
}

__inline__ float fastsin(float x) {
    int i;
    i = (int)(x * HALF_MAX_CIRCLE_ANGLE / PI);
       if (i < 0) {
              return fast_cossin_table[(-((-i)&MASK_MAX_CIRCLE_ANGLE)) + MAX_CIRCLE_ANGLE];
       } else {
              return fast_cossin_table[i&MASK_MAX_CIRCLE_ANGLE];
       }
}

void buildsincos(void) {
    int i;
    for (i = 0; i < MAX_CIRCLE_ANGLE; i++) {
        fast_cossin_table[i] = (float)sinf(i * PI / HALF_MAX_CIRCLE_ANGLE);
    }
}

SDL_Surface *screen;
int quit = 0;
SDL_Event event;

SDL_Surface *skull = NULL;
SDL_Surface *skull_tmp = NULL;
SDL_Surface *tmp = NULL;
SDL_Surface *wavy = NULL;

int floorLog2(unsigned int n) {
    int pos = 0;
    if (n >= 1<<16) { n >>= 16; pos += 16; }
    if (n >= 1<< 8) { n >>=  8; pos +=  8; }
    if (n >= 1<< 4) { n >>=  4; pos +=  4; }
    if (n >= 1<< 2) { n >>=  2; pos +=  2; }
    if (n >= 1<< 1) {           pos +=  1; }
    return ((n == 0) ? (-1) : pos);
}

SDL_Rect posTmp;
SDL_Rect clipTmp;
inline void mega_super_fast_blit_tmp(int x, int y, SDL_Surface *src, SDL_Surface *dest)
{
    posTmp.x = x;
    posTmp.y = y;
    clipTmp.x = x;
    SDL_BlitSurface(src, &clipTmp, dest, &posTmp);
}

SDL_Rect pos;
SDL_Rect clip;
inline void mega_super_fast_blit(int x, int y, SDL_Surface *src)
{
    pos.y = y;
    pos.x = x;
    clip.y = y;
    SDL_BlitSurface(src, &clip, wavy, &pos);
}

GLuint texture;
GLenum texture_format;
GLint nOfColors;

int main(int argc, char *args[]) {
    assert(SDL_Init(SDL_INIT_VIDEO) != -1);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    screen = SDL_SetVideoMode(DEFAULT_XRES, DEFAULT_YRES, 32, SDL_OPENGL);
    assert(screen != NULL);
    buildsincos();

    Uint32 colorkey;
    tmp = SDL_LoadBMP("back.bmp");
    assert(tmp != NULL);
    skull = SDL_DisplayFormat(tmp);
    skull_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, skull->w, skull->h, 32, 0, 0, 0, 0);
    wavy = SDL_CreateRGBSurface(SDL_SWSURFACE, skull->w, skull->h, 32, 0, 0, 0, 0);
    SDL_FreeSurface(tmp);

    SDL_WM_SetCaption("Powah", NULL);

    unsigned int skullw = skull->w;
    unsigned int skullh = skull->h;

    float jit = 0.0f;
    float jitstep = 0.16f;
    float amp = 4.0f;
    float z = 0.0f;
    float x = 0.0f;
    float y = 0.0f;

    unsigned int slice = 1;
    int sliceShift = floorLog2(slice);

    clipTmp.y = 0;
    clipTmp.w = slice;
    clipTmp.h = skullh;

    clip.x = 0;
    clip.w = skullw;
    clip.h = slice;

    int skullws = skullw>>sliceShift;
        int skullhs = skullh>>sliceShift;

    int bandTbl[1024];
    register unsigned int e;
    for (e = 0; e<1024; e++)
            bandTbl[e] = (e<<sliceShift);


    glEnable(GL_TEXTURE_2D);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    // Set the texture's stretching properties
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   
    while (quit == 0) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                quit = 1;
            }
            if (event.type = SDL_KEYDOWN) {
                switch (event.key.keysym.sym) {
                    case SDLK_LEFT:
                        z += 0.2f;
                    break;
                    case SDLK_RIGHT:
                        z -= 0.2f;
                    break;

                    default:
                    break;
                }
            }
        }

        //unsigned int band = 0;

        for(e = 0; e < skullws; e++) {
            mega_super_fast_blit_tmp(bandTbl[e], fastsin(jit)*amp, skull, skull_tmp);
            jit += jitstep;
        }
        for(e = 0; e < skullhs; e++) {
            mega_super_fast_blit(fastcos(jit)*amp, bandTbl[e], skull_tmp);
            jit -= jitstep;
        }

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glClearDepth(1.0f);                            // Depth Buffer Setup
        glEnable(GL_DEPTH_TEST);                        // Enables Depth Testing
        glDepthFunc(GL_LEQUAL);   
        glViewport(0, 0, DEFAULT_XRES, DEFAULT_YRES);
        gluPerspective(45.0f, (GLfloat)DEFAULT_XRES/(GLfloat)DEFAULT_YRES, 0.1f, 100.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        gluLookAt(0, 0, z, 0, 0, 0, 0, 1, 0);
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexImage2D(GL_TEXTURE_2D, 0, 4, wavy->w, wavy->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, wavy->pixels);

        glBegin(GL_QUADS);
            glTexCoord2i(0, 0);
            glVertex3f(1.0f, 1.0f, 0.0f);
   
            //Bottom-left vertex (corner)
            glTexCoord2i(1, 0);
            glVertex3f(-1.0f, 1.0f, -5.0f);
   
            //Bottom-right vertex (corner)
            glTexCoord2i(1, 1);
            glVertex3f(-1.0f, -1.0f, -5.0f);
   
            //Top-right vertex (corner)
            glTexCoord2i(0, 1);
            glVertex3f(1.0f, -1.0f, 0.0f);
        glEnd();

        SDL_GL_SwapBuffers();
        SDL_Delay(15);
    }
    SDL_FreeSurface(skull);
    SDL_FreeSurface(wavy);
    SDL_FreeSurface(skull_tmp);
    SDL_Quit();
    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List