[3674] | 1 | |
---|
| 2 | /* |
---|
| 3 | |
---|
| 4 | orxonox - the future of 3D-vertical scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify it |
---|
| 9 | under the terms of the GNU General Public License as published by the Free |
---|
| 10 | Software Foundation; either version 2, or (at your option) any later version. |
---|
| 11 | |
---|
| 12 | ### File Specific: |
---|
| 13 | main-programmer: David Gruetter |
---|
| 14 | co-programmer: ... |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | Created by Dave, in this file shadow will be implemented in a quite sexy and |
---|
| 18 | fast way, with a lot of opengl-code, to keep it fast! The origin of the code |
---|
| 19 | comes form an example at www.frustum.org, slitly different although, so that |
---|
| 20 | it works with Orxonox:) |
---|
| 21 | |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include "importer/material.h" |
---|
| 25 | #include "stdincl.h" |
---|
| 26 | #include <stdio.h> |
---|
| 27 | #include <stdarg.h> |
---|
| 28 | #include <malloc.h> |
---|
| 29 | #include <math.h> |
---|
| 30 | #include "shadow.h" |
---|
| 31 | |
---|
| 32 | #define SIZE 128 |
---|
| 33 | #define GL_CLAMP_TO_EDGE_EXT 0x812F |
---|
| 34 | |
---|
| 35 | using namespace std; |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | \brief default Constructor |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | Shadow::Shadow() |
---|
| 42 | { |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | \brief default destructor |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | Shadow::~Shadow() |
---|
| 51 | { |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | \don't ask me how this works, but it adds a blur effect to the shadow |
---|
| 57 | \for it doesn't look that edgy |
---|
| 58 | |
---|
| 59 | */ |
---|
| 60 | void Shadow::blur(unsigned char *in,int size) |
---|
| 61 | { |
---|
| 62 | int x,y,sum,size3=size*3; |
---|
| 63 | unsigned char *out,*inp,*outp; |
---|
| 64 | out = (unsigned char *)malloc(size * size * 3); |
---|
| 65 | memset(out,255,size *size *3); |
---|
| 66 | |
---|
| 67 | inp=in+size3; |
---|
| 68 | outp=out+size3; |
---|
| 69 | for(y=1;y<size-1;y++){ |
---|
| 70 | inp+=3; |
---|
| 71 | outp+=3; |
---|
| 72 | for(x=1;x<size-1;x++){ |
---|
| 73 | sum=inp[-size3-3]+ inp[-size3] + inp[-size3+3]+ |
---|
| 74 | inp[-3]+inp[0]+inp[3]+ |
---|
| 75 | inp[size3-3]+inp[size3]+inp[size3+3]; |
---|
| 76 | sum/=9; |
---|
| 77 | inp+=3; |
---|
| 78 | *outp++ =sum; |
---|
| 79 | *outp++ =sum; |
---|
| 80 | *outp++ =sum; |
---|
| 81 | } |
---|
| 82 | inp+=3; |
---|
| 83 | outp+=3; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | memcpy(in,out,size*size*3); |
---|
| 87 | free(out); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|