pavana
04-18-2010, 01:16 PM
hello everybody.. this is the code i have
void display(void)
{
int i ;
float R;
r_max=n_circles;
char* str ;
str = (char*)malloc(500*sizeof(char)) ;
sprintf(str , "Radar Display ,Beam Rotating at %.1f rpm at a speed of %.3f" ,rpm, inr) ;
glutSetWindowTitle(str) ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f(0.0f ,0.8f , 0.0f, 0.2f) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f(-5.0, -5.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(-5.0, 5.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(5.0, 5.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(5.0, -5.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
glClear(GL_DEPTH_BUFFER_BIT) ;
glColor4f(0.0f , 0.2f , 0.0f, 0.6f) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
for(i = 1 ; i <= n_circles ; i++)
{
R = r_min + ((r_max - r_min)/(n_circles-1))*(i-1) ;
Draw_circle(R) ;
}
glClear(GL_DEPTH_BUFFER_BIT) ;
glColor4f(0.0 , 0.2 , 0.0, 0.8) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBegin(GL_LINES);
glVertex2f(0.0,0.0);
glVertex2f(r_max,0.0);
glVertex2f(0.0,0.0);
glVertex2f(0.0,r_max);
glVertex2f(0.0,0.0);
glVertex2f(0.0, -r_max);
glVertex2f(0.0,0.0);
glVertex2f(-r_max,0.0);
glEnd();
if(done==30)
{
for(i=1;i<=12;i++)
{
if(i%3!=0)
{
glBegin(GL_LINES);
glVertex2f(0.0,0.0);
glVertex2f(r_max*cos(angle1*i) , r_max*sin(angle1*i)) ;
glEnd();
}
}
}
else
{
for(i=1;i<=8;i++)
{
if(i%2!=0)
{
glBegin(GL_LINES);
glVertex2f(0.0,0.0);
glVertex2f(r_max*cos(angle2*i) , r_max*sin(angle2*i)) ;
glEnd();
}
}
}
glClear(GL_DEPTH_BUFFER_BIT) ;
glPushMatrix() ;
glRotatef(spin , 0.0 , 0.0 , 1.0) ;
glColor4f(0.0f,0.8f,0.0f,0.4f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBegin(GL_POLYGON) ;
glVertex2f(0.0 , 0.0) ;
glVertex2f(r_max*cos(0.0) , r_max*sin(0.0)) ;
glVertex2f(r_max*cos(0.1) , r_max*sin(0.1)) ;
glEnd() ;
glPopMatrix() ;
spinDisplay();
glutSwapBuffers() ;
}
//here is the main function
void main (int argc, char **argv)
{
printf("Enter the maximum range (50km/60km/75km)\n");
scanf("%f",&max_range);
if(max_range==50 || max_range==75)
n_circles=5;
else if(max_range==60)
n_circles=6;
printf("Enter the angle 30 or 45\n");
scanf("%d",&done);
centerOnScreen ();
glutInit(&argc, argv);
glutInitWindowSize (window_width, window_height);
glutInitWindowPosition (window_x, window_y);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE);
main_window = glutCreateWindow (window_title);
if (full_screen)
glutFullScreen ();
init();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
loadTextureFromFile( filename );
setupGLUI ();
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMainLoop();
}
i have mapped a google map to a quad. i want this map within one layer,circles within another layer,lines within another layer and polygon with in another layer.
can anybody help me in achieving this using wgl stuffs...
Thank u.
pavana
04-18-2010, 10:41 PM
actually wot m doi is... at the background ive put a google map after that m goi to display some circles and after that some lines (angle markers)and then a rotating triangle from center.
wot i need is.. i need all the above 4 stuffs(map,circles,lines,triangle)to be displayed as seperate layers using the layering concept in opengl.
iv gone thru the wgl stuffs but m not gettin how to go with it...
ll paste the code
#include <windows.h>
#include <math.h>
#include <GL/glui.h>
#include <GL/glut.h>
#include <Gl/glu.h>
# include <string.h>
# include <stdlib.h>
# include <stdio.h>
#ifndef RGBIMAGE_H
#define RGBIMAGE_H
#include <assert.h>
# define dtheta 0.1
# define PI 3.14159
static GLfloat spin = 360.0 ;
static int n_circles ;
static float r_min=1 , r_max=8 ;
static float inr = 0.1 ;
static int done;
static float angle1=0.5257;
static float angle2=0.7877;
static float max_range;
class RgbImage
{
public:
RgbImage();
RgbImage( const char* filename );
RgbImage( int numRows, int numCols ); // Initialize a blank bitmap of this size.
~RgbImage();
bool LoadBmpFile( const char *filename ); // Loads the bitmap from the specified file
bool WriteBmpFile( const char* filename ); // Write the bitmap to the specified file
#ifndef RGBIMAGE_DONT_USE_OPENGL
bool LoadFromOpenglBuffer(); // Load the bitmap from the current OpenGL buffer
#endif
long GetNumRows() const { return NumRows; }
long GetNumCols() const { return NumCols; }
// Rows are word aligned
long GetNumBytesPerRow() const { return ((3*NumCols+3)>>2)<<2; }
const void* ImageData() const { return (void*)ImagePtr; }
const unsigned char* GetRgbPixel( long row, long col ) const;
unsigned char* GetRgbPixel( long row, long col );
void GetRgbPixel( long row, long col, float* red, float* green, float* blue ) const;
void GetRgbPixel( long row, long col, double* red, double* green, double* blue ) const;
void SetRgbPixelf( long row, long col, double red, double green, double blue );
void SetRgbPixelc( long row, long col,
unsigned char red, unsigned char green, unsigned char blue );
// Error reporting. (errors also print message to stderr)
int GetErrorCode() const { return ErrorCode; }
enum {
NoError = 0,
OpenError = 1, // Unable to open file for reading
FileFormatError = 2, // Not recognized as a 24 bit BMP file
MemoryError = 3, // Unable to allocate memory for image data
ReadError = 4, // End of file reached prematurely
WriteError = 5 // Unable to write out data (or no date to write out)
};
bool ImageLoaded() const { return (ImagePtr!=0); } // Is an image loaded?
void Reset(); // Frees image data memory
private:
unsigned char* ImagePtr; // array of pixel values (integers range 0 to 255)
long NumRows; // number of rows in image
long NumCols; // number of columns in image
int ErrorCode; // error code
static short readShort( FILE* infile );
static long readLong( FILE* infile );
static void skipChars( FILE* infile, int numChars );
static void RgbImage::writeLong( long data, FILE* outfile );
static void RgbImage::writeShort( short data, FILE* outfile );
static unsigned char doubleToUnsignedChar( double x );
};
inline RgbImage::RgbImage()
{
NumRows = 0;
NumCols = 0;
ImagePtr = 0;
ErrorCode = 0;
}
inline RgbImage::RgbImage( const char* filename )
{
NumRows = 0;
NumCols = 0;
ImagePtr = 0;
ErrorCode = 0;
LoadBmpFile( filename );
}
inline RgbImage::~RgbImage()
{
delete[] ImagePtr;
}
// Returned value points to three "unsigned char" values for R,G,B
inline const unsigned char* RgbImage::GetRgbPixel( long row, long col ) const
{
assert ( row<NumRows && col<NumCols );
const unsigned char* ret = ImagePtr;
long i = row*GetNumBytesPerRow() + 3*col;
ret += i;
return ret;
}
inline unsigned char* RgbImage::GetRgbPixel( long row, long col )
{
assert ( row<NumRows && col<NumCols );
unsigned char* ret = ImagePtr;
long i = row*GetNumBytesPerRow() + 3*col;
ret += i;
return ret;
}
inline void RgbImage::GetRgbPixel( long row, long col, float* red, float* green, float* blue ) const
{
assert ( row<NumRows && col<NumCols );
const unsigned char* thePixel = GetRgbPixel( row, col );
const float f = 1.0f/255.0f;
*red = f*(float)(*(thePixel++));
*green = f*(float)(*(thePixel++));
*blue = f*(float)(*thePixel);
}
inline void RgbImage::GetRgbPixel( long row, long col, double* red, double* green, double* blue ) const
{
assert ( row<NumRows && col<NumCols );
const unsigned char* thePixel = GetRgbPixel( row, col );
const double f = 1.0/255.0;
*red = f*(double)(*(thePixel++));
*green = f*(double)(*(thePixel++));
*blue = f*(double)(*thePixel);
}
inline void RgbImage::Reset()
{
NumRows = 0;
NumCols = 0;
delete[] ImagePtr;
ImagePtr = 0;
ErrorCode = 0;
}
#endif
void init ();
void display (void);
void reshape (int w, int h);
void mouse (int button, int state, int x, int y);
void entry (int state);
int window_x;
int window_y;
int window_width = 600;
int window_height = 500;
char *window_title = "GLUI Window Template";
GLuint main_window;
int full_screen = 0;
GLUI * glui_window;
int wireframe = 1;
int draw = 1;
int listbox_item_id = 7;
int radiogroup_item_id = 0;
int radiogroup_item_id1 = 1;
float speed = 50.0;
int az=30;
int hh=10;
int sr=0;
int er=60;
int no=1;
char * ss="ass1";
char * ash=" Hello!!..CAP=30 deg";
void setupGLUI ();
void idle ();
void glui_callback (int arg);
enum
{
MAP_LISTBOX = 0,
NUMBER,
TYPE_OF_TARGAT_RADIOGROUP,
TIME_RADIOGROUP,
ID,
SPEED_SPINNER,
AZIMUTH_EDITTEXT_INT,
HEADING,
START_RANGE,
END_RANGE,
OK_BUTTON,
RESET_BUTTON
};
enum GLUT_SHAPES
{
GLUT_WIRE_CUBE = 0,
GLUT_SOLID_CUBE,
GLUT_WIRE_SPHERE,
GLUT_SOLID_SPHERE,
};
void loadTextureFromFile(char *filename)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
RgbImage theTexMap( filename );
// Pixel alignment: each row is word aligned (aligned to a 4 byte boundary)
// Therefore, no need to call glPixelStore( GL_UNPACK_ALIGNMENT, ... );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3,theTexMap.GetNumCols(), theTexMap.GetNumRows(),
GL_RGB, GL_UNSIGNED_BYTE, theTexMap.ImageData() );
}
void centerOnScreen ();
//void drawObject ();
void printMatrixf (float *matrix);
void init ()
{
glClearColor (0.0, 0.0, 0.0, 0.0);
//glColor4f(0.0 , 1.0 , 0.0, 0.4) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glShadeModel(GL_FLAT) ;
}
void Draw_circle(float r)
{
float angle ;
int i ;
glBegin(GL_LINE_LOOP) ;
for(i = 0 ; i < 100 ; i++)
{
angle = 2*PI*i/100 ;
glVertex2f(r*cos(angle) , r*sin(angle)) ;
}
glEnd() ;
}
void display(void)
{
int i ;
float R , cps;
char* str ;
cps = 10*(inr-0.1)/14 ;
str = (char*)malloc(500*sizeof(char)) ;
sprintf(str , "Radar Display , scanning at %f cycles per second" , cps) ;
glutSetWindowTitle(str) ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f(0.0f , 1.0f , 0.0f, 0.2f) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f(-8.0, -8.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(-8.0, 8.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(8.0, 8.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(8.0, -8.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
glClear(GL_DEPTH_BUFFER_BIT) ;
glColor4f(0.0f , 0.2f , 0.0f, 0.6f) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
for(i = 1 ; i <= n_circles ; i++)
{
R = r_min + ((r_max - r_min)/(n_circles-1))*(i-1) ;
Draw_circle(R) ;
}
glClear(GL_DEPTH_BUFFER_BIT) ;
glColor4f(0.0 , 0.2 , 0.0, 0.8) ;
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBegin(GL_LINES);
glVertex2f(0.0,0.0);
glVertex2f(r_max,0.0);
glVertex2f(0.0,0.0);
glVertex2f(0.0,r_max);
glVertex2f(0.0,0.0);
glVertex2f(0.0, -r_max);
glVertex2f(0.0,0.0);
glVertex2f(-r_max,0.0);
glEnd();
if(done==30)
{
for(i=1;i<=12;i++)
{
if(i%3!=0)
{
glBegin(GL_LINES);
glVertex2f(0.0,0.0);
glVertex2f(r_max*cos(angle1*i) , r_max*sin(angle1*i)) ;
glEnd();
}
}
}
else
{
for(i=1;i<=8;i++)
{
if(i%2!=0)
{
glBegin(GL_LINES);
glVertex2f(0.0,0.0);
glVertex2f(r_max*cos(angle2*i) , r_max*sin(angle2*i)) ;
glEnd();
}
}
}
glClear(GL_DEPTH_BUFFER_BIT) ;
glPushMatrix() ;
glRotatef(spin , 0.0 , 0.0 , 1.0) ;
glColor4f(0.0f,1.0f,0.0f,0.4f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBegin(GL_POLYGON) ;
glVertex2f(0.0 , 0.0) ;
glVertex2f(r_max*cos(0.0) , r_max*sin(0.0)) ;
glVertex2f(r_max*cos(dtheta) , r_max*sin(dtheta)) ;
glEnd() ;
glPopMatrix() ;
glutSwapBuffers() ;
}
void centerOnScreen ()
{
window_x = (glutGet (GLUT_SCREEN_WIDTH) - window_width)/2;
window_y = (glutGet (GLUT_SCREEN_HEIGHT) - window_height)/2;
}
void spinDisplay(void)
{
spin = spin - inr ;
if(spin < 0.0)
spin = spin + 360.0 ;
glutPostRedisplay() ;
}
void reshape (int w, int h)
{
printf ("GLUT: ");
float viewWidth = 1.1;
float viewHeight = 1.1;
glViewport(0, 0, w, h);
h = (h==0) ? 1 : h;
w = (w==0) ? 1 : w;
//printf ("Window Width: %d, Window Height: %d.\n", window_width, window_height);
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
if ( h < w ) {
viewWidth *= (float)w/(float)h;
}
else {
viewHeight *= (float)h/(float)w;
}
glOrtho(-r_max , r_max , -r_max , r_max , -1.0 , 1.0) ;
//glOrtho( -viewWidth, viewWidth, -viewHeight, viewHeight, -1.0, 1.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
void mouse (int button, int state, int x, int y)
{
printf ("GLUT: ");
switch (button)
{
case GLUT_LEFT_BUTTON:
switch (state)
{
case GLUT_DOWN:
printf ("Mouse Left Button Pressed (Down)...\n");
glutIdleFunc(spinDisplay) ;
break;
case GLUT_UP:
printf ("Mouse Left Button Released (Up)...\n");
break;
}
break;
case GLUT_MIDDLE_BUTTON:
switch (state)
{
case GLUT_DOWN:
printf ("Mouse Middle Button Pressed (Down)...\n");
break;
case GLUT_UP:
printf ("Mouse Middle Button Released (Up)...\n");
break;
}
break;
case GLUT_RIGHT_BUTTON:
switch (state)
{
case GLUT_DOWN:
printf ("Mouse Right Button Pressed (Down)...\n");
glutIdleFunc(NULL) ;
break;
case GLUT_UP:
printf ("Mouse Right Button Released (Up)...\n");
break;
}
break;
}
}
void keyboard(unsigned char key , int x , int y)
{
switch(key)
{
case 'u' :
if(inr < PI)
inr = inr + 0.1 ;
break ;
case 'd' :
if(inr > 0.0)
inr = inr - 0.1 ;
break ;
}
}
void motion (int x, int y)
{
printf ("GLUT: ");
printf ("Mouse Drag Position: %d, %d.\n", x, y);
}
void entry (int state)
{
printf ("GLUT: ");
if (state == GLUT_ENTERED)
printf ("Mouse entered GLUT window...\n");
else if (state == GLUT_LEFT)
printf ("Mouse left GLUT window...\n");
}
void setupGLUI ()
{
GLUI_Master.set_glutIdleFunc (idle);
glui_window = GLUI_Master.create_glui ("Target Data", 0, window_x +705, window_y-150);
GLUI_Panel *op = glui_window->add_panel ("Number of Targets");
GLUI_EditText *ttt = glui_window->add_edittext_to_panel (op, "number", GLUI_EDITTEXT_INT, &no, NUMBER, glui_callback);
ttt->set_int_limits ( 0, 10 );
GLUI_Panel *op_panel = glui_window->add_panel ("Geographical Area");
glui_window->add_separator_to_panel (op_panel);
GLUI_Listbox *Map_listbox = glui_window->add_listbox_to_panel (op_panel,
"map", &listbox_item_id, MAP_LISTBOX, glui_callback);
glui_window->add_separator_to_panel (op_panel);
Map_listbox->add_item (1, "Mysore");
Map_listbox->add_item (2, "Banglore");
Map_listbox->add_item (3, "Delhi");
Map_listbox->add_item (4, "Hydrabad");
Map_listbox->add_item (5, "Mumbai");
Map_listbox->add_item (6, "India map");
Map_listbox->add_item (7, "World map");
Map_listbox->set_int_val (7);
GLUI_Panel *loose3 = glui_window->add_panel ("");
GLUI_Rollout *ot_rollout = glui_window->add_rollout_to_panel (loose3,"Type of the Target");
GLUI_RadioGroup *ot_group = glui_window->add_radiogroup_to_panel
(ot_rollout, &radiogroup_item_id, TYPE_OF_TARGAT_RADIOGROUP, glui_callback);
glui_window->add_radiobutton_to_group( ot_group, "Incoming" );
glui_window->add_radiobutton_to_group( ot_group, "Outgoing" );
GLUI_Panel *transformation_panel = glui_window->add_panel ("Target Data");
GLUI_Panel *transformation_panel2 = glui_window->add_panel_to_panel (transformation_panel, "");
glui_window->add_separator_to_panel (transformation_panel2);
GLUI_EditText *edit0 = glui_window->add_edittext_to_panel (transformation_panel2, "Track ID", GLUI_EDITTEXT_TEXT, &ss, ID, glui_callback);
glui_window->add_separator_to_panel (transformation_panel2);
GLUI_Spinner *spinner = glui_window->add_spinner_to_panel (transformation_panel2, "Speed", GLUI_SPINNER_FLOAT, &speed, SPEED_SPINNER, glui_callback);
glui_window->add_separator_to_panel (transformation_panel2);
spinner->set_float_limits ( 0.0, 100.0 );
GLUI_EditText *edit = glui_window->add_edittext_to_panel (transformation_panel2, "Azimuth", GLUI_EDITTEXT_INT, &az, AZIMUTH_EDITTEXT_INT, glui_callback);
edit->set_int_limits ( 0, 360 );
glui_window->add_separator_to_panel (transformation_panel2);
GLUI_EditText *edit3 = glui_window->add_edittext_to_panel (transformation_panel2, "Heading", GLUI_EDITTEXT_INT, &hh, HEADING, glui_callback);
edit3->set_int_limits ( 0, 360 );
glui_window->add_separator_to_panel (transformation_panel2);
GLUI_EditText *edit1 = glui_window->add_edittext_to_panel (transformation_panel2, "Stat Range",GLUI_EDITTEXT_INT, &sr, START_RANGE, glui_callback);
edit1->set_int_limits ( 0, 75 );
glui_window->add_separator_to_panel (transformation_panel2);
GLUI_EditText *edit2 = glui_window->add_edittext_to_panel (transformation_panel2, "End Range",GLUI_EDITTEXT_INT, &er, END_RANGE, glui_callback);
edit2->set_int_limits ( 0, 75 );
glui_window->add_separator_to_panel (transformation_panel2);
GLUI_Panel *loose = glui_window->add_panel ("");
GLUI_Rollout *ot_rollout1 = glui_window->add_rollout_to_panel (loose,"Time for radar Beam Roation");
GLUI_RadioGroup *ot_group1 = glui_window->add_radiogroup_to_panel
(ot_rollout1, &radiogroup_item_id1, TIME_RADIOGROUP, glui_callback);
glui_window->add_radiobutton_to_group( ot_group1, "2 sec" );
glui_window->add_radiobutton_to_group( ot_group1, "4 sec" );
glui_window->add_radiobutton_to_group( ot_group1, "8 sec" );
GLUI_Panel *loose1 = glui_window->add_panel ("");
GLUI_Panel *cap = glui_window->add_panel_to_panel(loose1,"CAP");
glui_window->add_statictext_to_panel(cap,ash);
GLUI_Panel *op_pane2 = glui_window->add_panel ("");
glui_window->add_button_to_panel (op_pane2,"OK", OK_BUTTON, glui_callback);
glui_window->add_separator_to_panel (op_pane2);
glui_window->add_button_to_panel (op_pane2,"RESET", RESET_BUTTON, glui_callback);
glui_window->set_main_gfx_window( main_window );
}
void glui_callback (int control_id)
{
printf ("GLUI: ");
switch (control_id)
{
case MAP_LISTBOX:
printf ("Map List box item changed: ");
printf ("Item %d selected.\n", listbox_item_id);
break;
case NUMBER:
printf ("Number of the targets: %d.\n", no);
break;
case TYPE_OF_TARGAT_RADIOGROUP:
printf ("Radio Button %d selected.\n", radiogroup_item_id);
break;
case TIME_RADIOGROUP:
printf ("Radio Button %d selected.\n", radiogroup_item_id);
break;
case ID:
printf ("ID of the target\n");
break;
case SPEED_SPINNER:
printf ("Speed of the target: %f.\n", speed);
break;
case AZIMUTH_EDITTEXT_INT:
printf ("Azimuth of the target: %d.\n", az);
break;
case HEADING:
printf ("Heading of the target: %d.\n", hh);
break;
case START_RANGE:
printf ("Start Range of the target: %d.\n", sr);
break;
case END_RANGE:
printf ("Start Range of the target: %d.\n", er);
break;
case OK_BUTTON:
printf ("OK Button clicked... Exit!\n");
exit (1);
break;
case RESET_BUTTON:
printf ("RESET Button clicked... Exit!\n");
break;
}
}
void idle ()
{
glutSetWindow (main_window);
glutPostRedisplay ();
Sleep (50);
}
char* filename = "world.bmp";
void main (int argc, char **argv)
{
printf("Enter the maximum range (50km/60km/75km)\n");
scanf("%f",&max_range);
if(max_range==50 || max_range==75)
n_circles=5;
else if(max_range==60)
n_circles=6;
printf("Enter the angle 30 or 45\n");
scanf("%d",&done);
centerOnScreen ();
glutInit(&argc, argv);
glutInitWindowSize (window_width, window_height);
glutInitWindowPosition (window_x, window_y);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE);
main_window = glutCreateWindow (window_title);
if (full_screen)
glutFullScreen ();
init();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
loadTextureFromFile( filename );
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMouseFunc (mouse);
glutKeyboardFunc(keyboard) ;
glutMotionFunc (motion);
glutEntryFunc (entry);
setupGLUI ();
glutMainLoop();
}
#ifndef RGBIMAGE_DONT_USE_OPENGL
#include "GL/gl.h"
#endif
RgbImage::RgbImage( int numRows, int numCols )
{
NumRows = numRows;
NumCols = numCols;
ImagePtr = new unsigned char[NumRows*GetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld bitmap.\n",
NumRows, NumCols);
Reset();
ErrorCode = MemoryError;
}
// Zero out the image
unsigned char* c = ImagePtr;
int rowLen = GetNumBytesPerRow();
for ( int i=0; i<NumRows; i++ ) {
for ( int j=0; j<rowLen; j++ ) {
*(c++) = 0;
}
}
}
bool RgbImage::LoadBmpFile( const char* filename )
{
Reset();
FILE* infile = fopen(filename, "rb" ); // Open for reading binary data
if ( !infile ) {
fprintf(stderr, "Unable to open file: %s\n",filename);
ErrorCode = OpenError;
return false;
}
bool fileFormatOK = false;
int bChar = fgetc( infile );
int mChar = fgetc( infile );
if ( bChar=='B' && mChar=='M' ) { // If starts with "BM" for "BitMap"
skipChars( infile, 4+2+2+4+4 ); // Skip 4 fields we don't care about
NumCols = readLong( infile );
NumRows = readLong( infile );
skipChars( infile, 2 ); // Skip one field
int bitsPerPixel = readShort( infile );
skipChars( infile, 4+4+4+4+4+4 ); // Skip 6 more fields
if ( NumCols>0 && NumCols<=100000 && NumRows>0 && NumRows<=100000
&& bitsPerPixel==24 && !feof(infile) ) {
fileFormatOK = true;
}
}
if ( !fileFormatOK ) {
Reset();
ErrorCode = FileFormatError;
fprintf(stderr, "Not a valid 24-bit bitmap file: %s.\n", filename);
fclose ( infile );
return false;
}
// Allocate memory
ImagePtr = new unsigned char[NumRows*GetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld bitmap: %s.\n",
NumRows, NumCols, filename);
Reset();
ErrorCode = MemoryError;
fclose ( infile );
return false;
}
unsigned char* cPtr = ImagePtr;
for ( int i=0; i<NumRows; i++ ) {
int j;
for ( j=0; j<NumCols; j++ ) {
*(cPtr+2) = fgetc( infile ); // Blue color value
*(cPtr+1) = fgetc( infile ); // Green color value
*cPtr = fgetc( infile ); // Red color value
cPtr += 3;
}
int k=3*NumCols; // Num bytes already read
for ( ; k<GetNumBytesPerRow(); k++ ) {
fgetc( infile ); // Read and ignore padding;
*(cPtr++) = 0;
}
}
if ( feof( infile ) ) {
fprintf( stderr, "Premature end of file: %s.\n", filename );
Reset();
ErrorCode = ReadError;
fclose ( infile );
return false;
}
fclose( infile ); // Close the file
return true;
}
short RgbImage::readShort( FILE* infile )
{
// read a 16 bit integer
unsigned char lowByte, hiByte;
lowByte = fgetc(infile); // Read the low order byte (little endian form)
hiByte = fgetc(infile); // Read the high order byte
// Pack together
short ret = hiByte;
ret <<= 8;
ret |= lowByte;
return ret;
}
long RgbImage::readLong( FILE* infile )
{
// Read in 32 bit integer
unsigned char byte0, byte1, byte2, byte3;
byte0 = fgetc(infile); // Read bytes, low order to high order
byte1 = fgetc(infile);
byte2 = fgetc(infile);
byte3 = fgetc(infile);
// Pack together
long ret = byte3;
ret <<= 8;
ret |= byte2;
ret <<= 8;
ret |= byte1;
ret <<= 8;
ret |= byte0;
return ret;
}
void RgbImage::skipChars( FILE* infile, int numChars )
{
for ( int i=0; i<numChars; i++ ) {
fgetc( infile );
}
}
bool RgbImage::WriteBmpFile( const char* filename )
{
FILE* outfile = fopen( filename, "wb" ); // Open for reading binary data
if ( !outfile ) {
fprintf(stderr, "Unable to open file: %s\n", filename);
ErrorCode = OpenError;
return false;
}
fputc('B',outfile);
fputc('M',outfile);
int rowLen = GetNumBytesPerRow();
writeLong( 40+14+NumRows*rowLen, outfile ); // Length of file
writeShort( 0, outfile ); // Reserved for future use
writeShort( 0, outfile );
writeLong( 40+14, outfile ); // Offset to pixel data
writeLong( 40, outfile ); // header length
writeLong( NumCols, outfile ); // width in pixels
writeLong( NumRows, outfile ); // height in pixels (pos for bottom up)
writeShort( 1, outfile ); // number of planes
writeShort( 24, outfile ); // bits per pixel
writeLong( 0, outfile ); // no compression
writeLong( 0, outfile ); // not used if no compression
writeLong( 0, outfile ); // Pixels per meter
writeLong( 0, outfile ); // Pixels per meter
writeLong( 0, outfile ); // unused for 24 bits/pixel
writeLong( 0, outfile ); // unused for 24 bits/pixel
// Now write out the pixel data:
unsigned char* cPtr = ImagePtr;
for ( int i=0; i<NumRows; i++ ) {
// Write out i-th row's data
int j;
for ( j=0; j<NumCols; j++ ) {
fputc( *(cPtr+2), outfile); // Blue color value
fputc( *(cPtr+1), outfile); // Blue color value
fputc( *(cPtr+0), outfile); // Blue color value
cPtr+=3;
}
// Pad row to word boundary
int k=3*NumCols; // Num bytes already read
for ( ; k<GetNumBytesPerRow(); k++ ) {
fputc( 0, outfile ); // Read and ignore padding;
cPtr++;
}
}
fclose( outfile ); // Close the file
return true;
}
void RgbImage::writeLong( long data, FILE* outfile )
{
// Read in 32 bit integer
unsigned char byte0, byte1, byte2, byte3;
byte0 = (unsigned char)(data&0x000000ff); // Write bytes, low order to high order
byte1 = (unsigned char)((data>>8)&0x000000ff);
byte2 = (unsigned char)((data>>16)&0x000000ff);
byte3 = (unsigned char)((data>>24)&0x000000ff);
fputc( byte0, outfile );
fputc( byte1, outfile );
fputc( byte2, outfile );
fputc( byte3, outfile );
}
void RgbImage::writeShort( short data, FILE* outfile )
{
// Read in 32 bit integer
unsigned char byte0, byte1;
byte0 = data&0x000000ff; // Write bytes, low order to high order
byte1 = (data>>8)&0x000000ff;
fputc( byte0, outfile );
fputc( byte1, outfile );
}
void RgbImage::SetRgbPixelf( long row, long col, double red, double green, double blue )
{
SetRgbPixelc( row, col, doubleToUnsignedChar(red),
doubleToUnsignedChar(green),
doubleToUnsignedChar(blue) );
}
void RgbImage::SetRgbPixelc( long row, long col,
unsigned char red, unsigned char green, unsigned char blue )
{
assert ( row<NumRows && col<NumCols );
unsigned char* thePixel = GetRgbPixel( row, col );
*(thePixel++) = red;
*(thePixel++) = green;
*(thePixel) = blue;
}
unsigned char RgbImage::doubleToUnsignedChar( double x )
{
if ( x>=1.0 ) {
return (unsigned char)255;
}
else if ( x<=0.0 ) {
return (unsigned char)0;
}
else {
return (unsigned char)(x*255.0); // Rounds down
}
}
// Bitmap file format (24 bit/pixel form) BITMAPFILEHEADER
// Header (14 bytes)
// 2 bytes: "BM"
// 4 bytes: long int, file size
// 4 bytes: reserved (actually 2 bytes twice)
// 4 bytes: long int, offset to raster data
// Info header (40 bytes) BITMAPINFOHEADER
// 4 bytes: long int, size of info header (=40)
// 4 bytes: long int, bitmap width in pixels
// 4 bytes: long int, bitmap height in pixels
// 2 bytes: short int, number of planes (=1)
// 2 bytes: short int, bits per pixel
// 4 bytes: long int, type of compression (not applicable to 24 bits/pixel)
// 4 bytes: long int, image size (not used unless compression is used)
// 4 bytes: long int, x pixels per meter
// 4 bytes: long int, y pixels per meter
// 4 bytes: colors used (not applicable to 24 bit color)
// 4 bytes: colors important (not applicable to 24 bit color)
// "long int" really means "unsigned long int"
// Pixel data: 3 bytes per pixel: RGB values (in reverse order).
// Rows padded to multiples of four.
#ifndef RGBIMAGE_DONT_USE_OPENGL
bool RgbImage::LoadFromOpenglBuffer() // Load the bitmap from the current OpenGL buffer
{
int viewportData[4];
glGetIntegerv( GL_VIEWPORT, viewportData );
int& vWidth = viewportData[2];
int& vHeight = viewportData[3];
if ( ImagePtr==0 ) { // If no memory allocated
NumRows = vHeight;
NumCols = vWidth;
ImagePtr = new unsigned char[NumRows*GetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld buffer.\n",
NumRows, NumCols);
Reset();
ErrorCode = MemoryError;
return false;
}
}
assert ( vWidth>=NumCols && vHeight>=NumRows );
int oldGlRowLen;
if ( vWidth>=NumCols ) {
glGetIntegerv( GL_UNPACK_ROW_LENGTH, &oldGlRowLen );
glPixelStorei( GL_UNPACK_ROW_LENGTH, NumCols );
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
// Get the frame buffer data.
glReadPixels( 0, 0, NumCols, NumRows, GL_RGB, GL_UNSIGNED_BYTE, ImagePtr);
// Restore the row length in glPixelStorei (really ought to restore alignment too).
if ( vWidth>=NumCols ) {
glPixelStorei( GL_UNPACK_ROW_LENGTH, oldGlRowLen );
}
return true;
}
#endif // RGBIMAGE_DONT_USE_OPENGL
pavana
04-21-2010, 09:03 AM
hmmmm iv debugged.. but not getting.k ll post ma program.
#include<glew.h>
#include<wglew.h>
# include <GL/glut.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
static GLfloat spin = 360.0 ;
static float r_min=1 , r_max=8 ;
# define dtheta 0.1
GLuint color_tex;
GLuint fb;
GLuint depth_rb;
int width=512;
int height=512;
void init(void)
{
glShadeModel(GL_FLAT) ;
glClearColor(0.0f, 0.0f, 0.2f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glViewport(0,0,800,600);
glGenFramebuffersEXT(1, &fb);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glGenRenderbuffersEXT(1, &depth_rb);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 256, 256);
glGenTextures(1, &color_tex);
glBindTexture(GL_TEXTURE_2D,color_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color_tex, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);
GLenum status;
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
exit(1);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
void display(void)
{
glColor3f(1.0 , 1.0 , 1.0) ;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,512,512);
glColor4f(0.0 , 1.0 , 0.0, 0.1) ;
glBegin(GL_POLYGON) ;
glVertex2f(0.0 , 0.0) ;
glVertex2f(r_max*cos(0.0) , r_max*sin(0.0)) ;
glVertex2f(r_max*cos(dtheta) , r_max*sin(dtheta)) ;
glEnd() ;
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glClearColor(0.0f, 0.0f, 0.2f, 0.5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,color_tex);
glutSwapBuffers() ;
}
void reshape(int w , int h)
{
glViewport(0 , 0 , (GLsizei)w , (GLsizei)h) ;
glMatrixMode(GL_PROJECTION) ;
glLoadIdentity() ;
glOrtho(-r_max , r_max , -r_max , r_max , -1.0 , 1.0) ;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
void ShutDown(void)
{
glDeleteFramebuffersEXT(1, &fb);
glDeleteRenderbuffersEXT(1, &depth_rb);
glDeleteTextures(1,&color_tex);
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 27: // When Escape Is Pressed...
ShutDown();
exit(0); // Exit The Program
break;
default:
break;
}
}
int main(int argc , char* argv[])
{
glutInit(&argc , argv) ;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) ;
glutInitWindowSize(750 , 750) ;
glutInitWindowPosition(0,0) ;
glutCreateWindow("fbo") ;
init() ;
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard) ;
glutMainLoop() ;
return 0 ;
}
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.