indexbase 0
#include "freeglut.inc"
% ImageWidth 512
% ImageHeight 512
byte MatrixImage[ImageHeight*ImageWidth*4];
float InterPolation(float a, float b, float c)
{
return a+(b-a)*c*c*(3-2*c);
}
float InterpLinear(float a, float b, float c)
{
return a*(1-c)+b*c;
}
float Noise(int v)
{
static double d=1/0x7fffffff
mov eax,v
rol eax,5
mul v
xor eax,0x9595adad
mul v
rol eax,3
and eax,0x7fffffff 'always positive
mov v,eax
return v*d 'range 0..1.0
}
void AddTex(sys i,r,g,b,a)
{
sys x,y,a
float v1,v2,v3,v4,v5,v6,v7
dv=1/i
mk=i
neg mk
off=0x35353535
byte mb at (@MatrixImage)
for y=0 to <ImageWidth
{
y1=y and mk
y2=y1+i
y3=y1*ImageWidth+off
y4=y2*ImageWidth+off
for x=0 to <ImageHeight
{
x1=x and mk
x2=x1+i
v1=noise(y3+x1)
v2=noise(y3+x2)
v3=noise(y4+x1)
v4=noise(y4+x2)
'
v5=interpolation(v1,v2,(x-x1)*dv)
v6=interpolation(v3,v4,(x-x1)*dv)
v7=interpolation(v5,v6,(y-y1)*dv)
mb+=v7*r
@mb++
mb+=v7*g
@mb++
mb+=v7*b
@mb++
mb+=v7*a
@mb++
}
}
}
void MakeImage()
{
'scale,rgba bytes
'
AddTex 64,100, 50, 0, 128
AddTex 32, 64, 32, 0, 128
AddTex 16, 48, 24, 0, 128
AddTex 8, 24, 12, 0, 128
AddTex 4, 12, 6, 0, 128
AddTex 2, 6, 3, 0, 128
AddTex 1, 3, 2, 0, 128
}
extern cdecl
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
makeImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0, 0);
glDrawPixels(ImageWidth, ImageHeight, GL_RGBA,
GL_UNSIGNED_BYTE, MatrixImage);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, w, 0.0, h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(byte key, int x, int y)
{
switch key
case 27:
GlutExit();
case else
end switch
}
end extern
int main(int argc, char** argv)
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
finit
init();
glutDisplayFunc(@display);
glutReshapeFunc(@reshape);
glutKeyboardFunc(@keyboard);
glutMainLoop();
return 0;
}
char *argv
int argc
main argc,argv