PDA

View Full Version : I REALLY NEED HELP IN YHE CLIPPING



MOON-GIRL
12-23-2002, 04:39 AM
HI

I want implement code for clipping the upper left quarter of sphere
i meane disable only the upper left of the sphear
i don't how i can do that

i write this code but this code dont work as what i want http://www.opengl.org/discussion_boards/ubb/frown.gif http://www.opengl.org/discussion_boards/ubb/frown.gif

any body can help me??

#include <GL/glut.h>

float x,y,x1,y1;
//GLdouble eqn[4];
//GLdouble eqn2[4];
//GLdouble eqn3[4];

void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glShadeModel(GL_FLAT);
}

void display(void)
{
//GLdouble eqn[4]={0.0,1.0,0.0,0.0};
GLdouble eqn[4]={x,y,0.0,0.0};
GLdouble eqn1[4]={x1,y1,0.0,0.0};

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glPushMatrix();
glTranslatef(0.0,0.0,-5.0);


/* clip lower half --y<0 */
glClipPlane(GL_CLIP_PLANE0,eqn);
glEnable(GL_CLIP_PLANE0);

glClipPlane(GL_CLIP_PLANE1,eqn1);
glEnable(GL_CLIP_PLANE1);


glRotatef(90.0,1.0,0.0,0.0);
glutWireSphere(1.0,20,16);
glPopMatrix();
glFlush();
}

void reshape(int w,int h)
{
glViewport(0,0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,(GLfloat) w / (GLfloat) h,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
}
//----------------------------------------
void clip (int selection)
{
switch (selection)
{
case 1:
//clip with plane x=y
x=1.0;
y=1.0;
x1=0.0;
y1=0.0;
break;
case 2:
//clip the upper right quarter
x=1.0;
y=0.0;
x1=0.0;
y1=1.0;
break;
case 3:
//clip the upper lift quarter
x=-1.0;
y=0.0;
x1=0.0;
y1=1.0;

break;
case 4:
x=0.0;
y=0.0;
x1=0.0;
y1=0.0;
break;
case 0:exit(0);
}
}
//------------------------------------------
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
//main menu
glutCreateMenu(clip);
glutAddMenuEntry("clip x=y.",1);
glutAddMenuEntry("clip the upper right quarter.",2);
glutAddMenuEntry("clip the upper left quarter .",3);
glutAddMenuEntry("Disable any clippung",4);
glutAddMenuEntry("Quit",0);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

Stack Overflow
12-23-2002, 10:27 AM
Hope this helps:

#include <GL/glut.h>

float x, y, x1, y1;

void init( void ) {
glClearColor( 1.0, 1.0, 1.0, 0.0 );
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
}

void display( void ) {
GLdouble eqn[4] = { x,y, 0.0, 0.0 };
GLdouble eqn1[4] = { x1, y1, 0.0, 0.0 };

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 1.0, 0.0, 0.0 );
glPushMatrix();
glTranslatef( 0.0, 0.0, -5.0 );

/* clip lower half --y<0 */
glClipPlane( GL_CLIP_PLANE0, eqn );
glEnable( GL_CLIP_PLANE0 );

glClipPlane( GL_CLIP_PLANE1, eqn1 );
glEnable( GL_CLIP_PLANE1 );


glRotatef( 90.0, 1.0, 0.0, 0.0 );
glutWireSphere( 1.0, 20, 16 );
glPopMatrix();
glFlush();
glutSwapBuffers();
}

void reshape( int w,int h ) {
if( h == 0 )
h = 1;

float ratio = 1.0 * w / h;

glMatrixMode( GL_PROJECTION );

glLoadIdentity();

glViewport( 0, 0, w, h );

gluPerspective( 45, ratio, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
//----------------------------------------
void clip ( int selection ) {
switch ( selection ) {
case 1:
//clip with plane x=y
x = 1.0;
y = 1.0;
x1 = 0.0;
y1 = 0.0;
glutPostRedisplay();
break;

case 2:
//clip the upper right quarter
x = 1.0;
y = 0.0;
x1 = 0.0;
y1 = 1.0;
glutPostRedisplay();
break;

case 3:
//clip the upper lift quarter
x = -1.0;
y = 0.0;
x1 = 0.0;
y1 = 1.0;
glutPostRedisplay();
break;

case 4:
x = 0.0;
y = 0.0;
x1 = 0.0;
y1 = 0.0;
glutPostRedisplay();
break;
case 0:
exit(0);
}
}
//------------------------------------------
int main( int argc,char** argv ) {
glutInit( &argc, argv );
glutInitWindowPosition( 100, 100 );
glutInitWindowSize( 500, 500 );
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
glutCreateWindow( argv[0] );
init();
glutReshapeFunc( reshape );
glutDisplayFunc( display );
//main menu
glutCreateMenu( clip );
glutAddMenuEntry( "clip x=y.", 1 );
glutAddMenuEntry( "clip the upper right quarter.", 2 );
glutAddMenuEntry( "clip the upper left quarter .", 3 );
glutAddMenuEntry( "Disable any clipping", 4);
glutAddMenuEntry( "Quit", 0);
glutAttachMenu( GLUT_RIGHT_BUTTON );
glutMainLoop();
return 0;
}

MOON-GIRL
12-23-2002, 12:43 PM
HI

THNAK YOU

BUT YOUR CODE DO EXACTLY WHAT MY CODE DO http://www.opengl.org/discussion_boards/ubb/frown.gif


I WANT CLIP UPPER LEFT QARTER

I mean disable left upper quarter and show the sphear with the out left upper quarter


best regards
Moon_Girl

Stack Overflow
12-23-2002, 12:49 PM
I'll see what I can do!!! http://www.opengl.org/discussion_boards/ubb/smile.gif

MOON-GIRL
12-23-2002, 02:07 PM
THANK YOU VERY MUCH http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif


I well wait you

best regards
Moon_Girl

Stack Overflow
12-23-2002, 02:34 PM
I have tried for the past two hours and haven't figured out a way. I tried creating two Spheres and overlapping them, but that still didn't work. My best suggestion is to use GL_QUADS and try to simulate clipping (when really not clipping). For example, creating different QUADS, and then when the entry selection has been changed:
1. to erase the background
2. then load the other QUAD
(which is just an idea).

I'm sorry, but I really tried.

- VC6-OGL

[This message has been edited by VC6-OGL (edited 12-23-2002).]

[This message has been edited by VC6-OGL (edited 12-23-2002).]

Deniz
12-23-2002, 03:31 PM
hmm... MOON-GIRL i would like to ask you what you think about openGL programming..

Is it hard to learn?
How long did it take for you to learn
everything you need to do whatever you can do right now?? and what did you have to learn??

I would be very pleased if you could answer my questions.. http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif

MOON-GIRL
12-24-2002, 07:54 AM
HI


THANK YOU http://www.muslimwomen.org/rosa.gif

I THINK DRAW RCTINGLE BUT THE REALLY PROBLEM WITH ME ITS WORK WITH 3D BECUASE THIS IS FIRST PROGRAM FOR ME IN 3D

BUT I WELL TRY READ IN THIS AND APPLIYED YOUR IDEA
===================
i saw your profile and your Interests: Game Programming

I try design code for ( x /o ) games
but is very simple
can I send it for you
and tell me if my idea is good or so bad http://www.opengl.org/discussion_boards/ubb/biggrin.gif



WELCOME Deniz http://www.opengl.org/discussion_boards/ubb/smile.gif

1)IN FACT I very beginer in opengl but i see its not hard

for me becuase i have some knowldge in c++ and c


2) i begin learn opengl befor 2 months but to learn everythings comes from bracticing not from studying
i use some book and some sits

3)MY knowldge until now in 2D if i learn it very good i try learn 3d
but i found some example in 3d and i try change in it and i see what is happend

i want my answers help you http://www.opengl.org/discussion_boards/ubb/smile.gif

but

seek understand and it well be understoooooooooood http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif


best regards
Moon_Girl http://www.opengl.org/discussion_boards/ubb/smile.gif


[This message has been edited by MOON-GIRL (edited 12-24-2002).]

Stack Overflow
12-24-2002, 08:02 AM
Sure, no problem.

- VC6-OGL

Stack Overflow
12-24-2002, 10:20 AM
Your (x/o) Program is very nice. I saw that if you lose it says you "lose" and if you win you "win" and if you tie the game it says nothing but that can always be changeable, but so far it is a very nice code/game. You are on the right track.

Your idea is GREAT!!!

I'll see if I can change that resize problem.

Good Luck. http://www.opengl.org/discussion_boards/ubb/smile.gif

- VC6-OGL

[This message has been edited by VC6-OGL (edited 12-24-2002).]

Stack Overflow
12-24-2002, 10:50 AM
I tried, but no luck. I believe it is the way you are programming your gluOrtho2D. If you want it to resize to fit the window, you might have to re-program the whole thing.

- VC6-OGL

MOON-GIRL
12-25-2002, 04:26 AM
HI

thank you for you


but i want in space area but some button for repaly
select x or o


but i don't now how i can make change for computer in win better than that

i want make intlegent code

can you help me in this trick


best regards
Moon_Girl

nexusone
12-25-2002, 07:39 AM
You can find examples of programming the game X/O's (Tic Tac Toe), maybe will give you an better idea of the game logic.

This site had a forum on programming X/O's and the logic behind it.
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_10837641.html


Originally posted by MOON-GIRL:
HI

thank you for you


but i want in space area but some button for repaly
select x or o


but i don't now how i can make change for computer in win better than that

i want make intlegent code

can you help me in this trick


best regards
Moon_Girl

MOON-GIRL
12-25-2002, 01:11 PM
HI

thank you http://www.opengl.org/discussion_boards/ubb/smile.gif

i well see it now and try modify my code

best regards
Moon_Girl