Getting together for developing a Game?


Ok, screen quads cant be used for parralax layers they still need different vertice positions or the fps go down.


Another worrying aspect was that I wasnt looking at fps on my Pandora before, I was looking at the left terminal part and saw up to 300 frames in the message, when I closed the window I saw just now that theres a right part of that line to... 300 means 60fps or so, its the fps that matters, so my performance wasnt very impressive afterall :/ anyway, to test this code for framerate we need a map system, the level should be built by blocks right? Then what size should the blocks be in pixels counted?


Then I can make a test level structure and put a couple parralax layers and convert to GLES2 and ask someone to compile.


In the section I describe as "GET RENDER INFO", thats were the interaction with renderer happens, thats the data the renderer will want from the rest of the engine, currently theres only size of image and value for rotation, and the position shoulg go there also, the level data needs some dataformat to get passed here to.



Code:
// 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;

}





Code:
// 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);}


}





Code:
// 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);//}


}
 
Yes, the driver forces it afaik. However, one of my early GL|ES attempts somehow deactivated Vsync. I scrapped that project just because of that.
 
hmm I just realized a mistake, the rotations shouldnt happen around player position but around 0.0.... I dont know why this works...


EDIT: the player position is always close to 0 so the error isnt extremely apparent.


Change the rotation(mechaX,mechaY,xxx,yyy,zr2); lines to rotate(0.0,0.0,xxx,yyy,zr2);
 
Last edited by a moderator:
How about level blocks be 40x40 and ship collision detection be 60x? mayby 60x60 for a mecha but something like 60x30 for ship? That means a ship could squeeze through a single block high tunnel, and not a mecha, it also means vertical tunnels can be 2 blocks wide at smallest and have 20 pixels free move.
 
Since we can't (well, shouldn't) use non-power-of-two sized tilesets, I think the level elements should have power-of-two dimensions.
 
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.
 
Whenever you guys have a little something to show even just a technical proof of concept or such id love to see it.
 
Yeah. I'd also like to have a piece of code to compile and run.


Maybe a step to learn some code.
 
So are we using this thread, the PM or the google doc? It seems rather silly to use all three


.

- This thread is fine for discussions.


- Google doc is to capture assumptions and serve as reference document.


- The internal PM thread is to keep Linux-Swat in the loop since he does not like cloud services.
 
for a group project, a production manager is a must(a girl must be)


a production designer is a must too


First project should always be a test on the team, as with no team, no project.


So start with something like pong or a project you can do on your own alone, but can be increased by the team.


First project done, you see the TEAM and advance to something better.
 
- The internal PM thread is to keep Linux-Swat in the loop since he does not like cloud services.
Thanks, but don't do it just for me ^^.


I suggested to use it for secret things (if there's any).
 
So what happens now, can my render system be incorporated in someones engine? I havent made a game before, I havent yet looked at any sound programming and I have no idea about fonts, who is the main programmer? I got the feeling it was slaesh or someone else?


With shaders you can discard the drawing of a pixel, that means we wouldnt even need to activate blending.


http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/discard.php


Although blending on or off dosnt seem to make a difference in performance for me at all, the only difference I get is when polygons overlap same vertice coordinates.


Perhaps I should clarify that what I wanted to do was programming the shaders specifically, if we are gonna use GLES2, and also Id like to supply some pixel images, probably not a ton of them though.


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 don't mind coding the game engine as I mentioned in the doc, if nobody else is willing. Though, I'd appreciate if somebody would give me a simplified interface to the graphics functions (ie DrawTexture(Position, Rotation, Scale)), as I'm not exactly well informed when it comes to GL[ES].


As we're using SDL to create the GL window, I'm assuming the normal SDL_TTF will work, and there's a couple of audio libraries around (I use BASS mostly, but don't mind really)


Edit: I'm assuming we're going to be using GL|ES?


I can start work on a basic prototype that has parallax background and a player you can move about, though to be honest, that isn't very difficult


Also, what should we use for source control? Have we picked if we're open source? (I don't mind if we're open or closed source TBH)
 
Last edited by a moderator:
Can you compile for Pandora, and can you compile GLES2 code then?


With GLES you shouldnt draw level blocks individually for ex, 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:


Ship position on screen.


What enemy type and position, for all active enemies plus bullets.


Level position, thinking about this I dont know how to determine were you are in a level, if levels should be able to change direction of scrolling when you come to some part of the level and so on...


The level blocks can be described as an 2D array with value 0 for blank and other values for different block types/graphics.


hmmm then the renderer can get the position to offset the level blocks, and that position can be calculated by vektors, for ex time 0 to 1 on vektor 1 wich is x0 to x594, and if time > 1.0 then vektor+=1 and time-=1.0, and new vektor with perhaps diagonally travel.


So what needs to happen is an update per frame of ship position, level offset, and an array of enemy types and positions and same for bullets were array has room for max simultaneous stuff and value 0 means nothing gets drawn. And then rotation and scale values also.


I think it should be open source and hopefully reusable by anyone to make other games with.


Parralax layers need offset values that gets applied to texture coordinates.
 
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 can commit to delivering a game design document, describing in details what the game would be like in terms of mecanisms/display/interface and so on.


Of course, get inputs from the team members after I have a first draft.


But if someone else feel like they want to take a lead on this, I have no issue with that.
 
Can you compile for Pandora, and can you compile GLES2 code then?
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.

With GLES you shouldnt draw level blocks individually for ex,
Not quite sure what you mean by this? Do you mean like a QuadList with mutliple textures or something?

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:
So you'd want to seperate the rendering out into a completely different module?

I think it should be open source and hopefully reusable by anyone to make other games with.
GitHub then? We get a Wiki with it too ;)
 
Back
Top