layering

helllo… is there anybody who can help me in creating multiple graphics layers… please help out…

Have you tried searching this forum for a similar problem?

http://www.opengl.org/discussion_boards/…true#Post274217

nope… please tell me the syntax to create layers…

Lots of ways. Depends on what you need. Please define more about your problem. Surface decals? Depth layers? Transparency layers? 3D layers? 2D layers? Sequential rendering of multiple layers? Simultaneous rendering of multiple layers? Pre-defined geometry? Dynamically-generated geometry? …

Give us an example.

hello…
i don know the actual concept of layerin… hmmm… i have many things to display… like at the background i want to put a google map and above that i need to write some text and after that i need to point out some regions… all these should be implemented seperateley so that i should get a non erasable screen…so i think i neeed simultaneous rendering of multiple layers. like i need to implement some overlays and underlays.

Thank u.

You would render each layer to a RTT (render to texture) and then you apply the texture to a quad.
RTT code examples are here
http://www.opengl.org/wiki/GL_EXT_framebuffer_object

Those are short examples. They are not there to teach general programming or concepts.

Thank u…
Ll try out this.

sorry… as i told ive many things that are be displayed, if i use this technique it will be a hectic… so using wgl functions will be easy… there in pixel format descriptor we can easily set the overlays and underlays.M thinkin of creatin many layer planes with different intensities… can u help out…

Thank u…

Try that wgl stuff if you want but I think it is considered ancient history by now. What I gave (GL_EXT_framebuffer_object) FBO is the modern way to do what you want.
Or just forget overlay planes and render directly to the backbuffer. Why do you want overlays anyway? video cards are very fast at rendering millions of pixels and chugging on vertices.

actually iv gotta project to simulate radar display… they ve specified us to use the concept of layering…so… we dont have any other options… please send me a sample program to create atleast two layers…

Simple.

  1. Make a list of the stuff to draw in each layer
  2. Clear the screen
  3. Draw back layer
  4. Draw next closer layer
  5. Draw next closer layer

    n. Swap buffers

hello good evenin…
u meant i should swap the buffers after displayin each layer…?
I tried this but the screen is too much flickering

Of course Dark Photon did not meant that, it would flicker !
Only swapbuffers once everything has been drawn.
The steps 1-n must be done for each frame, even if some layers did not change, they still have to be redrawn.

doi this is enough…? no need to use wgl stuffs…? like creating layer contexts, setting up the pixel format descriptor…

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

“);
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.

Sorry, throwing a bunch of code at us alone isn’t gonna cut it. You have to actually state what your problem is, specifically :wink:

And the code doesn’t even compile as it’s not the complete program.

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)&gt;&gt;2)&lt;&lt;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 = rowGetNumBytesPerRow() + 3col;
ret += i;
return ret;
}

inline unsigned char* RgbImage::GetRgbPixel( long row, long col )
{
assert ( row<NumRows && col<NumCols );
unsigned char* ret = ImagePtr;
long i = rowGetNumBytesPerRow() + 3col;
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 = 2PIi/100 ;
glVertex2f(rcos(angle) , rsin(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 &lt;= 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&lt;=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&lt;=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.

", 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)…
");
glutIdleFunc(spinDisplay) ;
break;

			case GLUT_UP:
				printf ("Mouse Left Button Released (Up)...

");
break;
}

		break;

	case GLUT_MIDDLE_BUTTON:
		switch (state)
		{
			case GLUT_DOWN:
				printf ("Mouse Middle Button Pressed (Down)...

");
break;

			case GLUT_UP:
				printf ("Mouse Middle Button Released (Up)...

");
break;
}

		break;

	case GLUT_RIGHT_BUTTON:
		
		switch (state)
		{
			case GLUT_DOWN:
				printf ("Mouse Right Button Pressed (Down)...

");
glutIdleFunc(NULL) ;
break;

			case GLUT_UP:
				printf ("Mouse Right Button Released (Up)...

");
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 &gt; 0.0) 
			inr = inr - 0.1 ;
	break ;
}

}

void motion (int x, int y)
{
printf ("GLUT: ");
printf ("Mouse Drag Position: %d, %d.
", x, y);
}

void entry (int state)
{
printf ("GLUT: ");
if (state == GLUT_ENTERED)
printf ("Mouse entered GLUT window…
");

else if (state == GLUT_LEFT)
	printf ("Mouse left GLUT window...

");
}

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-&gt;add_panel ("Number of Targets");

GLUI_EditText *ttt = glui_window-&gt;add_edittext_to_panel (op, "number", GLUI_EDITTEXT_INT, &no, NUMBER, glui_callback);
ttt-&gt;set_int_limits ( 0, 10 );

GLUI_Panel *op_panel = glui_window-&gt;add_panel ("Geographical Area");

glui_window-&gt;add_separator_to_panel (op_panel);

GLUI_Listbox *Map_listbox = glui_window-&gt;add_listbox_to_panel (op_panel, 
								"map", &listbox_item_id,	MAP_LISTBOX, glui_callback);
glui_window-&gt;add_separator_to_panel (op_panel);

Map_listbox-&gt;add_item (1, "Mysore");
Map_listbox-&gt;add_item (2, "Banglore");
Map_listbox-&gt;add_item (3, "Delhi");
Map_listbox-&gt;add_item (4, "Hydrabad");
Map_listbox-&gt;add_item (5, "Mumbai");
Map_listbox-&gt;add_item (6, "India map");
Map_listbox-&gt;add_item (7, "World map");
Map_listbox-&gt;set_int_val (7);

GLUI_Panel *loose3 = glui_window-&gt;add_panel ("");

GLUI_Rollout *ot_rollout = glui_window-&gt;add_rollout_to_panel (loose3,"Type of the Target");

GLUI_RadioGroup *ot_group = glui_window-&gt;add_radiogroup_to_panel 
							(ot_rollout, &radiogroup_item_id, TYPE_OF_TARGAT_RADIOGROUP, glui_callback);

glui_window-&gt;add_radiobutton_to_group( ot_group, "Incoming" );
glui_window-&gt;add_radiobutton_to_group( ot_group, "Outgoing" );

GLUI_Panel *transformation_panel = glui_window-&gt;add_panel ("Target Data");

GLUI_Panel *transformation_panel2 = glui_window-&gt;add_panel_to_panel (transformation_panel, "");

glui_window-&gt;add_separator_to_panel (transformation_panel2);

GLUI_EditText *edit0 = glui_window-&gt;add_edittext_to_panel (transformation_panel2, "Track ID", GLUI_EDITTEXT_TEXT, &ss, ID, glui_callback);

glui_window-&gt;add_separator_to_panel (transformation_panel2);

GLUI_Spinner *spinner = glui_window-&gt;add_spinner_to_panel (transformation_panel2, "Speed", GLUI_SPINNER_FLOAT, &speed, SPEED_SPINNER, glui_callback);
glui_window-&gt;add_separator_to_panel (transformation_panel2);
spinner-&gt;set_float_limits ( 0.0, 100.0 );

GLUI_EditText *edit = glui_window-&gt;add_edittext_to_panel (transformation_panel2, "Azimuth", GLUI_EDITTEXT_INT, &az, AZIMUTH_EDITTEXT_INT, glui_callback);
edit-&gt;set_int_limits ( 0, 360 );
glui_window-&gt;add_separator_to_panel (transformation_panel2);

GLUI_EditText *edit3 = glui_window-&gt;add_edittext_to_panel (transformation_panel2, "Heading", GLUI_EDITTEXT_INT, &hh, HEADING, glui_callback);
edit3-&gt;set_int_limits ( 0, 360 );
glui_window-&gt;add_separator_to_panel (transformation_panel2);
GLUI_EditText *edit1 = glui_window-&gt;add_edittext_to_panel (transformation_panel2, "Stat Range",GLUI_EDITTEXT_INT, &sr, START_RANGE, glui_callback);
edit1-&gt;set_int_limits ( 0, 75 );
glui_window-&gt;add_separator_to_panel (transformation_panel2);
GLUI_EditText *edit2 = glui_window-&gt;add_edittext_to_panel (transformation_panel2, "End Range",GLUI_EDITTEXT_INT, &er, END_RANGE, glui_callback);
edit2-&gt;set_int_limits ( 0, 75 );
glui_window-&gt;add_separator_to_panel (transformation_panel2);

GLUI_Panel *loose = glui_window-&gt;add_panel ("");

GLUI_Rollout *ot_rollout1 = glui_window-&gt;add_rollout_to_panel (loose,"Time for radar Beam Roation");

GLUI_RadioGroup *ot_group1 = glui_window-&gt;add_radiogroup_to_panel 
							(ot_rollout1, &radiogroup_item_id1, TIME_RADIOGROUP, glui_callback);

glui_window-&gt;add_radiobutton_to_group( ot_group1, "2 sec" );
glui_window-&gt;add_radiobutton_to_group( ot_group1, "4 sec" );
glui_window-&gt;add_radiobutton_to_group( ot_group1, "8 sec" );

GLUI_Panel *loose1 = glui_window-&gt;add_panel ("");

GLUI_Panel *cap = glui_window-&gt;add_panel_to_panel(loose1,"CAP");

glui_window-&gt;add_statictext_to_panel(cap,ash);

GLUI_Panel *op_pane2 = glui_window-&gt;add_panel ("");

glui_window-&gt;add_button_to_panel  (op_pane2,"OK", OK_BUTTON, glui_callback);

glui_window-&gt;add_separator_to_panel (op_pane2);

glui_window-&gt;add_button_to_panel  (op_pane2,"RESET", RESET_BUTTON, glui_callback);

glui_window-&gt;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.

", listbox_item_id);
break;

case NUMBER:
	printf ("Number of the targets: %d.

", no);
break;

case TYPE_OF_TARGAT_RADIOGROUP:
	printf ("Radio Button %d selected.

", radiogroup_item_id);
break;

case TIME_RADIOGROUP:
	printf ("Radio Button %d selected.

", radiogroup_item_id);
break;

case ID:
	printf ("ID of the target

");
break;

case SPEED_SPINNER:
	printf ("Speed of the target: %f.

", speed);
break;

case AZIMUTH_EDITTEXT_INT:
	printf ("Azimuth of the target: %d.

", az);
break;

case HEADING:
	printf ("Heading of the target: %d.

", hh);
break;

case START_RANGE:
	printf ("Start Range of the target: %d.

", sr);
break;

case END_RANGE:
	printf ("Start Range of the target: %d.

", er);
break;

case OK_BUTTON:
	printf ("OK Button clicked... Exit!

");
exit (1);
break;

case RESET_BUTTON:
	printf ("RESET Button clicked... Exit!

");
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)
“);
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

“);
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[NumRowsGetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld bitmap.
",
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
",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&gt;0 && NumCols&lt;=100000 && NumRows&gt;0 && NumRows&lt;=100000  
		&& bitsPerPixel==24 && !feof(infile) ) {
		fileFormatOK = true;
	}
}
if ( !fileFormatOK ) {
	Reset();
	ErrorCode = FileFormatError;
	fprintf(stderr, "Not a valid 24-bit bitmap file: %s.

", 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.

",
NumRows, NumCols, filename);
Reset();
ErrorCode = MemoryError;
fclose ( infile );
return false;
}

unsigned char* cPtr = ImagePtr;
for ( int i=0; i&lt;NumRows; i++ ) {
	int j;
	for ( j=0; j&lt;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&lt;GetNumBytesPerRow(); k++ ) {
		fgetc( infile );				// Read and ignore padding;
		*(cPtr++) = 0;
	}
}
if ( feof( infile ) ) {
	fprintf( stderr, "Premature end of file: %s.

", 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 &lt;&lt;= 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 &lt;&lt;= 8;
ret |= byte2;
ret &lt;&lt;= 8;
ret |= byte1;
ret &lt;&lt;= 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
", 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&lt;NumRows; i++ ) {
	// Write out i-th row's data
	int j;
	for ( j=0; j&lt;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&lt;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.

",
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&gt;=NumCols ) {
	glPixelStorei( GL_UNPACK_ROW_LENGTH, oldGlRowLen );
}	
return true;

}

#endif // RGBIMAGE_DONT_USE_OPENGL

Ok, sure. We got the general concept. What we don’t have is any specifics.

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.

Ok. You’re just talking about drawing these 2D annotations on top of the base map in a specific order. Seems pretty simple.

iv gone thru the wgl stuffs but m not gettin how to go with it…

You still didn’t state what “specifically” isn’t working. Just saying “it’s broke; what’s wrong?” doesn’t cut it. This isn’t a “fix my program for me” forum. State:

[ol][li] What “specifically” is your technical approach (more detailed than the general concept outlined above), [] what “specifically” is not working properly, and [] what “specifically” surprises you about the behavior you’re seeing compared to what you thought should happen.[/ol][/li]Please check out Eric Raymond’s FAQ on Asking Questions, in particular the Be precise and informative about your problem section.

For instance, why are you so convinced there are “wgl stuffs” involved in the solution, to whatever your specific problem is?

hmmm… k.
when m trying to rotate the triangle at 7.5rpm,it is rotating at a slower rate than expected. so i thot of rendering each of my stuffs as seperate layers… i gottu know that using wglCreateLayerContext function we can create multiple layers. m tryin out that,but m getting only the upper most layer displayed. is that i need to setup the pixel format descriptor for each of the layer…? if so wot fields need to be changed…?

Thank u.

So rotate once every 8 seconds, as sort of a “please wait” indicator. Rendering the triangle should be super-fast, so that suggests something about the other layers you’re rendering is slow, or your method for determining what rotation to display the triangle at is geared toward FPS rather than “clock time”. Use the latter and you can get that 7.5 RPM you want, though it might be choppy if your updates aren’t very frequent.

so i thot of rendering each of my stuffs as seperate layers… wglCreateLayerContext…

Wait. So something about your rendering code is slow/non-optimal, you haven’t figured out what it is yet, so you’re going to try rendering your spinning “please wait” triangle to “overlay planes” which are not universally available to try to avoid redrawing the underlying layers?

Ok, at least now I understand what you’re calling “layers” (layers means lots of things, and this is not one of the more common ones; more commonly, these things are called “overlay planes”).

Yes, if you want to go that route, that’ll work given that overlay planes are available and enabled on your platform.

But a solution that won’t lock you into not-necessarily-available overlay planes is to simply render your other layers (except for your spinning please-wait triangle) onto an off-screen renderbuffer or texture using a “framebuffer object” (aka FBO). Then when it comes time to rerender your window, you simply copy from that renderbuffer or texture to the system (window) framebuffer, and then draw your spinning triangle please-wait logo on top.

You only re-render your off-screen framebuffer when the map data or one of the other layers changes. And you can re-use each one of this renders many times to make your “please wait” gizmo rotate faster or more fluidly.

For instance:

  • Re-render off-screen FBO with map/etc.
  • Re-render window (copy off-screen FBO to window, draw triangle)
  • Re-render window (copy off-screen FBO to window, draw triangle)
  • Re-render window (copy off-screen FBO to window, draw triangle)
  • Map update received, so…
  • Re-render off-screen FBO
  • Re-render window
  • Re-render window

As you can see, with this we don’t have to “regenerate” the underlying layers from-scratch every time we draw the window. We just copy the last rendered contents onto the window which is super-fast/cheap.