View Single Post
Posts: 58 | Thanked: 28 times | Joined on Nov 2010
#864
Originally Posted by javispedro View Post
Send them to Gitorious, to me ( maemo at javispedro dot com ) or attach them here.
I am not sure but you might find this code useful
Code:
 file:sdlgl.c
/* Including math.h is not bad. It may become useful somehow */
#include <math.h>
/* what about establishing a surface? */
SDL_Surface *surface;
/* variable context, better or worse? */
/* perspective replacement for opengles? */
void gluPerspective(double fovy,double aspect,double zNear,double zFar)
{
double xmin,xmax,ymin,ymax;
ymax = zNear * tan(fovy * M_PI / 360);
ymin=-ymax;
xmin=ymin*aspect;
xmax=ymax*aspect;
glFrustumf(xmin,xmax,ymin,ymax,zNear,zFar);
}
/* defining screen resolution? */
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16
int resizeWindow(int width,int height)
{
GLfloat ratio;
if(height==0)
height =1;
ratio=(GLfloat)width/(GLfloat)height;
glViewport(0,0,(GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,ratio,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return(1);
}
/* a function for later use */
int initGL(GLvoid)
{
static int gles_init ...
SDL_GLES_MakeCurrent(context);
/* maybe some applications require background color and smoothing? */
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glHint(GL_PERSPECTIVE_CORRECTION,GL_NICEST);
glEnableClientState(GL_VERTEX_ARRAY);
return(1);
}
/* buffer cleaning might be needed */
glClear(GL_COLOR_BUFFER_BIT);
Also, it would be nice if the buffer size is set to rgba5551 instead of rgb565 because N900 has a native ALPHA Channel support.
(Set attribute has been disabled,maybe enabling it is useful(after getting the buffer size)Example after requested 16bit buffer size with alpha channel:
Code:
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
You have also skipped SetEventFilter programming in the description I must say:
void SDL_SetEventFilter(SDL_EventFilter filter);
This function sets up a filter to process all events before they are posted to the event queue. This is a very powerful and flexible feature. The filter is prototyped as:

typedef int (*SDL_EventFilter)(const SDL_Event *event);If the filter returns 1, then the event will be added to the internal queue. If it returns 0, then the event will be dropped from the queue. This allows dynamically-selective filtering of events.
There is one caveat when dealing with the SDL_QUITEVENT event type. The event filter is only called when the window manager desires to close the application window. If the event filter returns 1, then the window will be closed, otherwise the window will remain open if possible. If the quit event is generated by an interrupt signal, it will bypass the internal queue and be delivered to the application at the next event poll.
Example:
Code:
/* Using additional function */
int FilterEvents(const SDL_Event *event) {
    static int boycott = 1;

    /* This quit event signals the closing of the window */
    if ( (event->type == SDL_QUIT) && boycott ) {
        printf("Quit event filtered out -- try again.\n");
        boycott = 0;
        return(0);
    }
    if ( event->type == SDL_MOUSEMOTION ) {
        printf("Mouse moved to (%d,%d)\n",
                event->motion.x, event->motion.y);
        return(0);    /* Drop it, we've handled it */
    }
    return(1);
}

SDL_SetEventFilter(FilterEvents);
Are you sure GLES minor version not needed?:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
Here's a link for palm's opengl programming,you may find it useful:
http://www.webos-internals.org/wiki/...1_3D_Cube_Demo

Last edited by aligoodidea; 2010-12-15 at 11:54.