Can anyone try to compile this GLES 1 code?

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
The following code compiles without error messages for me, but when I start it it terminates immidiatly. Can anyone see if they get a different result, and if so do the textures work? Replace mud3.bmp with a RGBA bmp that you have.



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

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

#include "GLES/gl.h"

#include "math.h"

#include "iostream"

#include "fstream"

#include "unistd.h"

//#include "eglport.c"


/**

*

* eglport.c/.h

* Copyright (C) 2011 Scott Smith

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see <http://www.gnu.org/licenses/>.

*

*/


#include "eglport.h"


/* Pandora VSync */

#include <fcntl.h>

#include <sys/ioctl.h>

#include <linux/fb.h>


#ifndef FBIO_WAITFORVSYNC

#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)

#endif

int fbdev = -1;

/* Pandora VSync End */


#define EGLNativeWindowType NativeWindowType

#define EGLNativeDisplayType NativeDisplayType


EGLDisplay g_eglDisplay = 0;

EGLConfig g_eglConfig = 0;

EGLContext g_eglContext = 0;

EGLSurface g_eglSurface = 0;


#define g_totalConfigsIn 20

int g_totalConfigsFound = 0;

EGLConfig g_allConfigs[g_totalConfigsIn];

Display *g_x11Display = NULL;



/*======================================================

 * Kill off any opengl specific details

  ====================================================*/

void EGL_Destroy()

{

    if( g_eglSurface || g_eglContext || g_eglDisplay )

    {

        eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);

        eglDestroyContext(g_eglDisplay, g_eglContext);

        eglDestroySurface(g_eglDisplay, g_eglSurface);

        eglTerminate(g_eglDisplay);

    }


    g_eglSurface = 0;

    g_eglContext = 0;

    g_eglDisplay = 0;


if (g_x11Display)

XCloseDisplay(g_x11Display);


    g_x11Display = NULL;


    printf( "EGL Closed\n");


    /* Pandora VSync */

    close(fbdev);

    fbdev = -1;

    /* Pandora VSync End */

}


/*===========================================================

Setup EGL context and surface

===========================================================*/

int EGL_Init( void )

{

    FindAppropriateEGLConfigs();


    int configIndex = 0;


printf( "Config %d\n", configIndex );


if (!ConfigureEGL(g_allConfigs[configIndex]))

{

TestEGLError();

fprintf(stderr, "ERROR: Unable to initialise EGL. See previous error.\n");

return 1;

}


    /* Pandora VSync */

    fbdev = open ("/dev/fb0", O_RDONLY /* O_RDWR */ );

    if ( fbdev < 0 ) {

      fprintf ( stderr, "Couldn't open /dev/fb0 for vsync\n" );

    }

    /* Pandora VSync End */


    return 0;

}


/*===========================================================

Swap EGL buffers and update the display

===========================================================*/

void EGL_SwapBuffers( void )

{

    /* Pandora VSync */

    if ( fbdev >= 0 ) {

        int arg = 0;

        ioctl( fbdev, FBIO_WAITFORVSYNC, &amp;arg );

    }

    /* Pandora VSync End */

eglSwapBuffers(g_eglDisplay, g_eglSurface);

}



/*========================================================

 *  Init base EGL

 * ======================================================*/

int EGL_Open( void )

{

    // use EGL to initialise GLES

    printf( "EGL Open display\n" );

    g_x11Display = XOpenDisplay(NULL);


    if (!g_x11Display)

    {

        fprintf(stderr, "ERROR: unable to get display!\n");

        return 0;

    }


    printf( "EGL Get display\n" );

    g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)g_x11Display);


    if (g_eglDisplay == EGL_NO_DISPLAY)

    {

        TestEGLError();

        fprintf(stderr, "ERROR: Unable to initialise EGL display.\n");

        return 0;

    }


    // Initialise egl

    printf( "EGL Init\n" );

    if (!eglInitialize(g_eglDisplay, NULL, NULL))

    {

        TestEGLError();

        fprintf(stderr, "ERROR: Unable to initialise EGL display.\n");

        return 0;

    }


    return 1;

}


/*===========================================================

Initialise OpenGL settings

===========================================================*/

int ConfigureEGL(EGLConfig config)

{

    // Cleanup in case of a reset

    if( g_eglSurface || g_eglContext || g_eglDisplay )

    {

        eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);

        eglDestroyContext(g_eglDisplay, g_eglContext);

        eglDestroySurface(g_eglDisplay, g_eglSurface);

    }


    // Bind GLES and create the context

    printf( "EGL Bind\n" );

    eglBindAPI(EGL_OPENGL_ES_API);

if (!TestEGLError() )

{

return 0;

}


    printf( "EGL Create Context\n" );

    g_eglContext = eglCreateContext(g_eglDisplay, config, NULL, NULL);

    if (g_eglContext == EGL_NO_CONTEXT)

    {

        TestEGLError();

        fprintf(stderr, "ERROR: Unable to create GLES context!\n");

        return 0;

    }


    // Get the SDL window handle

    SDL_SysWMinfo sysInfo; //Will hold our Window information

    SDL_VERSION(&amp;sysInfo.version); //Set SDL version

    if(SDL_GetWMInfo(&amp;sysInfo) <= 0)

    {

        TestEGLError();

        fprintf( stderr, "ERROR: Unable to get window handle\n");

        return 0;

    }


    printf( "EGL Create window surface\n" );

    g_eglSurface = eglCreateWindowSurface(g_eglDisplay, config, (EGLNativeWindowType)sysInfo.info.x11.window, 0);


    if ( g_eglSurface == EGL_NO_SURFACE)

    {

        TestEGLError();

        fprintf(stderr, "ERROR: Unable to create EGL surface!\n");

        return 0;

    }


    printf( "EGL Make Current\n" );

    if (eglMakeCurrent(g_eglDisplay,  g_eglSurface,  g_eglSurface, g_eglContext) == EGL_FALSE)

    {

        TestEGLError();

        fprintf(stderr, "ERROR: Unable to make GLES context current\n");

        return 0;

    }


    printf( "EGL Done\n" );

    return 1;

}


/*=======================================================

* Detect available video resolutions

=======================================================*/

int FindAppropriateEGLConfigs( void )

{

    static const EGLint s_configAttribs[] =

    {

          EGL_RED_SIZE,     5,

          EGL_GREEN_SIZE,   6,

          EGL_BLUE_SIZE,    5,

          EGL_DEPTH_SIZE,       16,

          EGL_SURFACE_TYPE,         EGL_WINDOW_BIT,

          EGL_RENDERABLE_TYPE,      EGL_OPENGL_ES_BIT,

          EGL_NONE

    };


    if (eglChooseConfig(g_eglDisplay, s_configAttribs, g_allConfigs, g_totalConfigsIn, &amp;g_totalConfigsFound) != EGL_TRUE || g_totalConfigsFound == 0)

    {

        TestEGLError();

        fprintf(stderr, "ERROR: Unable to query for available configs.\n");

        return 0;

    }

    fprintf(stderr, "Found %d available configs\n", g_totalConfigsFound);

    return 1;

}


int TestEGLError( void )

{

EGLint iErr = eglGetError();

while (iErr != EGL_SUCCESS)

{

printf("EGL failed (%d).\n", iErr);

return 0;

}


return 1;

}



void setps(float fov,float ar,float&amp; ett,float&amp; tva, float&amp; tre, float&amp; fyr, float&amp; fem, float&amp; sex){

float xmin,xmax,ymin,ymax,zn=0.1f,zf=999999.0f,left,right,top,bottom;ymax=(float)zn*tan(fov*0.00872);

ymin=-ymax;xmin=ymin*ar;xmax=ymax*ar;left=xmin;right=xmax;bottom=ymin;top=ymax;ett=(float)(2*zn)/(right-left);

tva=(float)(2*zn)/(top-bottom);tre=(float)(right+left)/(right-left);fyr=(float)(top+bottom)/(top-bottom);

fem=(float)-((zf+zn)/(zf-zn));sex=(float)-((2*zf*zn)/(zf-zn));}


void cam(float rx,float ry,float rz,float&amp; t1x,float&amp; t1y,float&amp; t1z,float&amp; t2x,float&amp; t2y,float&amp; t2z,float&amp; t3x,

float&amp; t3y,float&amp; t3z){float sx,cx,sy,cy,sz,cz,theta;theta=rx*0.017453;sx=sin(theta);cx=cos(theta);

theta=ry*0.017453;sy=sin(theta);cy=cos(theta);theta=rz*0.017453;sz=sin(theta);cz=cos(theta);t1x=cz*cy-sz*sx*sy;

t1y=sz*cy+cz*sx*sy;t1z=-cx*sy;t2x=-sz*cx;t2y=cz*cx;t2z=sx;t3x=cz*sy+sz*sx*cy;t3y=sz*sy-cz*sx*cy;t3z=cx*cy;}


void rotate(float xp,float yp,float&amp; ux,float&amp; uy,float degrees){float bt,lx,ly,rx,ry,nnx,a;if(uy<=yp&amp;&amp;ux>=xp)

{a=atan((yp-uy)/((ux-xp)+0.001))*57.295791;lx=ux-xp;ly=yp-uy;}if(uy<=yp&amp;&amp;xp>ux)

{a=90.0+(90.0-acos((xp-ux)/(sqrt(((yp-uy)*(yp-uy))+((xp-ux)*(xp-ux)))+0.001))*57.295791);lx=xp-ux;ly=yp-uy;}

if(yp<uy&amp;&amp;xp>ux){a=270.0-(90.0-(atan((uy-yp)/((xp-ux)+0.001))*57.295791));lx=xp-ux;ly=uy-yp;}if(yp<uy&amp;&amp;ux>=xp)

{a=360.0-(acos((ux-xp)/(sqrt(((uy-yp)*(uy-yp))+((ux-xp)*(ux-xp)))+0.001))*57.295791);lx=ux-xp;ly=uy-yp;}

a=((a)+degrees)+45.0;rx=(cos(a*0.017453))+(sin(a*0.017453));ry=(-sin(a*0.017453))+(cos(a*0.017453));

nnx=(sqrt((rx*rx)+(ry*ry))+0.001);bt=sqrt((lx*lx)+(ly*ly));rx/=nnx;ux=xp+(rx*bt);ry/=nnx;uy=yp-(ry*bt);}


void tricd(int px,int py,float&amp; px2,float&amp; py2,float ax,float ay, float bx,float by,float cx,float cy){

float v0x,v0y,v1x,v1y,v2x,v2y,invD,d00,d01,d02,d11,d12;v0x=cx-ax;v0y=cy-ay;v1x=bx-ax;v1y=by-ay;v2x=px-ax;

v2y=py-ay;d00=v0x*v0x+v0y*v0y;d01=v0x*v1x+v0y*v1y;d02=v0x*v2x+v0y*v2y;d11=v1x*v1x+v1y*v1y;d12=v1x*v2x+v1y*v2y;

invD=1.0/(d00*d11-d01*d01);px2=(d11*d02-d01*d12)*invD;py2=(d00*d12-d01*d02)*invD;}


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;

 glFrustumf(xmin,xmax,ymin,ymax,zn,zf);}


using namespace std;

int main(){

  unsigned short screen_width = 400, screen_height = 240;

  SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

  EGL_Open();

  SDL_Surface* sl1;sl1=SDL_SetVideoMode(700,380,0,SDL_SWSURFACE/*|SDL_FULLSCREEN*/);

  EGL_Init();

  SDL_Event gameover;

  Uint8* key;

  int quit=0;

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

  unsigned int oldTime=0,currentTime=0;fstream myfile;int c=0,d=0,e=0,f=0,aslen,c2=0,mvp=0;

  float xn,ynn,zn,xr=0.0,xrt=0.0,yr=0.0,zr=0.0,xpos=0.0,ypos=0.0,zpos=-2.0,ms,r_fov=45.0,r_aspectRatio=1.0;

  float cxp=0.0,cyp=0.0,czp=zpos-5.0,xpo,ypo,zpo,cmes;

  float rx,ry,nnx,ye,dett,dtva,dtre,dfyr,dfem,dsex,mp[16],mc[9],mrx,mrx2,mry,mry2;static int pi[5000][5];

  int aniti,anis,ctu,a1,a2;float anit,tangx,angx,tangy,angy,tangz,angz,r1x,r1y,r1z,r2x,r2y,r2z,r3x,r3y,r3z;

  static float shina[20000],tina[20000],rda[20000],lvnr[20000],ang[300][10][5][3],co[5000],mv[45000],texc[30000];

  static float al[10][5][2],nort[15000],bn[45000],td[5000][26],alvnr[150],alight[150],sk[45000],v[45000];

  static int um[5000],tdi[5000][10],linkn[15000][4],vl[15000][4];static float skt[500][450000],skw[500][450000];

  float mid,v1x,v1y,v1z,v2x,v2y,v2z,nx,ny,nz,ttt,tanipx,tanipy,tanipz;static float anip[300][10][5][3];

  int area=1,ffoward=0,bbackward=0,lleft=0,rright=0,free_float=0,cto,ptu;

  int nop = 5000;//  Number of POLYGONS

  int nov = nop*9; // Number of VERTICES (Vertice 1-3,XYZ)

  int nt  = 10; // Number of trees

  int noa = 5; // Number of animationpoints

  int nof = 300;// Number of frames (for animation)

  int numtex = 8;// Number of TEXTURES

  int nl = 1; //   Number of LIGHTS

  int nll = 1;//  Number of LIGHT LEVELS

  int numbn=4;//  Number of BENDED NORMALS

  int uat=3;//    Used amount of TEXTURES (in a package, normalmaps, shinymaps etc)

  int an=10000;// Amount of NODES

  static int treel[10][10];// Describes if tree [c] is affected by tree [d]

  static int anili[10][2];// Tree [c] is linked to tree [0] animationpoint [1]

  static float ang2[300][10][5][3];

  static float anip2[300][10][5][3];

  static float node[10000][3];// XYZ

  static float node2[10000][3];// VALUE 1,2 and 3

  static float texm[150000][6];// Manual texture cordinates

  static int texnv[150000];// FIT TO SURFACE mode selection (on/off)

  static int tmanh[150000];// Use manual values (on/off)

  static float cdpa[150000][12];

  static float light[20000][4];// R,G,B and DISTANCE

  static float lightp[20000][3];// X,Y,Z



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

 glClearDepthf(1.0f);

 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 yrot=0,y=0.0f,q=0,fspeed=0.04f,xx=1.0f;

  float piover180=0.0174532925f,aspect_ratio=45.0f,nrot=0;


  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glEnable(GL_BLEND);


  GLfloat fc[4]={0.5,0,0.2,1},fd[]={0.2},fs[]={0.9};

  glFogfv(GL_FOG_COLOR,fc);

  glFogfv(GL_FOG_DENSITY,fd);

  glFogfv(GL_FOG_START,fs);

  //glEnable(GL_FOG);

  static GLint T0=0,Frames=0;



  SDL_Surface* texturesar[100];//::::::::::::::::::::::::::::::::::::::::::::::: LOAD TEXTURES TO RAM.

  GLuint texture[30];

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

  //texturesar[1]=SDL_LoadBMP("mud3.bmp");

  /*texturesar[2]=SDL_LoadBMP("nm2.bmp");

  texturesar[3]=SDL_LoadBMP("nm2.bmp");

  texturesar[4]=SDL_LoadBMP("nm2.bmp");

  texturesar[5]=SDL_LoadBMP("nm2.bmp");

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

  texturesar[7]=SDL_LoadBMP("nm2.bmp");*/

  /*glActiveTexture(GL_TEXTURE0);

  glGenTextures(1,&amp;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);*/

/*

myfile.open("psoppolydata.txt");//*****************************************************************************

    while(c<nop){while(d<12){myfile>>   cdpa[c][d]   ;d+=1;}d=0;c+=1;}c=0;//::::::::: COLLISION DETECTION

    while(c<nop*6){myfile>>   texc[c]   ;c+=1;}c=0;//::::::::::::::::::::::::::::::::: TEXTURE CORDINATES

    while(c<nov){myfile>>   v[c]   ;c+=1;}c=0;//:::::::::::::::::::::::::::::::::::::::::::::::: POLYGONS

    while(c<an){myfile>>   node[c][0]   ;myfile<<   node[c][1]   <<endl;

      myfile>>   node[c][2]   ;c+=1;}c=0;//::::::::::::::::::::::::::::::::::::::::::::::: NODE POSITIONS

    while(c<an){myfile>>   node2[c][0]   ;myfile<<   node2[c][1]   <<endl;

      myfile>>   node2[c][2]   ;c+=1;}c=0;//::::::::::::::::::::::::::::::::::::::::::::::::: NODE VALUES

    while(c<nop){while(d<5){myfile>>   pi[c][d]   ;d+=1;}d=0;c+=1;}c=0;//::::::::::::::::: MISC POLY DATA

    while(c<nop){myfile>>   tdi[c][2];c+=1;}c=0;//:::::::::::::::::::::::::::::::::::::::: TEXTURE SELECT

myfile.close();myfile.open("psopeditdata.txt");//**************************************************************

    while(c<nop){while(d<6){myfile>>   texm[c][d]   ;d+=1;}d=0;c+=1;}c=0;//:::::::: MANUAL TEX COORDS (E)

    while(c<nop){myfile>>   texnv[c]   ;c+=1;}c=0;//:::::::::::::::::::::::::: TEX FIT TO SURF ON/OFF (E)

    while(c<nop){myfile>>   tmanh[c]   ;c+=1;}c=0;//::::::::::::::::::::::::::::::: MANUAL TEX ON/OFF (E)

    while(c<nop){while(d<26){myfile>>   td[c][d]   ;d+=1;}d=0;c+=1;}c=0;//::::::::::::::::: MISC TEX DATA

    while(c<nop){while(d<10){myfile>>   tdi[c][d]   ;d+=1;}d=0;c+=1;}c=0;//:::::::::::::: MISC TEX DATA 2

    while(c<nt){while(d<nt){myfile>>   treel[c][d]   ;d+=1;}d=0;c+=1;}c=0;

    while(c<nt){myfile>>   anili[c][0]   ;myfile>>   anili[c][1]   ;c+=1;}c=0;

    while(c<nof){while(d<nt){while(e<noa){

      myfile>>   ang2[c][d][e][0]   ;myfile>>   ang2[c][d][e][1]   ;

      myfile>>   ang2[c][d][e][2]   ;e+=1;}e=0;d+=1;}d=0;c+=1;}c=0;

    while(c<nof){while(d<nt){while(e<noa){

      myfile>>   anip2[c][d][e][0]   ;myfile>>   anip2[c][d][e][1]   ;

      myfile>>   anip2[c][d][e][2]   ;e+=1;}e=0;d+=1;}d=0;c+=1;}c=0;

myfile.close();myfile.open("psopanidata.txt");//***************************************************************

    myfile >> aslen;// ANIMATION SEQUENCE LENGHT (in frames)

    while(c<nof){while(d<nt){while(e<noa){

      myfile>>   ang[c][d][e][0]   ;myfile>>   ang[c][d][e][1]   ;

      myfile>>   ang[c][d][e][2]   ;e+=1;}e=0;d+=1;}d=0;c+=1;}c=0;

    while(c<nof){while(d<nt){while(e<noa){

      myfile>>   anip[c][d][e][0]   ;myfile>>   anip[c][d][e][1]   ;

      myfile>>   anip[c][d][e][2]   ;e+=1;}e=0;d+=1;}d=0;c+=1;}c=0;

    while(c<nov){myfile>>   um[c]   ;c+=1;}c=0;

    while(c<nov){myfile>>   vl[c][0]   ;myfile>>   vl[c][1]   ;

      myfile>>   vl[c][2]   ;myfile>>   vl[c][3]   ;c+=1;}c=0;

    while(c<nt){while(d<noa){myfile>>   al[c][d][0]   ;myfile>>   al[c][d][1]   ;d+=1;}d=0;c+=1;}c=0;

    while(c<nov){myfile>>   co[c]   ;c+=1;}c=0;

  myfile.close();*/


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

while(quit==0){while(SDL_PollEvent(&amp;gameover))

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


 key=SDL_GetKeyState(NULL);  //       CONTROLS

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

 if(key[SDLK_q]){xr-=1.0;}

 if(key[SDLK_w]){xr+=1.0;}

 if(key[SDLK_UP]){ffoward=1;}else{ffoward=0;}

 if(key[SDLK_DOWN]){bbackward=1;}else{bbackward=0;}

 if(key[SDLK_LEFT]){lleft=1;}else{lleft=0;}

 if(key[SDLK_RIGHT]){rright=1;}else{rright=0;}// END OF CONTROLS


 // MOVEMENT PROCESSING :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::START of movement.

 cto=ctu;ctu=SDL_GetTicks();anis=ctu;ptu=ctu-cto;ms=(float)ptu/1000;ms*=10.0;xpo=xpos;ypo=ypos;zpo=zpos;


//if(cmes<5.0){czpt=zpos-czp;cxpt=xpos-cxp;czpt*=(5.0-cmes)/5.0;cxpt*=(5.0-cmes)/5.0;cxp-=cxpt;czp-=czpt;}

//if(cmes>5.0){czpt=zpos-czp;cxpt=xpos-cxp;czpt*=(cmes-5.0)/5.0;cxpt*=(cmes-5.0)/5.0;cxp+=cxpt;czp+=czpt;}

 while(xr>=360.0f){xr-=360.0f;}while(xr<0.0f){xr+=360.0f;}

 while(yr>=360.0f){yr-=360.0f;}while(yr<0.0f){yr+=360.0f;}

 while(zr>=360.0f){zr-=360.0f;}while(zr<0.0f){zr+=360.0f;}

 if(yr<270.0f&amp;&amp;yr>180.0f){yr=270.0f;}if(yr>90.0f&amp;&amp;yr<=180.0f){yr=90.0f;}

 if(yr<=90.0f){if(yr==90.0f){ye=0.0f;}else{ye=(float)(90.0f-yr)/90.0f;}}

 else{if(yr==270.0f){ye=0.0f;}else{ye=(float)(yr-270.0f)/90.0f;}}

     if(ffoward==1){rx=cos((xrt+135.0)*0.017453)+sin((xrt+135.0)*0.017453);

ry=-sin((xrt+135.0)*0.017453)+cos((xrt+135.0)*0.017453);nnx=sqrt((rx*rx)+(ry*ry));

rx/=nnx;ry/=nnx;rx*=ms;ry*=ms;if(free_float==0){xpos+=rx;zpos-=ry;}

else{xpos+=rx*ye;zpos-=ry*ye;if(yr<=90.0f){ypos-=ms*(1.0f-ye);}else{ypos+=ms*(1.0f-ye);}}}

     if(bbackward==1){rx=cos((xrt+135.0)*0.017453)+sin((xrt+135.0)*0.017453);

ry=-sin((xrt+135.0)*0.017453)+cos((xrt+135.0)*0.017453);nnx=sqrt((rx*rx)+(ry*ry));

rx/=nnx;ry/=nnx;rx*=ms;ry*=ms;if(free_float==0){xpos-=rx;zpos+=ry;}

else{xpos-=rx*ye;zpos+=ry*ye;if(yr>90.0f){ypos-=ms*(1.0f-ye);}else{ypos+=ms*(1.0f-ye);}}}

     if(lleft==1){rx=cos((xrt+225.0)*0.017453)+sin((xrt+225.0)*0.017453);

ry=-sin((xrt+225.0)*0.017453)+cos((xrt+225.0)*0.017453);

nnx=sqrt((rx*rx)+(ry*ry));rx/=nnx;ry/=nnx;rx*=ms;ry*=ms;xpos-=rx;zpos+=ry;}

     if(rright==1){rx=cos((xrt+45.0)*0.017453)+sin((xrt+45.0)*0.017453);

ry=-sin((xrt+45.0)*0.017453)+cos((xrt+45.0)*0.017453);

nnx=sqrt((rx*rx)+(ry*ry));rx/=nnx;ry/=nnx;rx*=ms;ry*=ms;xpos-=rx;zpos+=ry;}

//cout<<ms<<endl;

 cmes=sqrt(((xpos-cxp)*(xpos-cxp))+((zpos-czp)*(zpos-czp)));float czpt,cxpt,a,xp,yp,ux,uy;

xp=cxp;yp=czp;ux=xpos;uy=zpos;

if(uy<=yp&amp;&amp;ux>=xp){a=atan((yp-uy)/((ux-xp)))*57.295791;}

if(uy<=yp&amp;&amp;xp>ux){a=90.0+(90.0-acos((xp-ux)/(sqrt(((yp-uy)*(yp-uy))+((xp-ux)*(xp-ux)))))*57.295791);}

if(yp<uy&amp;&amp;xp>ux){a=270.0-(90.0-(atan((uy-yp)/((xp-ux)))*57.295791));}

if(yp<uy&amp;&amp;ux>=xp){a=360.0-(acos((ux-xp)/(sqrt(((uy-yp)*(uy-yp))+((ux-xp)*(ux-xp)))))*57.295791);}

xrt=((a-270.0)*-1.0);

if(cmes<5.0){czpt=zpos-czp;cxpt=xpos-cxp;czpt*=(5.0-cmes)/5.0;cxpt*=(5.0-cmes)/5.0;cxp-=cxpt;czp-=czpt;}

if(cmes>5.0){czpt=zpos-czp;cxpt=xpos-cxp;czpt*=(cmes-5.0)/5.0;cxpt*=(cmes-5.0)/5.0;cxp+=cxpt;czp+=czpt;}

/*rx=cos((xrt+135.0)*0.017453)+sin((xrt+135.0)*0.017453);

ry=-sin((xrt+135.0)*0.017453)+cos((xrt+135.0)*0.017453);nnx=sqrt((rx*rx)+(ry*ry))+0.001;

rx/=nnx;ry/=nnx;rx*=5.0-cmes;ry*=5.0-cmes;cxp-=rx;czp+=ry;}

if(cmes>5.0){xp=cxp;yp=czp;ux=xpos;uy=zpos;

if(uy<=yp&amp;&amp;ux>=xp){a=atan((yp-uy)/((ux-xp)+0.001))*57.295791;}

if(uy<=yp&amp;&amp;xp>ux){a=90.0+(90.0-acos((xp-ux)/(sqrt(((yp-uy)*(yp-uy))+((xp-ux)*(xp-ux)))+0.001))*57.295791);}

if(yp<uy&amp;&amp;xp>ux){a=270.0-(90.0-(atan((uy-yp)/((xp-ux)+0.001))*57.295791));}

if(yp<uy&amp;&amp;ux>=xp){a=360.0-(acos((ux-xp)/(sqrt(((uy-yp)*(uy-yp))+((ux-xp)*(ux-xp)))+0.001))*57.295791);}

xrt=a;

rx=cos((xrt+135.0)*0.017453)+sin((xrt+135.0)*0.017453);

ry=-sin((xrt+135.0)*0.017453)+cos((xrt+135.0)*0.017453);nnx=sqrt((rx*rx)+(ry*ry))+0.001;

rx/=nnx;ry/=nnx;rx*=5.0-cmes;ry*=5.0-cmes;cxp-=rx;czp+=ry;}*/


 anit=ctu-anis;aniti=anit;anit-=aniti;anit/=1000.0;// anis = SDL_tick linked to start of animation sequence.

//*********************************************************************************** ROTATE POLYGONS FOR ANIMATION.

while(c<nov){mid=al[vl[c][0]][vl[c][1]][um[c]];if(um[c]==1){a1=vl[c][2];a2=vl[c][3];}else{a1=vl[c][0];a2=vl[c][1];}

tangx=(ang[aniti][vl[c][2]][vl[c][3]][0]-ang[aniti][vl[c][0]][vl[c][1]][0])*co[c];

tangx=ang[aniti][vl[c][0]][vl[c][1]][0]+tangx;

tangy=(ang[aniti][vl[c][2]][vl[c][3]][1]-ang[aniti][vl[c][0]][vl[c][1]][1])*co[c];

tangy=ang[aniti][vl[c][0]][vl[c][1]][1]+tangy;

tangz=(ang[aniti][vl[c][2]][vl[c][3]][2]-ang[aniti][vl[c][0]][vl[c][1]][2])*co[c];

tangz=ang[aniti][vl[c][0]][vl[c][1]][2]+tangz;

angx=tangx;angy=tangy;angz=tangz;

tangx=(ang[aniti+1][vl[c][2]][vl[c][3]][0]-ang[aniti+1][vl[c][0]][vl[c][1]][0])*co[c];

tangx=ang[aniti+1][vl[c][0]][vl[c][1]][0]+tangx;

tangy=(ang[aniti+1][vl[c][2]][vl[c][3]][1]-ang[aniti+1][vl[c][0]][vl[c][1]][1])*co[c];

tangy=ang[aniti+1][vl[c][0]][vl[c][1]][1]+tangy;

tangz=(ang[aniti+1][vl[c][2]][vl[c][3]][2]-ang[aniti+1][vl[c][0]][vl[c][1]][2])*co[c];

tangz=ang[aniti+1][vl[c][0]][vl[c][1]][2]+tangz;

angx=angx+((tangx-angx)*anit);angy=angy+((tangy-angy)*anit);angz=angz+((tangz-angz)*anit);

tanipx=anip[aniti][a1][a2][0]+((anip[aniti+1][a1][a2][0]-anip[aniti][a1][a2][0])*anit);

tanipy=anip[aniti][a1][a2][1]+((anip[aniti+1][a1][a2][1]-anip[aniti][a1][a2][1])*anit);

tanipz=anip[aniti][a1][a2][2]+((anip[aniti+1][a1][a2][2]-anip[aniti][a1][a2][2])*anit);

cam(angy,angx,angz,r1x,r1y,r1z,r2x,r2y,r2z,r3x,r3y,r3z);

mv[mvp+(c*3)+0]=((r1x*v[(c*3)])+(r2x*(v[(c*3)+1]-mid))+(r3x*v[(c*3)+2]))+tanipx;

mv[mvp+(c*3)+1]=((r1y*v[(c*3)])+(r2y*(v[(c*3)+1]-mid))+(r3y*v[(c*3)+2]))+tanipy;

mv[mvp+(c*3)+2]=((r1z*v[(c*3)])+(r2z*(v[(c*3)+1]-mid))+(r3z*v[(c*3)+2]))+tanipz;

c+=1;}mvp=0;c=0;//mvp=c for rendering multiple objects (dont forget to reset mvp at beginning of frame)


 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glMatrixMode(GL_PROJECTION);

 glLoadIdentity();

 glup(aspect_ratio,1,0.1f,10000.f);

 glMatrixMode(GL_MODELVIEW);

 glLoadIdentity();


          // CAMERA START

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

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

 glTranslatef(cxp,cyp,czp);

         // CAMERA END



    mv[0]=(xpos*-1.0)-1.0;mv[1]=(ypos*-1.0)-1.0;mv[2]=(zpos*-1.0);

    mv[3]=(xpos*-1.0)+1.0;mv[4]=(ypos*-1.0)-1.0;mv[5]=(zpos*-1.0);

    mv[6]=(xpos*-1.0);mv[7]=(ypos*-1.0)+1.0;mv[8]=(zpos*-1.0);

    mv[9]=-1.0;mv[10]=-1.0;mv[11]=-5.0;

    mv[12]= 1.0;mv[13]=-1.0;mv[14]=-5.0;

    mv[15]= 0.0;mv[16]= 1.0;mv[17]=-5.0;

    mv[18]=-1.0;mv[19]=-1.0;mv[20]=-4.0;

    mv[21]= 1.0;mv[22]=-1.0;mv[23]=-4.0;

    mv[24]= 0.0;mv[25]= 1.0;mv[26]=-4.0;

    texc[0]=0.0;texc[1]=1.0;

    texc[2]=1.0;texc[3]=1.0;

    texc[4]=0.5;texc[5]=0.0;

    texc[6]=0.0;texc[7]=1.0;

    texc[8]=1.0;texc[9]=1.0;

    texc[10]=0.5;texc[11]=0.0;

    texc[12]=0.0;texc[13]=1.0;

    texc[14]=1.0;texc[15]=1.0;

    texc[16]=0.5;texc[17]=0.0;

    tdi[0][2]=0;pi[0][0]=0;

    tdi[1][2]=1;pi[1][0]=0;

    tdi[2][2]=1;pi[2][0]=0;

 while(c2<1){while(c<nop){if(tdi[c][2]==c2&amp;&amp;pi[c][0]==0){// ORDER POLYGONS FOR TEXTURE DRAWING

  skt[c2][(c*9)+0]=mv[(c*9)+0];skt[c2][(c*9)+1]=mv[(c*9)+1];skt[c2][(c*9)+2]=mv[(c*9)+2];

  skt[c2][(c*9)+3]=mv[(c*9)+3];skt[c2][(c*9)+4]=mv[(c*9)+4];skt[c2][(c*9)+5]=mv[(c*9)+5];

  skt[c2][(c*9)+6]=mv[(c*9)+6];skt[c2][(c*9)+7]=mv[(c*9)+7];skt[c2][(c*9)+8]=mv[(c*9)+8];}

 else{

  skt[c2][(c*9)+0]=0.0;skt[c2][(c*9)+1]=0.0;skt[c2][(c*9)+2]=0.0;

  skt[c2][(c*9)+3]=0.0;skt[c2][(c*9)+4]=0.0;skt[c2][(c*9)+5]=0.0;

  skt[c2][(c*9)+6]=0.0;skt[c2][(c*9)+7]=0.0;skt[c2][(c*9)+8]=0.0;}

 c+=1;}c=0;c2+=1;}c2=0;




glDepthMask(GL_TRUE);

 while(c2<1){//::::::::::::::::::::::::::: SELECT TEXTURE

while(c<nop){sk[(c*9)+0]=skt[c2][(c*9)+0];sk[(c*9)+1]=skt[c2][(c*9)+1];sk[(c*9)+2]=skt[c2][(c*9)+2];

sk[(c*9)+3]=skt[c2][(c*9)+3];sk[(c*9)+4]=skt[c2][(c*9)+4];sk[(c*9)+5]=skt[c2][(c*9)+5];

sk[(c*9)+6]=skt[c2][(c*9)+6];sk[(c*9)+7]=skt[c2][(c*9)+7];sk[(c*9)+8]=skt[c2][(c*9)+8];c+=1;}c=0;

glVertexPointer(3,GL_FLOAT,0,sk);


   glActiveTexture(GL_TEXTURE0);

  glGenTextures(1,&amp;texture[0]);

  glBindTexture(GL_TEXTURE_2D, texture[0]);

  glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,

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

   GL_RGBA,GL_UNSIGNED_BYTE,texturesar[c2]->pixels);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);


 glEnableClientState(GL_VERTEX_ARRAY);

 glEnableClientState(GL_TEXTURE_COORD_ARRAY);

  glVertexPointer(3,GL_FLOAT,0,sk);

  glTexCoordPointer(2,GL_FLOAT,0,texc);

glDrawArrays(GL_TRIANGLES,0,9); 

  glDisableClientState(GL_VERTEX_ARRAY);

  glDisableClientState(GL_TEXTURE_COORD_ARRAY);


  glActiveTexture(GL_TEXTURE0);

  glBindTexture(GL_TEXTURE_2D, 0);

  glDeleteTextures(1,&amp;texture[0]);

   c2+=1;}c2=0;//::::::::::::::: END OF TEXTURES




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

while(c<1){free(texturesar[c]);c+=1;}c=0;

EGL_Destroy();

SDL_Quit();

return 0;

}


and here is the eglport.h file:







Code:
/**

*

* eglport.c/.h

* Copyright (C) 2011 Scott Smith

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see <http://www.gnu.org/licenses/>.

*

*/


#ifndef EGLPORT_H

#define EGLPORT_H


#ifdef __cplusplus

extern "C" {

#endif


#include <stdio.h>

#include <math.h>

#include <GLES/gl.h>

#include <EGL/egl.h>

#include <SDL/SDL_syswm.h>


void EGL_Destroy( void );

int EGL_Open( void );

int EGL_Init( void );

void EGL_SwapBuffers( void );


int ConfigureEGL(EGLConfig config);

int FindAppropriateEGLConfigs( void );

int TestEGLError( void );


#ifdef __cplusplus

}

#endif


#endif // EGLPORT_H
 
Last edited by a moderator:

sebt3

homebrew player (P. & C.)
Joined
Sep 9, 2008
Messages
4,747
Age
39
Location
France
Website
sebt3.openpandora.org
The following code compiles without error messages for me, but when I start it it terminates immidiatly.
For a start,what does eglport say on stderr ?


also either use the [ code ] marcker so we can enjoy your code in all its beauty (aka with indent) or upload a tarball somewhere (including makefile and such...)


EDIT:

"Killed" is the only message I get when try to run the program.
"Killed" mean the kernel killed your process. So something realy nasty is going on (if it was only a memory problem it would have been "Segmentation fault")


Are you sure you're able to talk to X11 with this terminal (guessing ssh) ? try runing something.


if that's the only thing you see, it mean the the EGL functions havent finished.


And... this look nasty :



Code:
EGL_Open();

SDL_Surface* sl1;sl1=SDL_SetVideoMode(700,380,0,SDL_SWSURFACE/*|SDL_FULLSCREEN*/);

EDIT2:http://www.pandorawi...the_EGL_context
 
Last edited by a moderator:

Pickle

Mega GP Mania
Joined
May 30, 2006
Messages
5,456
Location
Detroit, Michigan
Website
Visit site
put some code flags around the code.



Code:
glTexImage2D(GL_TEXTURE_2D,0,3,

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

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

The 3 for internal format is not supported with GLES. Internal and External have to be the same. You could try GL_BGR for both, but i think only GLES2 supports it.


Edit: In addition, is there any reason why your loading textures each frame? If they are static then load them once and then just bind them when you need to draw them.
 
Last edited by a moderator:

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
I dont know how much video memory the Pandora has, does it even have any? Otherwise gpu needs to fetch from ram anyway hmm, does automatically reserve from ram perhaps? either way there shouldnt be a speed difference, but I havent tested that.


I dont use that glTexImage2D call, I used some old code and just added to it so I havent removed all code that was blanked out, sorry. GLES dont suport BGR format either, on my laptop if I use RGB format the colors are changed, but texture still displays normally other then that, and since data contains value it shouldnt know that anything was wrong anyway, so I dont understand why textures work on laptop but not Pandora.


I dont know what stderr is, standard error? The terminal only prints out Killed and nothing else. I dont know how to use makefiles either, sorry. I have another GLES program that I compile with basically same content only less of my own code, it runs fine except the polygons are blank without a texture.
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
Could it be the static floats trying to reserve more memory then what is available? I never calculated how much memory I used, several gigs never had the need... I try blanking that and check.
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
Yea, that was what it was, program started, but black screen and nothing happen, the Pandora was working fine in the background though, mayby to slow code to work at all? I look more tomorrow.
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
yea, I use same image as on laptop also. I tryed loading it in a SDL program that only displays the image, and it dosnt show up, arent there any image viewing programs on the Pandora OS? I cant see the image at all it seem.

Can I replace the SDL library in C-DEVTOOLS with the newer one?
 

mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
From the updated SDL thread,


"new in this update:

  • true 24bpp/32bpp support"



So I converted imagr to 16bit, it wont display at all in SDL program, but in old GLES renderer the one that worked I now get multicolored garbage, its not the image but its atleast not a blank surface either.


What do I do with the crosscompiler, how do I use it? The one thats the second option in the crosscompiler thread, not Yeactfe or what it was called but the other, if I have to use cmake or something is there an easy beginners tutorial anyone would recomend?
 
Top