Pandora Cant compile shaders on Pandora with CDEVTOOLS


mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
I get the window open and random colored pixels and then the Panda freezes.


My error check messages dont get printed out in the terminal, but the EGL messages do.


I use the old EGL port and have blanked out the line with close() cos it said it was undefined, I have changed in .h from include GLES to GLES2/gl2.h I think, and I type -lGLESv2 when compiling, no complaints from compiler.


And the code is the following:


main cpp:


#include "SDL/SDL.h"


#include "eglport.c"


//#include "eglport.c"


//#include "GLES2/gl2.h"


#include "iostream"


#include "fstream"


#include "math.h"


#include "unistd.h"


using namespace std;


//enum {ATTRIB_VERTEX=0, ATTRIB_COLOR=1};


int verta=0,cola=1;


void setps(float fov,float ar,float zn,float& left,float& right,float& bottom,float& top){


float xmin,xmax,ymin,ymax;ymax=(float)zn*tan(fov*0.00872);


ymin=-ymax;xmin=ymin*ar;xmax=ymax*ar;left=xmin;right=xmax;bottom=ymin;top=ymax;}


int main(){


SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);


EGL_Open();


SDL_Surface* sl1;


sl1=SDL_SetVideoMode(400,380,0,SDL_HWSURFACE);


EGL_Init();


// SDL_Surface* s=SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_OPENGL|SDL_DOUBLEBUF);


SDL_Event gameover;


Uint8* key;


int quit=0;


static int T0=0,Frames=0;


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


unsigned int oldTime=0,currentTime=0;


//glewInit();


glClearDepthf(1.0f);


glEnable(GL_DEPTH_TEST);


glDepthFunc(GL_LEQUAL);


float colors[]={1.0,0.0,0.0,1.0, 0.0,1.0,0.0,1.0, 0.0,0.0,1.0,1.0};


float vertices[]={-0.5,-0.5,-2.0, 0.5,-0.5,-2.0, 0.0,0.5,-2.0};


int lenght1,lenght2,foward=0,backward=0,left=0,right=0,free_float=0;


char * buffer1, * buffer2;


float r_fov=45.0f,r_aspectRatio=1.0f,rn=1.0f,rf=200000.0f,rleft,rright,rbottom,rtop;


float tx,ty,tz,ta,xpos=0.0f,ypos=0.0f,zpos=0.0f,xr=0.0f,yr=0.0f,zr=0.0f,ye,rx,ry,nnx,ms=1.0f;


float matr[16],matt[16],mats[16];


ifstream is1,is2;


is1.open("versha4.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("frasha4.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 char* vv=buffer1;


const char* ff=buffer2;


cout<<vv<<endl;cout<<ff<<endl;


int v=glCreateShader(GL_VERTEX_SHADER);


int f=glCreateShader(GL_FRAGMENT_SHADER);


glShaderSource(v, 1, &vv, NULL);


glShaderSource(f, 1, &ff, NULL);


glCompileShader(v); glCompileShader(f);


int IsCompiled_FS;


glGetShaderiv(f,GL_COMPILE_STATUS,&IsCompiled_FS);


if(IsCompiled_FS==true){cout<<"FRAG=GOOD!"<<endl;}


else{cout<<"FRAG=BAD..."<<endl;}


glGetShaderiv(v,GL_COMPILE_STATUS,&IsCompiled_FS);


if(IsCompiled_FS==true){cout<<"VERT=GOOD!"<<endl;}


else{cout<<"VERT=BAD..."<<endl;}


int prog = glCreateProgram();


glAttachShader(prog,v);


glAttachShader(prog,f);


glBindAttribLocation(prog,verta,"pos");


glBindAttribLocation(prog,cola,"col");


glLinkProgram(prog);


glGetProgramiv(prog,GL_LINK_STATUS,(int *)&IsCompiled_FS);


if(IsCompiled_FS==true){cout<<"LINK=GOOD!"<<endl;}


else{cout<<"LINK=BAD..."<<endl;}


//glBindAttribLocation(prog,ATTRIB_VERTEX,"pos");


//glBindAttribLocation(prog,ATTRIB_COLOR,"col");


while(quit==0){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]){foward=1;}else{foward=0;}


if(key[sDLK_DOWN]){backward=1;}else{backward=0;}


if(key[sDLK_LEFT]){left=1;}else{left=0;}


if(key[sDLK_RIGHT]){right=1;}else{right=0;}


if(key[sDLK_m]){xr-=0.5f;}


if(key[sDLK_n]){xr+=0.5f;}


// MOVEMENT PROCESSING ::::::::::::::::::::::::::::::::::::::::::::::::::::


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


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


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


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


if(yr>90.0f&&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(foward==1){


rx=(float)(cos((xr+135)*0.017453))+(sin((xr+135)*0.017453));


ry=(float)(-sin((xr+135)*0.017453))+(cos((xr+135)*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(ry<=90.0f){ypos+=ms*(1.0f-ye);}else{ypos-=ms*(1.0f-ye);}}}


if(backward==1){


rx=(float)(cos((xr+135)*0.017453))+(sin((xr+135)*0.017453));


ry=(float)(-sin((xr+135)*0.017453))+(cos((xr+135)*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(ry<=90.0f){ypos+=ms*(1.0f-ye);}else{ypos-=ms*(1.0f-ye);}}}


if(left==1){


rx=(float)(cos((xr+45)*0.017453))+(sin((xr+45)*0.017453));


ry=(float)(-sin((xr+45)*0.017453))+(cos((xr+45)*0.017453));


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


if(right==1){


rx=(float)(cos((xr+225)*0.017453))+(sin((xr+225)*0.017453));


ry=(float)(-sin((xr+225)*0.017453))+(cos((xr+225)*0.017453));


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


tx=0;ty=0;tz=0;ta=xr;


// CREATE PERSPECTIVE RENDERING :::::::::::::::::::::::::::::::::::::::::::


setps(r_fov,r_aspectRatio,rn,rleft,rright,rbottom,rtop);


matr[0]=(float)(2*rn)/(rright-rleft);


matr[1]=0.0f;


matr[2]=0.0f;


matr[3]=0.0f;


matr[4]=0.0f;


matr[5]=(float)(2*rn)/(rtop-rbottom);


matr[6]=0.0f;


matr[7]=0.0f;


matr[8]=(float)(rright+rleft)/(rright-rleft);


matr[9]=(float)(rtop+rbottom)/(rtop-rbottom);


matr[10]=(float)-((rf+rn)/(rf-rn));


matr[11]=-1.0f;


matr[12]=0.0f;


matr[13]=0.0f;


matr[14]=(float)-((2*rf*rn)/(rf-rn));


matr[15]=0.0f;


int location1=glGetUniformLocation(prog,"matp");


glUniformMatrix4fv(location1, 1, 1, matr);


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


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


glVertexAttribPointer(verta,3,GL_FLOAT,0,0,vertices);


glVertexAttribPointer(cola,4,GL_FLOAT,0,0,colors);


glEnableVertexAttribArray(verta);


glEnableVertexAttribArray(cola);


glUseProgram(prog);


glDrawArrays(GL_TRIANGLES,0,3);


glDisableVertexAttribArray(verta);


glDisableVertexAttribArray(cola);


// SDL_GL_SwapBuffers();


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


}


delete[] buffer1;


delete[] buffer2;


SDL_Quit();


return 0;


}


****************************************************************************************************************


versha4.txt:


attribute vec3 pos;


attribute vec4 col;


varying vec4 colv;


uniform mat4 matp;


void main()


{


gl_Position = vec4(pos.x,pos.y,pos.z,1.0)*matp;


colv=col;


}


****************************************************************************************************************


frasha4.txt:


varying vec4 colv;


void main()


{


gl_FragColor = vec4(colv.xyz,1.0);


}
 
It makes the error messages print in terminal, but winow is still multicolored pixels and freezes.

I have another code that produces a black winow that dont freeze, but the code that matters should be exactly the same...
 
I think its a clue, if shaders compile they should say shade=good, else they should say shader=bad. the fact that they dont get printed out, Im back to not recieving them seem like something go wrong before that part of the code? but only EGL_swapbuffer should make any colors appear in the window? I dont get it...


I tried couting f to the terminal after glShadersource, and it produces 0, in both v and f they both get pRInted out as 0, if i try my linux code they get printed out as 1 and 2.
 
gl_Position does not exist in GL ES 2's GLSL variant, so that won't help.


Also, as Pickle said, you'll need to set the float precision in the fragment shader, else it'll likely complain there too.


You're very much forced to do the full shader-based pipeline stuff and handle your own Model-View-Projection matrices with GL ES 2...
 
gl_Position does not exist in GL ES 2's GLSL variant, so that won't help.

Sure it does.


heres my basic vertex/fragment shader



Code:
precision mediump float;


uniform mat4 u_MVPMatrix;   	// A constant representing the combined model/view/projection matrix.


uniform vec4 u_Color;   	// Per-vertex color information we will pass in.

uniform float u_PointSize;


attribute vec3 a_Position;  // Per-vertex position information we will pass in.


varying vec4 v_Color;   	// This will be passed into the fragment shader.


void main()

{

	v_Color = u_Color;

	// gl_Position is a special variable used to store the final position.

	// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.

	gl_PointSize = u_PointSize;

	gl_Position = u_MVPMatrix * vec4(a_Position, 1.0);

}





Code:
precision mediump float;


varying vec4 v_Color;


void main()

{

    gl_FragColor = v_Color;

}
 
Bah.. not sure what I'm thinking of then.. I'm wresting with five things at once just now.. apologies for that!


Ok, in an attempt to redeem myself, the code I use for dealing with shaders can be found in my GLESGAE project here:


https://github.com/stuckie/glesgae/blob/master/Graphics/Shader.h


https://github.com/stuckie/glesgae/blob/master/Graphics/Shader.cpp


There's TODOs marked where you could printf/cout out the infolog, and figure out just what's gone wrong.


I haven't done it yet, as I've not gone back in to look at my shader pipeline, but I'd be using my own Logger class anyway.


Only thing that might be odd in there is HashString, but you can literally just think of this as a standard string if you want.. all it is, is a string converted to a number for quicker comparison tests.
 
Last edited by a moderator:
Possibly, it would match up with what I was thinking of with handling transforms and things at the time.. anyway, my shader loading code is linked if it's of any use.


I highly suggest grabbing the info log from GLES and printing it out as it'll tell you any errors it finds when compiling the shaders, and it's usually pretty detailed.
 
Back
Top