PDA

View Full Version : Need Once Again Help :)



Ryan4441
01-06-2016, 01:27 AM
Respected SIr / Maam :)
After Running the given Code on Linux,the following issues Arises.kindly Give solution for these :)
1: after compiling,the executed window is transparent

this is the code ==>
#include <GL/glut.h>
#include <math.h>
void Soccer_Field (void)
{
float x, y, ang, radius = 0.05;
static float RAD_DEG = 57.296;

glBegin (GL_QUADS);
glColor3f (0.20, 0.60, 0.20); // GreenYard
glVertex2f (0.10, 0.10); glVertex2f (0.90, 0.10);
glVertex2f (0.90, 0.90); glVertex2f (0.10, 0.90);
glColor3f (1.0, 1.0, 1.0);
glVertex2f (0.90, 0.35); glVertex2f (0.83, 0.35); // Inner White Quad - Right
glVertex2f (0.83, 0.65); glVertex2f (0.90, 0.65);
glVertex2f (0.10, 0.35); glVertex2f (0.17, 0.35); // Inner White Quad - Left
glVertex2f (0.17, 0.65); glVertex2f (0.10, 0.65);
glEnd ();

glColor3f (0.0, 0.0, 0.0); // Change color to black

glBegin (GL_LINES);
glVertex2f (0.50, 0.10); glVertex2f (0.50, 0.90); // Mid Line

// Left side of the Ground
glVertex2f (0.25, 0.25); glVertex2f (0.25, 0.75); // Goal keeper front line
glVertex2f (0.10, 0.75); glVertex2f (0.25, 0.75); // Goal keeper left line
glVertex2f (0.10, 0.25); glVertex2f (0.25, 0.25); // Goal keeper right line

// Right Side of the Ground
glVertex2f (0.75, 0.25); glVertex2f (0.75, 0.75); // Goal keeper front line
glVertex2f (0.75, 0.25); glVertex2f (0.90, 0.25); // Goal keeper left Line
glVertex2f (0.75, 0.75); glVertex2f (0.90, 0.75); // Goal keeper right line
glEnd ();

glBegin (GL_LINE_LOOP); // Circle at center of field
for (ang = 0.0; ang < 360.0; ang += 10.0) {
x = radius * cos(ang/RAD_DEG) + 1.0;
y = radius * sin(ang/RAD_DEG) + 0.5;
glVertex2f (x/2.0, y);
}
glEnd ();
}
void Initialize()
{
glClearColor(0.60, 0.40, 0.12, 0.20);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100, 100, -50, 50, -1, 1);
}
int main(int iArgc, char** cppArgv)
{
glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(900, 450);
glutInitWindowPosition(200, 200);
glutCreateWindow("Football Ground OpenGL");
Initialize();
glutDisplayFunc(Soccer_Field);
glutMainLoop();
return 0;
}

Carmine
01-06-2016, 12:24 PM
Try adding 'glClear(GL_COLOR_BUFFER_BIT)' to the top of the 'Soccer_Field' routine.

Also, change the glOrtho parameters back to what you had before.

Ryan4441
01-08-2016, 10:03 PM
Sir it worked fine by adding glClear(GL_COLOR_BUFFER_BIT); <3 awesome thank you so much help <3 May God Help and bless you <3

hamzabinjaved
01-10-2016, 08:16 AM
sir that is true method to create circle in openGl but also give a short lecture on creating circle .if i want to create a circle on an other place then what i should do .i am confused about position/vertex of circle that how i change the place of circle and also change the size of circle thanks.:)
please help me out .......

Carmine
01-10-2016, 05:20 PM
I suggest you experiment with the circle routine I posted. Try changing some of the numbers to see what happens. The size, position, and shape of the circle can all be controlled by changing those numbers.