if anyone want to dig my source , here it is :D :D
------------------------------
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/gl.h>
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
#define RENDER 1 // No ray-plane intersection (i haven't studied the vectors properly )
#define SELECT 2 // So old-good color selection
#define MORPHOS 1
#define SWITCH_INT(a) { char s_i, *p_i;p_i= (char *)&(a);s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i;s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
int mode = RENDER;
int FRAMES_PER_SECOND = 50; //The frames per second const
int frame = 0; //Keep track of the current frame
int startTicks = 0;
int currentTicks=0;
int SCREENW=800;
int SCREENH=600;
int mousex,mousey;
unsigned int nIndex;
void DrawSelection() {
glDisable(GL_LIGHTING);
glDisable( GL_TEXTURE_2D );
nIndex=10000;
glColor3ub ( nIndex % 256, (nIndex>>8) % 256, (nIndex>>16) % 256);
glBegin(GL_QUADS);
glVertex3f( -0.5f, -0.5f, +0.5f);
glVertex3f( +0.5f, -0.5f, +0.5f);
glVertex3f( +0.5f, +0.5f, +0.5f);
glVertex3f( -0.5f, +0.5f, +0.5f);
glEnd();
}
void mouseMove (int x, int y) {
static int x_pos = 0;
static int y_pos = 0;
x_pos = x;
y_pos = y;
}
void ProcessPick() {
unsigned int col;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
glReadPixels( mousex, viewport[3]-mousey, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &col);
SWITCH_INT(col);
printf(" color number %u\n",nIndex);
printf(" color founded %u\n",col);
printf(" color put %u ,%u ,%u\n",nIndex%256,(nIndex>>8) % 256, (nIndex>>16) % 256);
printf(" color get %u ,%u ,%u\n",col%256,(col>>8) % 256, (col>>16) % 256);
}
int main(int argc, char *argv[]) {
SDL_Surface *screen;
int done;
SDL_Event event;
if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*
screen = SDL_SetVideoMode( SCREENW, SCREENH, 32, SDL_OPENGL /*| SDL_FULLSCREEN*/); // *changed*
if ( !screen ) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
glViewport( 0, 0, SCREENW, SCREENH );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0 * SCREENW/SCREENH, 0.1, 400.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable (GL_DEPTH_TEST);
glEnable (GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gluLookAt(0,0,18,0.0,0.0,0.0,0.0,1.0,0.0);
done=0;
glClearColor( 0, 0, 0, 0);
while(!done) {
startTicks=SDL_GetTicks();
// Clear the screen before drawing
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEMOTION:
mouseMove (event.button.x, event.button.y);
mousex=event.button.x;
mousey=event.button.y;
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) done=1;
break;
case SDL_MOUSEBUTTONDOWN :
if (SDL_GetMouseState (NULL,NULL) & SDL_BUTTON_LMASK) {
mousex=event.button.x;
mousey=event.button.y;
mode = SELECT;
}
break;
default:
break;
}
}
if (mode == SELECT) DrawSelection(); else DrawSelection();
if (mode == SELECT) {
ProcessPick();
mode = RENDER;
} else SDL_GL_SwapBuffers();
if( currentTicks < 1000 / FRAMES_PER_SECOND ) SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - currentTicks );
}
SDL_Quit();
return 0;
}
[ Edited by raistlin77it 17.06.2011 - 17:57 ]I'm nerdy in the extreme
And whiter than sour cream
White&Nerdy 2006 Al Yankovic