Linux-SWAT
Forum Addict!
- Joined
- Feb 13, 2010
- Messages
- 9,188
I myself don't care.So are we using this thread, the PM or the google doc? It seems rather silly to use all three
I just avoid cloud stuff, and prefer the PM for "secret" things.
I myself don't care.So are we using this thread, the PM or the google doc? It seems rather silly to use all three
// Pandora SHOOT EM UP, BEST SHOOT EM UP FOREVER AND EVER!!!1
#include "SDL/SDL.h"
#include "GL/glew.h"
#include "iostream"
#include "fstream"
#include "math.h"
using namespace std;
enum {Vertice,TextureCordinate};// FOR SHADERS
// EASY ROTATION FUNCTION FOR GENERAL PURPOSE
float ralign=360.0;// For the rotation function, changes starting position to calculate from.
void rotate(float xp,float yp,float& ux,float& uy,float degrees){float bt,lx,ly,rx,ry,nnx,a;
if(uy<=yp&&ux>=xp){a=atan((yp-uy)/((ux-xp)))*57.295779579;lx=ux-xp;ly=yp-uy;}if(uy<=yp&&xp>ux)
{a=90.0+(90.0-acos((xp-ux)/(sqrt(((yp-uy)*(yp-uy))+((xp-ux)*(xp-ux)))))*57.295779579);lx=xp-ux;ly=yp-uy;}
if(yp<uy&&xp>ux){a=270.0-(90.0-(atan((uy-yp)/((xp-ux)))*57.295779579));lx=xp-ux;ly=uy-yp;}if(yp<uy&&ux>=xp)
{a=360.0-(acos((ux-xp)/(sqrt(((uy-yp)*(uy-yp))+((ux-xp)*(ux-xp)))))*57.295779579);lx=ux-xp;ly=uy-yp;}
a=((ralign-a)+degrees)+45.0;rx=cos(a*0.017453292)+sin(a*0.017453292);ry=-sin(a*0.017453292)+cos(a*0.017453292);
nnx=sqrt((rx*rx)+(ry*ry));bt=sqrt((lx*lx)+(ly*ly));rx/=nnx;ux=xp+(rx*bt);ry/=nnx;uy=yp-(ry*bt);}
// Size of a pixel on Pandoras screen ("2"/800 = 0.0025 = X value) ("2" = openGL -1.0 to 1.0 screen space range)
float pixel_to_gl_X = 0.0025, pixel_to_gl_Y = 0.004166667;
int main(int argc,char *argv[]){//**************************************************************** MAIN STARTS HERE
int sw=800,sh=480,sc=16;// SCREEN WIDTH and HEIGHT and COLOR RESOLUTION
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
SDL_Surface* s1=SDL_SetVideoMode(sw,sh,sc,SDL_HWSURFACE|SDL_OPENGL);
SDL_Event gameover;Uint8* key;int quit=0;
int c=0,d=0,e=0,f=0;// COUNTERS
unsigned int oldTime=0,currentTime=0,ct;unsigned char framerate=10;// FPS LIMITER
static GLint T0=0,Frames=0;// FOR FPS PRINTING FUNCTION
glewInit();
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,0,9999);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glClearStencil(0);
//********************************************************************************* CREATE SHADER.
char * buffer1, * buffer2;int lenght1,lenght2;
ifstream is1,is2;is1.open("psv.txt",ios::binary);is1.seekg(0,ios::end);
lenght1=is1.tellg();is1.seekg(0,ios::beg);buffer1=new char [lenght1];
is1.read(buffer1,lenght1);is1.close();buffer1[lenght1-1]=0;
is2.open("psf.txt",ios::binary);is2.seekg(0,ios::end);
lenght2=is2.tellg();is2.seekg(0,ios::beg);buffer2=new char [lenght2];
is2.read(buffer2,lenght2);is2.close();buffer2[lenght2-1]=0;
const GLchar* vv=buffer1;const GLchar* ff=buffer2;//cout<<vv<<endl;cout<<ff<<endl;
GLenum vert=glCreateShader(GL_VERTEX_SHADER);glShaderSource(vert, 1, &vv, NULL);glCompileShader(vert);
GLenum frag=glCreateShader(GL_FRAGMENT_SHADER);glShaderSource(frag, 1, &ff, NULL);glCompileShader(frag);
/*int IsCompiled_FS;glGetShaderiv(frag,GL_COMPILE_STATUS,&IsCompiled_FS);
if(IsCompiled_FS==true){cout<<"FRAG=GOOD!"<<endl;}else{cout<<"FRAG=BAD..."<<endl;}
glGetShaderiv(vert,GL_COMPILE_STATUS,&IsCompiled_FS);
if(IsCompiled_FS==true){cout<<"VERT=GOOD!"<<endl;}else{cout<<"VERT=BAD..."<<endl;}*/
GLenum prog = glCreateProgram();glAttachShader(prog,vert);glAttachShader(prog,frag);
glBindAttribLocation(prog,Vertice,"a_vertice");
glBindAttribLocation(prog,TextureCordinate,"a_texCor");
glLinkProgram(prog);//glGetProgramiv(prog,GL_LINK_STATUS,(int *)&IsCompiled_FS);
//if(IsCompiled_FS==true){cout<<"LINK=GOOD!"<<endl;}else{cout<<"LINK=BAD..."<<endl;}
delete[] buffer1;delete[] buffer2;
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SHADER IS COMPLETE.
glEnableVertexAttribArray(Vertice);
glEnableVertexAttribArray(TextureCordinate);
glUseProgram(prog);
// RGBA parameter is in preperation for GLES, there needs to be a function to swap R and B channel of BMP image...
/*SDL_Surface* texturesar[100];//::::::::::::::::::::::::::::::::::::::::::::::: LOAD TEXTURES TO RAM.
GLuint texture[30];
texturesar[0]=SDL_LoadBMP("mud.bmp");
texturesar[1]=SDL_LoadBMP("nm2.bmp");
glActiveTexture(GL_TEXTURE0);
glGenTextures(1,&texture[20]);
glBindTexture(GL_TEXTURE_2D, texture[20]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,
texturesar[0]->w,texturesar[0]->h,0,
GL_RGBA,GL_UNSIGNED_BYTE,texturesar[0]->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glActiveTexture(GL_TEXTURE1);
glGenTextures(1,&texture[21]);
glBindTexture(GL_TEXTURE_2D, texture[21]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,
texturesar[1]->w,texturesar[1]->h,0,
GL_RGBA,GL_UNSIGNED_BYTE,texturesar[1]->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);*/
float mechaX=0.0,mechaY=0.0;
float v1x,v1y,v2x,v2y,v3x,v3y,v4x,v4y,sizeX=60.0,sizeY=60.0,zr2=0.0;
while(quit==0){//******************************************************************** GAME LOOP START.
while(SDL_PollEvent(&gameover))
{if(gameover.type==SDL_QUIT){quit=1;}}
key=SDL_GetKeyState(NULL);
if(key[SDLK_ESCAPE]){quit=1;}
if(key[SDLK_UP]){mechaY+=pixel_to_gl_Y;if(mechaY>1.0){mechaY=1.0;}}
if(key[SDLK_DOWN]){mechaY-=pixel_to_gl_Y;if(mechaY<-1.0){mechaY=-1.0;}}
if(key[SDLK_LEFT]){mechaX-=pixel_to_gl_X;if(mechaX<-1.0){mechaX=-1.0;}}
if(key[SDLK_RIGHT]){mechaX+=pixel_to_gl_X;if(mechaX>1.0){mechaX=1.0;}}
if(key[SDLK_q]){zr2+=1.0;}
if(key[SDLK_w]){zr2=0.0;}
// GET RENDER INFO
sizeX=60.0;sizeY=60.0;//Get zr2 value from object data also
// SEND DATA TO SHADERS
int location1=glGetUniformLocation(prog,"u_cameraPos");
glUniform3f(location1, 0.0, 0.0, 0.0);
int location2=glGetUniformLocation(prog,"section");
glUniform1i(location2, 0);
int location3=glGetUniformLocation(prog,"mtex");
glUniform1i(location3, 1);
int location4=glGetUniformLocation(prog,"nm");
glUniform1i(location4, 0);
glClearColor(0.0f,0.0f,0.0f,0.0f);//********************************************** START RENDER TO SCREEN.
glClear(GL_COLOR_BUFFER_BIT);
float sk[12],stex[12];// SCREEN QUAD
sk[0]=-1.0;sk[1]=-1.0;
sk[2]= 1.0;sk[3]=-1.0;
sk[4]=-1.0;sk[5]= 1.0;
sk[6]= 1.0; sk[7]= 1.0;
sk[8]= -1.0; sk[9]= 1.0;
sk[10]= 1.0;sk[11]=-1.0;
stex[0]=0.0;stex[1]=0.0;
stex[2]=1.0;stex[3]=0.0;
stex[4]=0.0;stex[5]=1.0;
stex[6]=1.0;stex[7]=1.0;
stex[8]=0.0;stex[9]=1.0;
stex[10]=1.0;stex[11]=0.0;
glVertexAttribPointer(Vertice,2,GL_FLOAT,0,0,sk);
glVertexAttribPointer(TextureCordinate,2,GL_FLOAT,0,0,stex);
//glDrawArrays(GL_TRIANGLES,0,6);
// RENDER SHIP
v1x=-sizeX/2.0;v1y=-sizeY/2.0;
v2x= sizeX/2.0;v2y=-sizeY/2.0;
v3x=-sizeX/2.0;v3y= sizeY/2.0;
v4x= sizeX/2.0;v4y= sizeY/2.0;
rotate(mechaX,mechaY,v1x,v1y,zr2);
rotate(mechaX,mechaY,v2x,v2y,zr2);
rotate(mechaX,mechaY,v3x,v3y,zr2);
rotate(mechaX,mechaY,v4x,v4y,zr2);
v1x*=pixel_to_gl_X;v1y*=pixel_to_gl_Y;
v2x*=pixel_to_gl_X;v2y*=pixel_to_gl_Y;
v3x*=pixel_to_gl_X;v3y*=pixel_to_gl_Y;
v4x*=pixel_to_gl_X;v4y*=pixel_to_gl_Y;
sk[0]=mechaX+v1x;sk[1]=mechaY+v1y;
sk[2]=mechaX+v2x;sk[3]=mechaY+v2y;
sk[4]=mechaX+v3x;sk[5]=mechaY+v3y;
sk[6]= mechaX+v4x; sk[7]=mechaY+v4y;
sk[8]= mechaX+v3x; sk[9]=mechaY+v3y;
sk[10]=mechaX+v2x;sk[11]=mechaY+v2y;
stex[0]=0.0;stex[1]=0.0;
stex[2]=1.0;stex[3]=0.0;
stex[4]=0.0;stex[5]=1.0;
stex[6]=1.0;stex[7]=1.0;
stex[8]=0.0;stex[9]=1.0;
stex[10]=1.0;stex[11]=0.0;
glVertexAttribPointer(Vertice,2,GL_FLOAT,0,0,sk);
glVertexAttribPointer(TextureCordinate,2,GL_FLOAT,0,0,stex);
glDrawArrays(GL_TRIANGLES,0,6);
SDL_GL_SwapBuffers();
Frames++;
{
GLint t = SDL_GetTicks();
if (t - T0 >= 5000) {
GLfloat seconds = (t - T0) / 1000.0;
GLfloat fps = Frames / seconds;
printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
T0 = t;
Frames = 0;
}
}
currentTime=SDL_GetTicks();if(currentTime-oldTime<framerate)
{SDL_Delay(framerate-(currentTime-oldTime));}oldTime=SDL_GetTicks();}
//*********************************************************************** CLEAN THE HOUSE AND EXIT PROGRAM.
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
glDisableVertexAttribArray(Vertice);
glDisableVertexAttribArray(TextureCordinate);
// Dont forget to delete textures if using them...
/*while(c<3){free(texturesar[c]);c+=1;}
glDeleteTextures(2,&texture[20]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, 0);*/
SDL_Quit();
return 0;
}
// VERTEX SHADER 1.0
attribute vec2 a_vertice;
attribute vec2 a_texCor;
varying vec2 texCor;
uniform vec3 u_cameraPos;// POSITION OF CAMERA.
uniform int section;// CURRENT RENDERING TO SCREEN-SECTION.
float vx,vy;
void main()
{
if(section==0){
vx=a_vertice.x;
vy=a_vertice.y;
texCor=a_texCor;
gl_Position = vec4(vx,vy,0.0,1.0);}
}
// FRAGMENT SHADER 1.0
varying vec2 texCor;// TEXTURE CORDINATE
//varying int pass;
uniform sampler2D mtex;// NORMAL MAP TEXTURE
uniform sampler2D nm;// TEXTURE 1
void main()
{
//if(pass==1){
gl_FragColor=vec4(texCor.x,0.3,texCor.y,1.0);//}
}
I had forgotten about that, then how about:
ship 64x32
mecha 64x64
block 32x32
The collison detection for the ship can be anything, the image size should be larger then CD, but blocks need to match texture.
So are we using this thread, the PM or the google doc? It seems rather silly to use all three
.
Thanks, but don't do it just for me ^^.- The internal PM thread is to keep Linux-Swat in the loop since he does not like cloud services.
Im guessing no one has stepped foward and claimed to be the game designer cos it probably is a big commitment with lots of work with all kind of things, or did some one do it and I just missed it? You cant prototype air, there needs to be something there to try to achieve. Will someone be brave and commit to game design?
I use Sebt3's VM (I'm assuming that allows me to do GLES2), and I have a Pandora, so I can test builds immediately.Can you compile for Pandora, and can you compile GLES2 code then?
Not quite sure what you mean by this? Do you mean like a QuadList with mutliple textures or something?With GLES you shouldnt draw level blocks individually for ex,
So you'd want to seperate the rendering out into a completely different module?so what would be best would be to isolate the data needed to render and send that to the right array or something. Data thats needed I would imagine to look something like this:
GitHub then? We get a Wiki with it tooI think it should be open source and hopefully reusable by anyone to make other games with.