Doom3 Source Code Released (GPL licensed)


foxblock

Asleep
Joined
Jun 17, 2009
Messages
1,563
Location
Germany
So just about an hour ago John Carmack tweeted the following:

https://github.com/TTimo/doom3.gpl Timothee Besset did most of the work of getting it ready for release – thanks!
Source


Which means the source code of Doom3 (and the add-on Resurrection of Evil I believe) can be found here: https://github.com/TTimo/doom3.gpl


It's licensed under the GPLv3.


Some people have been waiting for this, so let's start the wild guesses whether it will be portable and actually run on the Pandora.


Also sacrifice a goat to the mightly Pickle, or whatever you do nowadays.


Cheers.
 
Last edited by a moderator:
I've heard that John had to rewrite some special Code for ingame shadows and that the new Code may not as optimized as the old one, wich doesn't matter on the PC but maybe on mobile ports?
 
I've heard that John had to rewrite some special Code for ingame shadows and that the new Code may not as optimized as the old one, wich doesn't matter on the PC but maybe on mobile ports?
He rewrote the way dynamic shadows are calculated and looking at the required system specs I think our best bet to get the game running at all is to disable shadows alltogether, so that changed code probably won't matter anyway.
 
That's not to say that Carmack's reverse cannot be re-implemented now the source is released, I know he has described the algorithm somewhere, since I remember reading about it at university...
 
I've heard that John had to rewrite some special Code for ingame shadows and that the new Code may not as optimized as the old one, wich doesn't matter on the PC but maybe on mobile ports?
He rewrote the way dynamic shadows are calculated and looking at the required system specs I think our best bet to get the game running at all is to disable shadows alltogether, so that changed code probably won't matter anyway.
I try to imagine how Doom 3 could work without it's shadows...but I don't come to a solution for this paradoxon... ;)
 
That's not to say that Carmack's reverse cannot be re-implemented now the source is released, I know he has described the algorithm somewhere, since I remember reading about it at university...
But I thought the reason he had to remove it in the first place was due to patents and/or copyrights. Us re-implementing what was there originally would result in the same violation, yes?
 
Depends on the accusation. If they were bitching about it being used commercially, then we're good to go, as the engine itself is no longer required to be sold.
 
That's not to say that Carmack's reverse cannot be re-implemented now the source is released, I know he has described the algorithm somewhere, since I remember reading about it at university...
But I thought the reason he had to remove it in the first place was due to patents and/or copyrights. Us re-implementing what was there originally would result in the same violation, yes?
No... If one does their own implementation of an algorithm and it gives similar outcomes then there is no violation. If one has access to Carmack's code and copy pastes it and even calls the shadow function Carmack's Reverse... there is the violation.


Think of open implementations of MP3 and similar codecs... in some countries it's iffy due to weird patent laws, but generally it's accepted as ok... this is the same.


So to get back to the point... the reason that HE had to remove it is because it's his code and it is Carmack's reverse and it's HIS implementation of the algorithm. If a clever person can reimplement the shadowing without viewing Carmack's code itself and call it openReverse... it should be legit.
 
I dont know if anyone wants it but I made stencil sahdows according to what was reffered to as the Carmacks reverse thingy. Theres plenty sites on the internet describing how to do that. I include my code but its very old and very bad, its a brute force implementation so very unelegant and annoying to read, after having succeeded I went on to work on next problem, the idea is to implement all my solutions in a complete renderer when I have solved all problems, Im actually very close to that stage now, Im working on my own editor and have only one thing with the animation system left to do then I will start working on a clean optimised renderer.


I dont have the best code on this PC, I recently improved on this one, if its as old as I think it will be missing the shaded back on the polygon displayed, wich is easy peasy to add anyway, I think there was something else I did alos that was incorrect with the old but dont remember what here now, I take a look at it later today and see.
 
The file didnt get attached? I post the code staright here then.

Code:
//  TRANSPARENCY WORKS!!!!**************************

//  MOUSE WORKS

//  SPECULAR works

// g++ ogl9.cpp -lSDL -lGL   = ./a.out

#include "SDL/SDL.h" // -lSDL

#include "GL/gl.h"   // -lGL

#include "math.h"

#include "iostream"


void glup(GLfloat fov,GLfloat aspectr,GLfloat zn,GLfloat zf){

GLfloat xmin,xmax,ymin,ymax;

  ymax=(float)zn*tan(fov*0.00872);

  ymin=-ymax;

  xmin=ymin*aspectr;

  xmax=ymax*aspectr;

glFrustum(xmin,xmax,ymin,ymax,zn,zf);

}


using namespace std;

int main(){

  unsigned short screen_width = 1024, screen_height = 768;

  SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

  SDL_Surface* sl1=SDL_SetVideoMode(screen_width,screen_height,16,SDL_HWSURFACE|SDL_OPENGL|SDL_NOFRAME|SDL_DOUBLEBUF);

  SDL_Event gameover,mouse;

  Uint8* key;

  bool quit=false;

  unsigned char framerate=10;//1000/10=100fps

  unsigned int oldTime=0,currentTime=0;

  float mx=0.2f,my=0.2f;//mousespeed

  float tfmx,tfmy,drawdistance=40,tra=0.5f;

  int dir[9];GLfloat sx[9],sn[9],sv[1][9];

glClearColor(0.0f,0.0f,0.2f,1.0f);

glClearDepth(1.0f);

glClearStencil(0);

glEnable(GL_DEPTH_TEST);

glEnable(GL_TEXTURE_2D);

glShadeModel(GL_SMOOTH);

glDepthFunc(GL_LEQUAL);//New pixel passes if depth value less or equal

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  float e,xpos=0,zpos=-2,yrot=0,y=0.0f,q=0,fspeed=0.04f,xx=1.0f;

  float piover180=0.0174532925f,aspect_ratio=45.0f;

  SDL_Surface* texturesar[1];

  GLuint texture[1];

  texturesar[0]=SDL_LoadBMP("mud.bmp");

  glGenTextures(1,&texture[0]);

  glBindTexture(GL_TEXTURE_2D, texture[0]);

  glTexImage2D(GL_TEXTURE_2D,0,3,

   texturesar[0]->w,texturesar[0]->h,0,

   GL_BGR,GL_UNSIGNED_BYTE,texturesar[0]->pixels);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

  free(texturesar[0]);

  glBlendFunc(GL_SRC_ALPHA,GL_ONE);

  //glColor4f(1.0f,1.0f,1.0f,tra);

  GLfloat lightambient[]  = { 0.8f, 0.7f, 0.6f, 1.0f };

  glLightfv( GL_LIGHT1, GL_AMBIENT, lightambient );

  //glEnable(GL_LIGHT1);

  //glCullFace(GL_BACK);

  //glEnable(GL_CULL_FACE);


  //glEnable(GL_STENCIL_TEST);

  //glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);

  //glStencilFunc(GL_EQUAL,1,0xffffffff);


  /*   SPECULAR  */

  GLfloat lp[]={1.0f, 1.0f, 1.0f, 1.0f};

  GLfloat diffMat[4]={0.0f, 1.0f, 0.0f, 1.0f};

  GLfloat specMat[4]={1.0f, 1.0f, 1.0f, 1.0f};

  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);

  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);

  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

  glLightfv(GL_LIGHT0, GL_POSITION, lp);

  //glEnable(GL_LIGHT0);

  glEnable(GL_COLOR_MATERIAL);

  glColor4fv(diffMat);


  /*   FOG   */

  GLfloat fc[4]={0.0f,0.0f,0.0f,1.0f},fd[]={0.08f},fs[]={10000.0f};

  glFogfv(GL_FOG_COLOR,fc);

  glFogfv(GL_FOG_DENSITY,fd);

  glFogfv(GL_FOG_START,fs);

  //glEnable(GL_FOG);


  /*   Print FrameRate   */

  static GLint T0=0,Frames=0;



  glEnable(GL_DEPTH_TEST);

  SDL_WM_GrabInput(SDL_GRAB_ON);

  SDL_WarpMouse(512,384);

  SDL_ShowCursor(0);



  //  GAME LOOP STARTS HERE **************************************

while(quit==false){

while(SDL_PollEvent(&mouse)){switch(mouse.type){

case SDL_MOUSEMOTION:

  yrot+=mouse.motion.xrel*mx;

  e+=mouse.motion.yrel*my;

break;}

   if(yrot<0.0f){yrot+=359.0f;}

   if(yrot>359.0f){yrot-=359.0f;}}

  while(SDL_PollEvent(&gameover))

{if(gameover.type==SDL_QUIT){quit=true;}}




key=SDL_GetKeyState(NULL);  //   	CONTROLS

if(key[SDLK_ESCAPE]){quit=true;}

if(key[SDLK_UP]){

   xpos -= ( float )sin( yrot * piover180 ) * fspeed;

   zpos += ( float )cos( yrot * piover180 ) * fspeed;}

if(key[SDLK_DOWN]){

   xpos += ( float )sin( yrot * piover180 ) * fspeed;

   zpos -= ( float )cos( yrot * piover180 ) * fspeed;}

if(key[SDLK_LEFT]){

   xpos -= ( float )sin( (yrot-90) * piover180 ) * fspeed;

   zpos += ( float )cos( (yrot-90) * piover180 ) * fspeed;}

if(key[SDLK_RIGHT]){

   xpos -= ( float )sin( (yrot+90) * piover180 ) * fspeed;

   zpos += ( float )cos( (yrot+90) * piover180 ) * fspeed;}

if(key[SDLK_a]){y-=0.02f;}

if(key[SDLK_z]){y+=0.02f;}

if(key[SDLK_q]){y=0.0f;}

if(key[SDLK_e]){e=0.0f;}

if(key[SDLK_w]){e=0.0f;}

if(key[SDLK_s]){e-=0.3f;}

if(key[SDLK_x]){e+=0.3f;}

if(key[SDLK_i]){aspect_ratio=45.0f;}

if(key[SDLK_o]){aspect_ratio-=5.0f;}

if(key[SDLK_p]){aspect_ratio+=5.0f;}

if(key[SDLK_k]){xx+=1.0f;}

if(key[SDLK_l]){xx-=1.0f;}

if(key[SDLK_j]){xx=1.0f;}// END OF CONTROLS


   GLfloat vertices[12]={0,1,0, 1,-1,-1, -1,-1,1,0,0,0};


   if(yrot<0.0f){yrot+=359.0f;}

   if(yrot>359.0f){yrot-=359.0f;}

   if(e<0.0f){e+=359.0f;}

   if(e>359.0f){e-=359.0f;}

   if(e<269.0f&&e>179.0f){e=269.0f;}

   if(e>89.0f&&e<=179.0f){e=89.0f;}


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glup(aspect_ratio,0.85f,0.1f,250.0f);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();


          // CAMERA START

glRotatef(e,1.0f,0.0f,0.0f);

glRotatef(yrot,0.0f,1.0f,0.0f);

glTranslatef(xpos,y,zpos);

     	// CAMERA END


/*   SHADOW CALCULATIONS   START   */

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

if(vertices[0]<=lp[0]){dir[0]=1;sx[0]=lp[0]-vertices[0];}else{dir[0]=2;sx[0]=vertices[0]-lp[0];}

if(vertices[1]<=lp[1]){dir[1]=1;sx[1]=lp[1]-vertices[1];}else{dir[1]=2;sx[1]=vertices[1]-lp[1];}

if(vertices[2]<=lp[2]){dir[2]=1;sx[2]=lp[2]-vertices[2];}else{dir[2]=2;sx[2]=vertices[2]-lp[2];}

if(vertices[3]<=lp[0]){dir[3]=1;sx[3]=lp[0]-vertices[3];}else{dir[3]=2;sx[3]=vertices[3]-lp[0];}

if(vertices[4]<=lp[1]){dir[4]=1;sx[4]=lp[1]-vertices[4];}else{dir[4]=2;sx[4]=vertices[4]-lp[1];}

if(vertices[5]<=lp[2]){dir[5]=1;sx[5]=lp[2]-vertices[5];}else{dir[5]=2;sx[5]=vertices[5]-lp[2];}

if(vertices[6]<=lp[0]){dir[6]=1;sx[6]=lp[0]-vertices[6];}else{dir[6]=2;sx[6]=vertices[6]-lp[0];}

if(vertices[7]<=lp[1]){dir[7]=1;sx[7]=lp[1]-vertices[7];}else{dir[7]=2;sx[7]=vertices[7]-lp[1];}

if(vertices[8]<=lp[2]){dir[8]=1;sx[8]=lp[2]-vertices[8];}else{dir[8]=2;sx[8]=vertices[8]-lp[2];}

  /*   MAKE NORMALS   */

   sn[0]=sx[0];sn[1]=sx[1];sn[2]=sx[2];

  if(sx[0]>=sx[1]&&sx[0]>=sx[2]){sn[1]/=sx[0];sn[2]/=sx[0];sn[0]=1;}

  if(sx[1]>=sx[0]&&sx[1]>=sx[2]){sn[0]/=sx[1];sn[2]/=sx[1];sn[1]=1;}

  if(sx[2]>=sx[1]&&sx[2]>=sx[0]){sn[1]/=sx[2];sn[0]/=sx[2];sn[2]=1;}

   sn[3]=sx[3];sn[4]=sx[4];sn[5]=sx[5];

  if(sx[3]>=sx[4]&&sx[3]>=sx[5]){sn[4]/=sx[3];sn[5]/=sx[3];sn[3]=1;}

  if(sx[4]>=sx[3]&&sx[4]>=sx[5]){sn[3]/=sx[4];sn[5]/=sx[4];sn[4]=1;}

  if(sx[5]>=sx[4]&&sx[5]>=sx[3]){sn[4]/=sx[5];sn[3]/=sx[5];sn[5]=1;}

   sn[6]=sx[6];sn[7]=sx[7];sn[8]=sx[8];

  if(sx[6]>=sx[7]&&sx[6]>=sx[8]){sn[7]/=sx[6];sn[8]/=sx[6];sn[6]=1;}

  if(sx[7]>=sx[6]&&sx[7]>=sx[8]){sn[6]/=sx[7];sn[8]/=sx[7];sn[7]=1;}

  if(sx[8]>=sx[7]&&sx[8]>=sx[6]){sn[7]/=sx[8];sn[6]/=sx[8];sn[8]=1;}

/*   MAKE VERTICES FOR SHADOW POLYGONS   */

  if(dir[0]==1){sv[0][0]=vertices[0]-(sn[0]*drawdistance);}

   else{sv[0][0]=vertices[0]+(sn[0]*drawdistance);}

  if(dir[1]==1){sv[0][1]=vertices[1]-(sn[1]*drawdistance);}

   else{sv[0][1]=vertices[1]+(sn[1]*drawdistance);}

  if(dir[2]==1){sv[0][2]=vertices[2]-(sn[2]*drawdistance);}

   else{sv[0][2]=vertices[2]+(sn[2]*drawdistance);}

  if(dir[3]==1){sv[0][3]=vertices[3]-(sn[3]*drawdistance);}

   else{sv[0][3]=vertices[3]+(sn[3]*drawdistance);}

  if(dir[4]==1){sv[0][4]=vertices[4]-(sn[4]*drawdistance);}

   else{sv[0][4]=vertices[4]+(sn[4]*drawdistance);}

  if(dir[5]==1){sv[0][5]=vertices[5]-(sn[5]*drawdistance);}

   else{sv[0][5]=vertices[5]+(sn[5]*drawdistance);}

  if(dir[6]==1){sv[0][6]=vertices[6]-(sn[6]*drawdistance);}

   else{sv[0][6]=vertices[6]+(sn[6]*drawdistance);}

  if(dir[7]==1){sv[0][7]=vertices[7]-(sn[7]*drawdistance);}

   else{sv[0][7]=vertices[7]+(sn[7]*drawdistance);}

  if(dir[8]==1){sv[0][8]=vertices[8]-(sn[8]*drawdistance);}

   else{sv[0][8]=vertices[8]+(sn[8]*drawdistance);}

/*   END OF SHADOW CALCULATIONS   */


//glBindTexture(GL_TEXTURE_2D,texture[0]);  

GLfloat texc[]={1,0,0,0,1,1,0,1};

glEnableClientState(GL_VERTEX_ARRAY);

//glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3,GL_FLOAT,0,vertices);

glTexCoordPointer(2,GL_FLOAT,0,texc);

  lightambient[0]=0.2f;

  lightambient[1]=0.0f;

  lightambient[2]=0.0f;

  lightambient[3]=0.1f;

    /*   SPECULAR  */

  GLfloat lp[]={1.0f, 1.0f, 1.0f, 1.0f};

  GLfloat diffMat[4]={0.0f, 1.0f, 0.0f, 1.0f};

  GLfloat specMat[4]={1.0f, 1.0f, 1.0f, 1.0f};

  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);

  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);

  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

  glLightfv(GL_LIGHT0, GL_POSITION, lp);

  glEnable(GL_LIGHT0);

  glEnable(GL_COLOR_MATERIAL);

  glColor4fv(diffMat);


// PASS 1 *************

    glColorMask(0,0,0,0);

    glDisable(GL_LIGHT0);

    glDisable(GL_STENCIL_TEST);


    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);


    // FLOOR

    vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;

    vertices[3]=24;vertices[4]=-1;vertices[5]=5;

    vertices[6]=-6;vertices[7]=-1;vertices[8]=15;

    glDrawArrays(GL_TRIANGLES,0,3);


    // CAST SHADOWS a

    glEnable(GL_CULL_FACE);

    glCullFace(GL_FRONT);

    glEnable(GL_STENCIL_TEST);

    glStencilFunc(GL_ALWAYS,1,9999);

    glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);

    // BOTTOM

    vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];

    vertices[3]=sv[0][3];vertices[4]=sv[0][4];vertices[5]=sv[0][5];

    vertices[6]=sv[0][6];vertices[7]=sv[0][7];vertices[8]=sv[0][8];

    glDrawArrays(GL_TRIANGLES,0,3);

 	// SIDE 1

    vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];

    vertices[3]=0;vertices[4]=1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    vertices[9]=sv[0][6];vertices[10]=sv[0][7];vertices[11]=sv[0][8];

    glDrawArrays(GL_QUADS,0,4);

 	// SIDE 2

    vertices[0]=sv[0][6];vertices[1]=sv[0][7];vertices[2]=sv[0][8];

    vertices[3]=2;vertices[4]=-1;vertices[5]=0;

    vertices[6]=0;vertices[7]=-1;vertices[8]=0;

    vertices[9]=sv[0][3];vertices[10]=sv[0][4];vertices[11]=sv[0][5];

    glDrawArrays(GL_QUADS,0,4);

 	// SIDE 3

    vertices[0]=sv[0][3];vertices[1]=sv[0][4];vertices[2]=sv[0][5];

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=0;vertices[7]=1;vertices[8]=0;

    vertices[9]=sv[0][0];vertices[10]=sv[0][1];vertices[11]=sv[0][2];

    glDrawArrays(GL_QUADS,0,4);

    glStencilFunc(GL_ALWAYS,1,9999);

    glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);

    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);


    // CAST SHADOWS b

    glStencilFunc(GL_ALWAYS,1,9999);

    glStencilOp(GL_KEEP,GL_DECR,GL_KEEP);

    glCullFace(GL_BACK);

    // BOTTOM

    vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];

    vertices[3]=sv[0][3];vertices[4]=sv[0][4];vertices[5]=sv[0][5];

    vertices[6]=sv[0][6];vertices[7]=sv[0][7];vertices[8]=sv[0][8];

    glDrawArrays(GL_TRIANGLES,0,3);

 	// SIDE 1

    vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];

    vertices[3]=0;vertices[4]=1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    vertices[9]=sv[0][6];vertices[10]=sv[0][7];vertices[11]=sv[0][8];

    glDrawArrays(GL_QUADS,0,4);

 	// SIDE 2

    vertices[0]=sv[0][6];vertices[1]=sv[0][7];vertices[2]=sv[0][8];

    vertices[3]=2;vertices[4]=-1;vertices[5]=0;

    vertices[6]=0;vertices[7]=-1;vertices[8]=0;

    vertices[9]=sv[0][3];vertices[10]=sv[0][4];vertices[11]=sv[0][5];

    glDrawArrays(GL_QUADS,0,4);

 	// SIDE 3

    vertices[0]=sv[0][3];vertices[1]=sv[0][4];vertices[2]=sv[0][5];

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=0;vertices[7]=1;vertices[8]=0;

    vertices[9]=sv[0][0];vertices[10]=sv[0][1];vertices[11]=sv[0][2];

    glDrawArrays(GL_QUADS,0,4);

    glStencilFunc(GL_ALWAYS,1,9999);

    glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);

    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);

    glDisable(GL_CULL_FACE);


/*   // CAST TRANSLUCENT SHADOWS a

    glStencilFunc(GL_ALWAYS,3,9999);

    glStencilOp(GL_KEEP,GL_REPLACE,GL_KEEP);


    // CAST TRANSLUCENT SHADOWS b

    glStencilFunc(GL_ALWAYS,0,9999);

    glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);

    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);


    // FLOOR

    vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;

    vertices[3]=24;vertices[4]=-1;vertices[5]=5;

    vertices[6]=-6;vertices[7]=-1;vertices[8]=15;

    glDrawArrays(GL_TRIANGLES,0,3);


    // PREPARE FOR TRANSLUCENT SURFACES

    glStencilFunc(GL_ALWAYS,1,9999);

    glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);*/


// PASS 2a (INSIDE SHADOWS)*************

    glClear(GL_DEPTH_BUFFER_BIT);

    glColorMask(1,1,1,1);

    glStencilFunc(GL_EQUAL,1,9999);

    glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);

    //glEnable(GL_LIGHT0);

    //glDisable(GL_LIGHT0);

      /*   SPECULAR  */

  diffMat[0]=1.0f;

  diffMat[1]=0.0f;

  diffMat[2]=1.0f;

  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);

  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);

  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

  glLightfv(GL_LIGHT0, GL_POSITION, lp);

  glEnable(GL_LIGHT0);

  glEnable(GL_COLOR_MATERIAL);

  glColor4fv(diffMat);


    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);


    // FLOOR

    vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;

    vertices[3]=24;vertices[4]=-1;vertices[5]=5;

    vertices[6]=-6;vertices[7]=-1;vertices[8]=15;

    glDrawArrays(GL_TRIANGLES,0,3);

/*  

    // INSIDE TRANSLUCENT SHADOWS ****

    glStencilFunc(GL_EQUAL,3,9999);

  lightambient[0]=(0.3f+diffMat[0])*tra;

  lightambient[1]=(0.3f+diffMat[1])*tra;

  lightambient[2]=(0.3f+diffMat[2])*tra;

  lightambient[3]=1.0f;

    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);


    // FLOOR

    vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;

    vertices[3]=24;vertices[4]=-1;vertices[5]=5;

    vertices[6]=-6;vertices[7]=-1;vertices[8]=15;

    glDrawArrays(GL_TRIANGLES,0,3);

    */

// PASS 2b (OUTSIDE SHADOWS)*************

    glStencilFunc(GL_EQUAL,0,9999);

    //glEnable(GL_LIGHT0);

      /*   SPECULAR  */

  diffMat[0]=0.0f;

  diffMat[1]=1.0f;

  diffMat[2]=0.0f;

  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);

  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);

  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

  glLightfv(GL_LIGHT0, GL_POSITION, lp);

  glEnable(GL_LIGHT0);

  glEnable(GL_COLOR_MATERIAL);

  glColor4fv(diffMat);


    // WALL 1

    vertices[0]=0;vertices[1]=1;vertices[2]=0;

    vertices[3]=0;vertices[4]=-1;vertices[5]=0;

    vertices[6]=2;vertices[7]=-1;vertices[8]=0;

    glDrawArrays(GL_TRIANGLES,0,3);


    // FLOOR

    vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;

    vertices[3]=24;vertices[4]=-1;vertices[5]=5;

    vertices[6]=-6;vertices[7]=-1;vertices[8]=15;

    glDrawArrays(GL_TRIANGLES,0,3);


    // DRAW TRANSLUCENT SURFACES

   // glStencilFunc(GL_EQUAL,1,9999);




glDisableClientState(GL_VERTEX_ARRAY);

//glDisableClientState(GL_TEXTURE_COORD_ARRAY);


q-=0.1f;



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();}

SDL_Quit();

return 0;

}
 
Last edited by a moderator:
I've heard that John had to rewrite some special Code for ingame shadows and that the new Code may not as optimized as the old one, wich doesn't matter on the PC but maybe on mobile ports?
He rewrote the way dynamic shadows are calculated and looking at the required system specs I think our best bet to get the game running at all is to disable shadows alltogether, so that changed code probably won't matter anyway.
I try to imagine how Doom 3 could work without it's shadows...but I don't come to a solution for this paradoxon... ;)
Yeah it sure creates a lot of atmosphere, but sadly dynamic shadows are not exactly easy on the CPU/GPU... though we still could have static shadows of immovable objects, which are baked right into the level file and then depending on performance can see where to go from there.


But that is assuming we get a working port and we are far from that ;)

I dont know if anyone wants it but I made stencil sahdows according to what was reffered to as the Carmacks reverse thingy. Theres plenty sites on the internet describing how to do that. I include my code but its very old and very bad, its a brute force implementation so very unelegant and annoying to read, after having succeeded I went on to work on next problem, the idea is to implement all my solutions in a complete renderer when I have solved all problems, Im actually very close to that stage now, Im working on my own editor and have only one thing with the animation system left to do then I will start working on a clean optimised renderer.


I dont have the best code on this PC, I recently improved on this one, if its as old as I think it will be missing the shaded back on the polygon displayed, wich is easy peasy to add anyway, I think there was something else I did alos that was incorrect with the old but dont remember what here now, I take a look at it later today and see.
Thanks, but please wrap that into a code and spoiler tag (or even better upload it on www.pastebiin.com, so one can just download the file).
 
Exciting stuff. What are the realistic chances of this running decently on a Pandora though? I mean, it required a mega-meaty-machine when it was released!
 
No kidding... Pandora needs a lot more REAL 3D games...


Which is why I'm working my ass of right now to get the character-renderer for Sticks of Styx going right now.


Having DOOM3 on this baby would sure pull attention and maybe more people that can port other 3D titles.
 
if only more of those old beauties were open source, like Deus Ex or System Shock 2. Deus Ex on Pandora is my ultimate dream.


Anyway! DOOM3 ho!
 
PokeParadox, I hate to say it but you're incorrect regarding the patent system and so on (especially in the US.) Just want to clarify, so you don't get into hot water someday. (And I may be misinterpreting what you wrote, you might well mean the same thing, or maybe I am wrong, so feel free to correct me :)


If reimplementations were safe, we'd have no problems; the whole patent issue in software is that _algorithyms_ (approaches) are patented, so you can implement 10 different codebases, but as long as the approach is similar, they're in violation. That is the danger -- that if there is only one good way to do something, and some idiot patents it, the whole industry suffers.


The issue here is there is a patented alg, and Carmack independantly solved the problem before patent was released; he has a specific arrangement with the patent holders, so he can use the alg indefinately and gives free advertising to Creative or whoever. But he cannot then go releasing this to the public, since that is not the agreement he has. (See the BS? He has independantly coded something, at the same time as others, but they own the patent, so he is their slave.)


jeff

@gotwake -- a bounty needs definition. You can port Doom3 to run on an Atari 2600, at .001fps.. does that count? :)


Your bounty is $x foe a successful port that has what features.... how many fps does it need?


jeff
 
@skeezix: Thank god its not like that at my place... (Europe) :D


Lack of software patents rullleee.
 
Yeah it sure creates a lot of atmosphere, but sadly dynamic shadows are not exactly easy on the CPU/GPU... though we still could have static shadows of immovable objects, which are baked right into the level file and then depending on performance can see where to go from there.


But that is assuming we get a working port and we are far from that ;)
Someone should give Carmack a Pandora and see what happens... ^^


Funny:


http://twitter.com/#...189212519792640


:D
 
Last edited by a moderator:
Coldbird -- you should check again ;) Its not as bad as in the US (I'm not a USian either btw), but in Europe.. still a problem. There are laws in some EU countries that pure-software cannot be patented, but many/most algos also apply _on paper_ and are thus patentable. Software algorhtiyms that are non-trivial are patentable in Europe, as I understand it.


jeff
 
Back
Top