Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL/SDL.h>
- #include <GL/glew.h>
- #include <stdlib.h>
- #include <math.h>
- #define WIDTH 1024
- #define HEIGHT 1024
- #define OSCN 3
- #define FN 2
- #define SAMPLERATE 48000
- GLUquadricObj *q;
- GLuint myp;
- GLint ut, ut2, vb, tim, ttim, i;
- float o_p[OSCN]={0}, o_f[OSCN]={0}, lp[FN][4] = {0}, f_f[2]={0}, bassd = 0;
- long mlc = 0, ml = -1;
- void sa(void *u, Uint8 *s, int l) {
- float *ass;
- long i,k;
- Sint16 *p = (Sint16*)s;
- for(; l > 0; l -= 2) {
- f_f[0] = 0.00004 + .999 * f_f[0];
- f_f[1] *= .9996;
- if((mlc -= (int)(0x1000000 * 9.6667 / SAMPLERATE)) < 0) {
- float kgg;
- ml++;
- kgg = pow(1.059, "<<HH<<H<<<HHHHFH"[15&ml]-'A') * 55.0f / SAMPLERATE;
- o_f[0] = kgg;
- o_f[1] = 0.5*kgg * 1.012;
- o_f[2] = kgg * 0.993;
- if("..##.###.###.###"[15&ml] == '#') f_f[0] = .3; else o_f[0]=0;
- if("#...#...#...#..."[15&ml] == '#') bassd = 0;
- f_f[1] = ("CCbCICbCCCbCICbC"[15&ml] - 'A') / 40.0;
- mlc += 0x1000000;
- }
- for(i = 0; i < OSCN; i++) o_p[i] = fmod(o_p[i] + o_f[i] + .5, 1) - .5;
- lp[0][0] = (mlc > 0x300000 ? o_p[0] + o_p[1]/2 + o_p[2]/9 : 0) - lp[0][3];
- lp[1][0] = (0x3FFF & rand()) - 0x2000 - 5 * lp[1][3];
- for(k = FN; k--;) {
- for(i=1;i<4;i++) lp[k][i] = fmax((1-f_f[k]) * lp[k][i] + f_f[k] * lp[k][i-1], -18000);
- }
- *p++ = (9999 * lp[0][3] + 500 * tanh(.003 * lp[1][2]) + 3000 * tanh(5*sin(bassd / (23 + 0.01*bassd++))));
- }
- }
- void tr(int n, float lgth)
- {
- glUniform1iARB(ut,n);
- glUniform1iARB(ut2,tim);
- gluCylinder(q,lgth/10.,lgth/10.,lgth,4,2);
- glPushMatrix();
- if (n == 1)
- glScalef(2*(tim/6000.),2*(tim/6000.),0.1);
- if (n--)
- {
- glTranslatef(0,0, lgth);
- glRotatef(60, 0, 0.4, 1);
- tr(n, lgth*0.8);
- glRotatef(-80, 0, 1, 1);
- tr(n, lgth*0.8);
- }
- glPopMatrix();
- }
- /* Some texture shit. */
- GLuint world_tex;
- int tex_size_x = WIDTH;
- int tex_size_y = HEIGHT;
- int lol = 0;
- int sc1()
- {
- GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
- glLightfv(GL_LIGHT0, GL_AMBIENT, specular);
- glPushMatrix();
- /* Here be trees */
- glTranslatef(0,0,0);
- glRotatef(270, 1, 0, 0);
- glDisable(GL_TEXTURE_2D);
- glColor4f(0.5, 0.5, 1.5, 0.5);
- for (i = -1; i < 12; i++)
- {
- glRotatef(40, 0, 0, 1);
- glPushMatrix();
- glTranslatef((sin(i/4.5)*5.), cos(i/1.5)*4.5, 0);
- tr(7, 1.0);
- glPopMatrix();
- }
- glPopMatrix();
- /* Here be water */
- glUniform1iARB(ut,12);
- glTranslatef(0, 0, -10);
- glRotatef(90, 1, 0, 0);
- gluDisk (q, 0.0, 100, 4, 1);
- glRotatef(-90, 1, 0, 0);
- /* Here be the ground. */
- glUniform1iARB(ut,10);
- GLfloat specular2[] = {0.0, 1.0, 1.0, 1.0};
- glLightfv(GL_LIGHT0, GL_AMBIENT, specular2);
- //glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, world_tex);
- //glDisable(GL_LIGHTING);
- //glRotatef(90, 0, 1, 0);
- glRotatef(90, 1, 0, 0);
- glTranslatef(-10, -10, 0);
- for (int i = 0; i < 15; i++) {
- for (int j = 0; j < 15; j++) {
- glTranslatef(2, 0, 0);
- gluDisk (q, 0.0, 1, 4, 1);
- }
- glTranslatef(-30, 2, 0);
- }
- glTranslatef(1, -31, 0);
- for (int i = 0; i < 15; i++) {
- for (int j = 0; j < 15; j++) {
- glTranslatef(2, 0, 0);
- gluDisk (q, 0.0, 1, 4, 1);
- }
- glTranslatef(-30, 2, 0);
- }
- /*
- for (int i = 0; i < 20; i++) {
- glRotatef(tim/100.+50, 0, 0, 1);
- gluDisk (q, 0.0, 1.4, 4, 1);
- }
- */
- lol++;
- //glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, WIDTH, HEIGHT, 0);
- glEnable(GL_LIGHTING);
- }
- int sc2()
- {
- }
- void printLog(GLuint obj)
- {
- int infologLength = 0;
- char infoLog[1024];
- if (glIsShader(obj))
- glGetShaderInfoLog(obj, 1024, &infologLength, infoLog);
- else
- glGetProgramInfoLog(obj, 1024, &infologLength, infoLog);
- if (infologLength > 0)
- printf("%s\n", infoLog);
- }
- int main()
- {
- q=gluNewQuadric();
- gluQuadricTexture(q, GL_TRUE);
- gluQuadricNormals(q, GL_AUTO_NORMAL);
- SDL_Event e;
- SDL_SetVideoMode(WIDTH, HEIGHT,32, SDL_OPENGL);
- glMatrixMode(GL_PROJECTION);
- gluPerspective(45.0f,800/640,0.1f,90.0f);
- glMatrixMode(GL_MODELVIEW);
- SDL_AudioSpec r={SAMPLERATE,AUDIO_S16,1,0,0x200,0,0,sa,NULL};
- SDL_OpenAudio(&r,NULL);
- // SDL_Delay(1000);
- // SDL_PauseAudio(0);
- // some texture shit
- printf( "VENDOR = %s\n", glGetString( GL_VENDOR ) ) ;
- printf( "RENDERER = %s\n", glGetString( GL_RENDERER ) ) ;
- printf( "VERSION = %s\n", glGetString( GL_VERSION ) ) ;
- unsigned int* data;
- // Create Storage Space For Texture Data (128x128x4)
- data = (unsigned int*)new GLuint[((tex_size_x * tex_size_y)* 4 * sizeof(unsigned int))];
- data = (unsigned int*)memset(data, 0, ((tex_size_x * tex_size_y)* 4 * sizeof(unsigned int)));
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &world_tex); // Create 1 Texture
- glBindTexture(GL_TEXTURE_2D, world_tex); // Bind The Texture
- glTexImage2D(GL_TEXTURE_2D, 0, 4, tex_size_x, tex_size_y, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, data); // Build Texture Using Information In data
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glEnable(GL_DEPTH_TEST);
- delete [] data;
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- glEnable(GL_BLEND);
- glewInit();
- printf("TESTI\n");
- char ves[] = "uniform int time; uniform int no; varying vec4 diffuse,ambient; varying vec3 normal,lightDir,halfVector;\
- void main() { \
- normal = normalize(gl_NormalMatrix * gl_Normal); \
- lightDir = normalize(vec3(gl_LightSource[0].position)); \
- halfVector = normalize(gl_LightSource[0].halfVector.xyz);\
- diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;\
- ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;\
- ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;\
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\
- gl_Position.y += sin(gl_Position.z*0.5)*2.5;\
- if (no == 10) { \
- gl_Position.y += cos(gl_Position.x*3.0);\
- normal.x += sin(gl_Vertex.x);\
- }\n\
- }";
- char frs[] = "uniform int time; uniform int no; varying vec4 diffuse,ambient; varying vec3 normal,lightDir,halfVector; \n\
- void main() { \n\
- vec3 n,halfV;\n\
- float NdotL,NdotHV;\n\
- vec4 color = ambient\n;\
- n = normalize(normal);\n\
- NdotL = max(dot(n,lightDir),0.0);\n\
- if (NdotL > 0.0) { \n\
- color += diffuse * NdotL; \n\
- halfV = normalize(halfVector); \n\
- NdotHV = max(dot(n,halfV),0.0); \n\
- color += gl_FrontMaterial.specular * \n\
- gl_LightSource[0].specular * \n\
- pow(NdotHV, gl_FrontMaterial.shininess);} \n\
- gl_FragColor = color;\n\
- gl_FragColor[0] *= 0.39;\n\
- if (no == 10) \n\
- gl_FragColor[0] *= 0.39 * sin(n.x);\n\
- if (no == 12) \n\
- gl_FragColor[2] *= 3.0;\n\
- gl_FragColor[1] *= 0.26;\n\
- gl_FragColor[2] *= 0.13;\n\
- if (no == 0) { \
- gl_FragColor[1] *= 1.5; \
- } \
- }";
- const GLcharARB * myfs;
- const GLcharARB * myvs;
- myfs = &frs[0];
- myvs = &ves[0];
- GLenum myv;
- GLenum myf;
- printf("TESTI\n");
- /* SEURAAVAAN KAATUU ********************/
- myp = glCreateProgram();
- printf("TESTI\n");
- myv = glCreateShader(GL_VERTEX_SHADER_ARB);
- myf = glCreateShader(GL_FRAGMENT_SHADER_ARB);
- glShaderSource(myv, 1, &myvs, NULL);
- glShaderSource(myf, 1, &myfs, NULL);
- glCompileShader(myv);
- glCompileShader(myf);
- glAttachShader(myp, myv);
- glAttachShader(myp, myf);
- printLog(myv);
- printLog(myf);
- glLinkProgram(myp);
- glUseProgram(myp);
- GLint errors;
- glGetShaderiv(myp,GL_COMPILE_STATUS, &errors);
- ttim = SDL_GetTicks();
- /* C shit
- const static void (*sc[])() = { sc1, sc2};
- const unsigned int scs[] ={30, 90};
- */
- GLfloat LP[]= { 0.0f,4.0f, 2.0f, 1.0f };
- glLightfv(GL_LIGHT0, GL_POSITION,LP);
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHTING);
- ut = glGetUniformLocationARB(myp,"no");
- ut2 = glGetUniformLocationARB(myp,"time");
- int FPS = 0;
- int FPS2 = 0;
- float rotatex, rotatey = 0;
- float movex, movez = 0;
- while (1)
- {
- /* MOUSE + keyboard HANDLING FOR TESTING ONLY! */
- while ( SDL_PollEvent(&e) ) {
- switch (e.type) {
- case SDL_MOUSEMOTION:
- rotatex += e.motion.xrel;
- rotatey += e.motion.yrel;
- break;
- case SDL_MOUSEBUTTONDOWN:
- printf("Mouse button %d pressed at (%d,%d)\n",
- e.button.button, e.button.x, e.button.y);
- break;
- case SDL_QUIT:
- exit(0);
- }
- }
- /* THE 4K key handling.
- SDL_PollEvent(&e);
- if (e.type==SDL_KEYDOWN)
- break;
- */
- tim=SDL_GetTicks() - ttim;
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- GLfloat LP[]= { 0,cos(tim/500.)*20, sin(tim/500.)*20, 1.0f };
- glLightfv(GL_LIGHT0, GL_POSITION,LP);
- glTranslatef(0,-4,-15);
- glRotatef(rotatey, 1, 0, 0);
- glRotatef(rotatex, 0, 1, 0);
- //glRotatef(5 + (fabs(sin(tim/2000.))*30), 1, 0, 0);
- int sk = -1;
- sc1();
- FPS++;
- if (tim - FPS2 > 2000)
- {
- printf("%i\n", FPS/2);
- FPS2 = tim;
- FPS = 0;
- }
- SDL_GL_SwapBuffers();
- }
- SDL_Quit();
- return 0;
- }
- // Directional Lighting PER VERTEX
- /*
- char ves[] = "uniform int time; void main() {\
- vec3 normal, lightDir; \
- vec4 diffuse; \
- float NdotL; \
- normal = normalize(gl_NormalMatrix * gl_Normal); \
- lightDir = normalize(vec3(gl_LightSource[0].position)); \
- NdotL = max(dot(normal, lightDir), 0.0); \
- diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; \
- gl_FrontColor = NdotL * diffuse; \
- gl_Position = ftransform(); \
- }";
- char frs[] = "uniform int time; void main() {gl_FragColor = gl_Color;\
- if (time > 1){\
- gl_FragColor[0] *= 0.39;\
- gl_FragColor[1] *= 0.26;\
- gl_FragColor[2] *= 0.13;}\
- else{\
- gl_FragColor[0] *= 0.29;\
- gl_FragColor[1] *= 0.46;\
- gl_FragColor[2] *= 0.03;}\
- }";
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement