My first 3D application with Raydium
Ref:
RaydiumTutorials
Before anything:
- Follow InstallRaydiumEn? instructions
- Create a new file, named test.c, in Raydium root directory (and not "raydium/" subdirectory)
Includes:
#include "raydium/index.c"
This line allows use of all
Raydium's functions.
main:
Window's declaration:
int main(int argc, char **argv)
{
raydium_init_args(argc,argv);
raydium_window_create(640,480,RAYDIUM_RENDERING_WINDOW,"Mon premier test !");
raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_TRILINEAR);
Nothing hard, here : we send command line arguments to
Raydium, and we create a window (640x480). It's also possible to use RAYDIUM_RENDERING_FULLSCREEN, and to change window's title, of course.
raydium_texture_filter_change will switch to a trilinear filter, the best one allowed by
Raydium.
Visibility space:
raydium_projection_near=0.01;
raydium_projection_far=1000;
raydium_projection_fov=60;
raydium_window_view_update();
These three variables will define min and max visibility values (near and far) of the camera.
Values depends on objects sizes : here, we can imagine a world of 1000 units that we want to display integrally.
raydium_window_view_update() function will updade values to hardware.
Primary light settings (sun):
For this step, a good idea is to store light color with a variable:
GLfloat sun[]={1.0,0.9,0.5,1.0};
Colors are expressed with RGBA schema (Red, Green, Blue, Alpha). Each element is clamped to the range [0, 1]. Alpha have no effect here.
raydium_light_on(0);
memcpy(raydium_light_color[0],sun,raydium_internal_size_vector_float_4);
raydium_light_intensity[0]=1000000;
raydium_light_position[0][0]=50;
raydium_light_position[0][1]=150;
raydium_light_position[0][2]=200;
raydium_light_update_all(0);
Then, we turn on light 0, and assign color with memcpy. We must also sets intensity (Intense here, for a "sun effect"), position (X,Y and Z), and apply.
raydium_background_color_change(sun[0],sun[1],sun[2],sun[3]);
This function will sets sun's color as the background color of the scene.
It's interesting to disable fog, since it allows us to see the sky.
Drawing function:
Declaration
The next step is to declare a new function, dedicated to drawing ("rendering"). This function will be then called by Raydium.
This function must follow the following prototype: void function(void)
Then, we will send this function to
Raydium , at the end of main():
raydium_callback(&display);
Implementation:
This function will allow the user to move camera, and this camera will always look at the scene's center (0,0,0).
First step: manage user input:
This call will emulate a joystick, if none is detected. This function allows you to use raydium_joy_*, even if no joystick nor joypad is configured.
Now, we can declare three global variables to store camera's position, juste after includes, for example.
GLfloat camx=10;
GLfloat camy=10;
GLfloat camz=20;
Then we modify this values using user inputs:
camx+=raydium_joy_x;
camy+=raydium_joy_y;
if(raydium_key[GLUT_KEY_PAGE_DOWN]) camz--;
if(raydium_key[GLUT_KEY_PAGE_UP] ) camz++;
if(raydium_key_last==1027) exit(0);
Now, the drawing part of the function:
raydium_clear_frame();
raydium_camera_look_at(camx,camy,camz,0,0,0);
raydium_object_draw_name("cocorobix.tri");
raydium_rendering_finish();
It's time to compile this first application, using ocomp.sh script, for example:
./ocomp.sh test.c
Complete source code:
#include "raydium/index.c"
GLfloat sun[]={1.0,0.9,0.5,1.0};
GLfloat camx=10;
GLfloat camy=10;
GLfloat camz=20;
void display(void)
{
raydium_joy_key_emul();
camx+=raydium_joy_x;
camy+=raydium_joy_y;
if(raydium_key[GLUT_KEY_PAGE_DOWN]) camz--;
if(raydium_key[GLUT_KEY_PAGE_UP] ) camz++;
if(raydium_key_last==1027) exit(0);
raydium_clear_frame();
raydium_camera_look_at(camx,camy,camz,0,0,0);
raydium_object_draw_name("cocorobix.tri");
raydium_rendering_finish();
}
int main(int argc, char **argv)
{
raydium_init_args(argc,argv);
raydium_window_create(640,480,RAYDIUM_RENDERING_WINDOW,"Mon premier test !");
raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_TRILINEAR);
raydium_projection_near=0.01;
raydium_projection_far=1000;
raydium_projection_fov=60;
raydium_window_view_update();
raydium_light_on(0);
memcpy(raydium_light_color[0],sun,raydium_internal_size_vector_float_4);
raydium_light_intensity[0]=1000000;
raydium_light_position[0][0]=50;
raydium_light_position[0][1]=150;
raydium_light_position[0][2]=200;
raydium_light_update_all(0);
raydium_background_color_change(sun[0],sun[1],sun[2],sun[3]);
raydium_fog_disable();
raydium_callback(&display);
return 0;
}
Tutorial 2:
TutorialMoveObjects?