radiobutton

Heelo ;

My question is ; how can I connect a radio-button with a drawapplication

The drawapplication is implemented in c and UNIX and GLUT with a glutMainLoop and so on.

I have been given some code with the buttons and need to know how to connect it with the application.

I meen when the button is clicked upon how is that normally handled in c / glut?

The buttons are made in the setupWindow by proj1.

Kr // OG
</font><blockquote><font size=“1” face=“Verdana, Arial”>code:</font><hr /><pre style=“font-size:x-small; font-family: monospace;”>#include <stdio.h>
#include <stdlib.h>

#include <GL/gl.h>
#include <GL/glut.h>

#include “givengui.h”

#include <math.h>

using namespace std;
bool lbuttonDown = false;

void antiaLine(int x0, int y0, int xe, int ye) ;
void bresLine(int x0, int y0, int xe, int ye) ;
void bresTest(int x1, int x2) ;
bool init() ;
void midCircle(int xc, int yc , int r) ;
void mouse(int button, int state, int x, int y) ;
int testSlope(int dx, int dy) ;

/******** Callbacks called by the GUI ********/
void primitiveMode(int primitive)
{
printf("Primitive %s selected
", primitive == LINE ? “line” : “circle”);
}

void antialias(int doAA)
{
printf("Anti-aliasing %s
", doAA ? “enabled” : “disabled”);
}

void clearScreen()
{
printf("Clear screen
");
}

void circleMode(int mode, int segments)
{
if(mode == MIDPOINT)
printf("Circle mode set to midpoint
");
else
printf("Circle mode set to polygon with %d segments
", segments);
}
/********* End GUI callbacks *********/

/********* GLUT callbacks ***********/

//Displays antialiased line
void antiaLine(int x0, int y0, int xe, int ye)
{
int x = x0 ;
int y = y0 ;
//Antar här att linjen har pos lutning mä ett
int dx = xe - x0 ;
//Obs världen är ju upp&ner
int dy = y0 - ye ;

    int twoDy = 2*dy ;

int sub = twoDy - 2*dx ;


//pk in literature...
int decP = twoDy - dx ;
int k = 0 ;

glBegin(GL_POINTS);
	glColor3f(0, 0, 0);
for(k = 0 ; k &lt; dx ; k++)
{
	if (decP &lt; 0)
	{
		x = x + 1 ;
		y = y ;
		
		decP = decP + twoDy ;
		
		//printf("%dAlltså kommer hit..", decP) ;
	} else 
	{
		x = x + 1 ;
		//Obs världen är ju upp&ner
		y = y - 1 ;
		decP = decP + sub ;
	}
	glVertex2i(x, y);

}
	glEnd();
 	glFlush();

}

//Displays a line calculated with Bresenham.
void bresLine(int x0, int y0, int xe, int ye)
{

int x = x0 ;
int y = y0 ;
//Antar här att linjen har pos lutning mä ett
int dx = xe - x0 ;
//Obs världen är ju upp&ner 
int dy = y0 - ye ;
 ///if (testSlope(dx, dy) == 1)
    int twoDy = 2*dy ;

int sub = twoDy - 2*dx ;


//pk in literature...
int decP = twoDy - dx ;
int k = 0 ;

glBegin(GL_POINTS);
	glColor3f(0, 0, 0);
for(k = 0 ; k &lt; dx ; k++)
{
	if (decP &lt; 0)
	{
		x = x + 1 ;
		y = y ;
		
		decP = decP + twoDy ;
		
		//printf("%dAlltså kommer hit..", decP) ;
	} else 
	{
		x = x + 1 ;
		//Obs världen är ju upp&ner
		y = y - 1 ;
		decP = decP + sub ;
	}
	glVertex2i(x, y);

}
	glEnd();
 	glFlush();

}

//Displays a steep line calculated with Bresenham.
void bresLineSteep(int x0, int y0, int xe, int ye)
{

int x = x0 ;
int y = y0 ;
//Antar här att linjen har pos lutning mä ett
int dx = xe - x0 ;
//Obs världen är ju upp&ner 
int dy = y0 - ye ;
//if (testSlope(dx, dy) == 0)
//{ }
    int twoDx = 2*dx ;

int sub = twoDx - 2*dy ;


//pk in literature...
int decP = twoDx - dy ;
int k = 0 ;

glBegin(GL_POINTS);
	glColor3f(0, 1.0, 0);
for(k = 0 ; k &lt; dy ; k++)
{
	if (decP &lt; 0)
	{
		y = y + 1 ;
		x = x ;
		
		decP = decP + twoDx ;
		
		//printf("%dAlltså kommer hit..", decP) ;
	} else 
	{
		y = y + 1 ;
		//Obs världen är ju upp&ner
		x = x - 1 ;
		decP = decP + sub ;
	}
	glVertex2i(x, y);

}
	glEnd();
 	glFlush();

}

void bresTest(int x1, int x2)
{
int k = 0 ;

glBegin(GL_POINTS);
	glColor3f(0, 0, 0);
for(k = x1 ; k &lt; x2 ; k++)
{
	glVertex2i(k, 24);
}
	glEnd();
 	glFlush();

}

void display()
{
/* Draw a grid on the screen */
int x, y, w, h;

w = glutGet(GLUT_WINDOW_WIDTH);
h = glutGet(GLUT_WINDOW_HEIGHT);

/* Clear the screen */
glClear(GL_COLOR_BUFFER_BIT);

/* Begin drawing points */
glBegin(GL_POINTS);
/* Set color to light grey */
glColor3f(0.7, 0.7, 0.7);
/* Loop over all points and set those that are on a multiple of five in
   either coordinate to grey, this will give a 5x5 grid */
for(x = 0; x &lt; w; x++)
    for(y = 0; y &lt; h; y++)
        if(x % 5 == 0

That code is spectacularly bad, it draws lines by plotting points and a software algorithm.

To use this you use state information to draw the radio in the draw callback, The state information is updated elsewhere in another input callback. Input to the radio button should use the mouse motion and click events & test bounds etc to tetermine the correct course of action. Mapping screenspace mouse x,y to GUI x,y requires using the window dimensions viewport and projection information. You can eliminate this problem by mapping the viewport to the entire window and setting up an ortho projection of exactly window dimensions just prior to drawing the GUI, but there are several other approaches.

There’s not much point in going into more detail than that, you should be able to figure this out if you have a rudimentary understanding of GLUT and of the GUI code you’re grafting in there. There’s way too much code missing and the comments are self explanatory, function names like “display()” should be a bit of a hint.