Jump to content
  • Advertisement

Cirus

Member
  • Content Count

    21
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Cirus

  • Rank
    Member
  1. Thank you gl_coder_one, I tried your tips and solved the problem. I called gluNurbsCurve in the main display function.
  2. Hi , I have a hexagon gving me six control points.I need to draw a circle using glNurbsCurve. Following is a snippet of my code : void drawNurbsCurve(float** ObjectCtrPts , int iTotalCtrlPts) { //GLUnurbsObj *pNurb = NULL; int i = 0 ; //int iKnotCount = ORDER + iTotalCtrlPts ; int iKnotCount = 13; int kStride = 2; GLfloat Knots[13] = {0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0} ; { glNewList(3, GL_COMPILE); // Begin the NURB definition glColor3f(0.2,0.8,0.5); gluBeginCurve(pNurb); //Enable the following glEnable(GL_MAP1_VERTEX_3); // Send the Non Uniform Rational BSpline gluNurbsCurve(pNurb, 13, Knots, kStride, &ObjectCtrPts[0][0] , 4, GL_MAP1_VERTEX_3); gluEndCurve(pNurb); glBegin(GL_POINTS); glColor3f(1.0,1.0,1.0); glVertex3f(0.0f, 0.0f , 0.0f); glEnd(); glEndList(); } I am passing Object control points as follows: ObjCtrPts[][] = { 1.0 , 0.0 ; 0.5, sqrt(3)/4 ; -0.5, sqrt(3)/4; - 1.0 , 0.0 ; -0.5, -sqrt(3)/4}; 0.5, -sqrt(3)/4 } And I am using function call as : gluNurbsCurve(pNurb, 13, Knots, kStride, &ObjectCtrPts[0][0] , 4, GL_MAP1_VERTEX_3); Where my order is 4 , num of knots is 13 ( since control points are 9, for drawing a circle) and knotcount is 13. I am using GL_MAP1_VERTEX_3 RESULT : Getting two perpendicular lines meeting at coordinate (0.0f , 0.0f) i.e at origin. When i use GL_MAP_VERTEX_4 I get a straigh line starting from Control point number 1 and goes out of screen(viewport). I want to get a circle.Where am I going wrong.I searched the RED Book and other sites on google but could not get any help.Hope I will be fortunate this time.
  3. Hi , I have a hexagon gving me six control points.I need to draw a circle using glNurbsCurve. Following is a snippet of my code : void drawNurbsCurve(float** ObjectCtrPts , int iTotalCtrlPts) { //GLUnurbsObj *pNurb = NULL; int i = 0 ; //int iKnotCount = ORDER + iTotalCtrlPts ; int iKnotCount = 13; int kStride = 2; GLfloat Knots[13] = {0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0} ; { glNewList(3, GL_COMPILE); // Begin the NURB definition glColor3f(0.2,0.8,0.5); gluBeginCurve(pNurb); //Enable the following glEnable(GL_MAP1_VERTEX_3); // Send the Non Uniform Rational BSpline gluNurbsCurve(pNurb, 13, Knots, kStride, &ObjectCtrPts[0][0] , 4, GL_MAP1_VERTEX_3); gluEndCurve(pNurb); glBegin(GL_POINTS); glColor3f(1.0,1.0,1.0); glVertex3f(0.0f, 0.0f , 0.0f); glEnd(); glEndList(); } I am passing Object control points as follows: ObjCtrPts[][] = { 1.0 , 0.0 ; 0.5, sqrt(3)/4 ; -0.5, sqrt(3)/4; - 1.0 , 0.0 ; -0.5, -sqrt(3)/4}; 0.5, -sqrt(3)/4 } And I am using function call as : gluNurbsCurve(pNurb, 13, Knots, kStride, &ObjectCtrPts[0][0] , 4, GL_MAP1_VERTEX_3); Where my order is 4 , num of knots is 13 ( since control points are 9, for drawing a circle) and knotcount is 13. I am using GL_MAP1_VERTEX_3 RESULT : Getting two perpendicular lines meeting at coordinate (0.0f , 0.0f) i.e at origin. When i use GL_MAP_VERTEX_4 I get a straigh line starting from Control point number 1 and goes out of screen(viewport). I want to get a circle.Where am I going wrong.I searched the RED Book and other sites on google but could not get any help.Hope I will be fortunate this time.
  4. Hello All. An interesting task for me. I am given a planar triagnle and I need to project it on the surface of a sphere of known radius "R". I also know th distance between the center of the sphere and the point closest to the sphere's center perpendicularly, lying on the triangle. How to realize the projection in OPenGL? [In short I need to make a spherical triangle.] All right I make my task simpler. I need to project a striaght line segment on a curved surface with known radius of curvature. How to do in OpenGL ? Is this have some connection with using NURBS?Or I will have to do it mathematically and then write a code for it?
  5. Hello All, Another interesting problem for me. I have a triangle that I need to project on a sphere.I can understand it conceptually but not able to realize it practically. I am supplied with coordinates of the traingle and also know the radius of the sphere. I also know the distance between the center of the sphere and the plane where the traingle is located. How to project a planar triangle on a sphere? In otherwords how to create a specherical triangle ? (i.e If you draw a triangle on Earth's surface and view it from space, it would appear to be a triangle with curved edges.) OR I simplify my task : How to project a straight line segment on a curved surface in OPENGL? Is there a specific function or do I need to se NURBS? Help Appreciated.
  6. Original post by Mike2343 @Cirus: glut is a bit old and from my understanding not really maintained anymore. Also, he wanted the libs included when he makes a new project without typing anything. The glut refers to all libraries using pragma.The SGI maintains.Though it is not much popular but for basics it is good.
  7. Quote:Original post by Bob III Do you have mismatching push/pops of names? I see you initialize using pushname(0). But when you draw a point, you use loadname(name), followed by popname(). Load name doesn't push a name, it writes over the current top of the name stack. A glGetError call would probably show you that you had (name)stack underflow. Thanks Bob for your response. I believe in you. I was testing with snippet given in the redbook and did some modification. Can you point out what is wrong with the code given at the link : http://www.gamedev.net/community/forums/topic.asp?topic_id=396357 ( Above link is a link to my another post on this topic) . Thanks. I am checking about Push and Pop operations as pointed by you for the code in this post. Help Appreciated.
  8. Cirus

    Simple Picking

    Refer to the RedBook Ch13.
  9. Include glut.h. It automatically includes all libraries.
  10. This is the output I get on execution of posted code. //When Blue Point is picked......................... hits = 1 number of names for hit = 3 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 1242280 hits = 1 number of names for hit = 3 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 1242280 hits = 1 number of names for hit = 3 z1 is 0.333333 z2 is 0.333333 ........................................................... //When yellow point is picked................................. Name is 1242272 1242276 1242280 hits = 1 number of names for hit = 4 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 1242280 1242284 hits = 1 number of names for hit = 4 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 1242280 1242284 hits = 1 number of names for hit = 4 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 1242280 1242284 hits = 1 number of names for hit = 4 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 1242280 1242284 ........................................................ //When red point is picked hits = 0 hits = 0 hits = 0 hits = 1 ..................................................... //When Yellow Point is picked......................... number of names for hit = 2 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 hits = 1 number of names for hit = 2 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 hits = 1 number of names for hit = 2 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276 hits = 1 number of names for hit = 2 z1 is 0.333333 z2 is 0.333333 Name is 1242272 1242276
  11. My task is to pick a point from a set of point, change color of the picked point and then chage its position thorough mouse drag such that positions of rest of the points do not change. Basically its a point selection problem I am tackling with.My previous post on it had my code.This time I am using a snippet from the Red Book and modifying a bit.Now I am trying to get printed the results of hits and hit-records when mouse is dragged. Given below is the code I am using ( You can run it and verify results). // BookEx.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<stdio.h> #include<glut.h> #define BUFFER 512 int flag = 0; int iClick; float X = 0.0f , Y = 0.0f , Z = 0.0f; int Index[3]; void processHits(GLint , GLuint* ); void drawRects(GLenum); void Drag(int x , int y) { GLuint selectBuf[BUFFER]; GLint hits ; GLint viewport[4]; X = x ; Y = y; if(flag) { glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(BUFFER, selectBuf); (void )glRenderMode(GL_SELECT); glInitNames(); glPushName(0) ; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix( (GLdouble)x, (GLdouble)(viewport[3] - y) , 50.0 , 50.0 , viewport ); glOrtho(0.0 , 8.0 , 0.0 , 8.0 , -0.5 , 2.5); drawRects(GL_SELECT); glPopMatrix(); glFlush(); hits = glRenderMode(GL_RENDER); processHits(hits, selectBuf); glutPostRedisplay(); } } void init(void) { glClearColor(0.0, 0.0 , 0.0 , 0.0 ); glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glDepthRange(0.0 , 1.0); } void processHits(GLint hits , GLuint buffer[]) { unsigned int i , j ; GLuint names , *ptr; printf("hits = %d\n", hits); ptr = (GLuint *)buffer; for ( i = 0 ; i < (unsigned)hits ; i++) { names = *ptr ; printf(" number of names for hit = %d\n " , names); ptr++; printf("z1 is %g ", (float) *ptr / 0x7fffffff); ptr++; printf("z2 is %g ", (float) *ptr / 0x7fffffff); ptr++; printf("Name is \n"); for ( j = 0 ; j < names ; j++) { printf("%d\t", ptr); ptr++; } } } void drawRects(GLenum mode) { glPointSize(7); //while(iClick != 0) { //if(mode == GL_RENDER) { //1st pt glColor3f(1.0 , 1.0 , 0.0); if(mode == GL_SELECT) { glColor3f(1.0 , 1.0 , 1.0); glPushName(Index[0]); glLoadName(Index[0]); } glBegin(GL_POINTS); if(mode == GL_SELECT) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ; glEnable(GL_COLOR_MATERIAL) ; glEnable(GL_DEPTH_TEST); glVertex3f( (float)(2 + X/(float)5000) , (float)(1 + Y/(float)5000),0); glPopName(); // glPopName(); } else { glVertex3i(2, 1 ,0); Index[0] = 1; } glEnd(); ///Second pt glColor3f(0.0 , 1.0 , 1.0); if(mode == GL_SELECT) { glColor3f(1.0 , 1.0 , 1.0); glPushName(Index[1]); glLoadName(Index[1]); } glBegin(GL_POINTS); if(mode == GL_SELECT) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ; glEnable(GL_COLOR_MATERIAL) ; glEnable(GL_DEPTH_TEST); glVertex3f( (float)(2 + X/(float)5000) , (float)(6 + Y/(float)5000) ,0); glPopName(); // glPopName(); } else { glVertex3i(2, 6 ,0); Index[1] = 2; } glEnd(); //3rd pt glColor3f(1.0 , 0.0 , 1.0); if(mode == GL_SELECT) { glColor3f(1.0 , 1.0 , 1.0); glPushName(Index[2]); glLoadName(Index[2]); } glBegin(GL_POINTS); if(mode == GL_SELECT) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ; glEnable(GL_COLOR_MATERIAL) ; glEnable(GL_DEPTH_TEST); glVertex3f( (float)(6 + X/(float)5000), (float)(6 + Y/(float)5000) ,0); glPopName(); // glPopName(); } else { glVertex3i(6, 6 ,0); Index[2] = 3; } glEnd(); //4th pt glColor3f(1.0 , 0.0 , 0.0); if(mode == GL_SELECT) { glColor3f(1.0 , 1.0 , 1.0); glPushName(Index[3]); glLoadName(Index[3]); } glBegin(GL_POINTS); if(mode == GL_SELECT) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ; glEnable(GL_COLOR_MATERIAL) ; glEnable(GL_DEPTH_TEST); glVertex3f( (float)(6 + X/(float)5000), (float)(8 + Y/(float)5000) , 0); glPopName(); // glPopName(); } else { glVertex3i(6, 4 ,0); Index[3] = 4; } glEnd(); } } } void pickRects(int button , int state , int x , int y ) { if(button != GLUT_MIDDLE_BUTTON && state != GLUT_DOWN) return ; flag = 1; } void display(void) { glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); drawRects(GL_RENDER); //glFlush(); glutSwapBuffers(); } void reshape(int w , int h) { glViewport(0 , 0 , (GLsizei)w , (GLsizei)h ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0 , 8.0 , 0.0 , 8.0 , -0.5 , 2.5); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc , argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(500 , 500); glutInitWindowPosition(600,400); glutCreateWindow("Book Example"); init(); glutMouseFunc(pickRects); glutMotionFunc(Drag); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMainLoop(); return 0; } As an addition , I am aiming to get point's index value on picking. As a first step, I indexed all the points but still picking is giving me numbers other than index value. To be precise, I want to pick a point using MIDDLE button of mouse and then desire to change its position and color on drag. Now in the code given as above, I am able to change point's color using a boolean flag.i.e when middle button is pressed, the flag is set and so the color changes, but I am getting hits as 0. Problem is I am not able to pick point( because number of hits is 0) and change its position on drag.I am using Orthographic projection through out my code. Help appreciated. [Edited by - Cirus on June 3, 2006 4:37:49 PM]
  12. Hi all, I am struggling to develop an application in openGL that allows me to pick a particular point at a time , change its color and drag it to a new position with respect to other points. With my understanding and hard efforts I have been able to draw all points but not getting the desired results. Following is the relevant portion of my code concerning the above described function: //This function is responsible for dragging. void Drag(int iPos_X , int iPos_Y) { int i = iEle; int iIndex; //Var declarations for picking and selection. GLuint selectBuf[BUF_SIZE]; GLint ViewPort[FOUR] ; GLint iHits = 0; memset(selectBuf,0,BUF_SIZE); //clear if(bMiddleButton) //If middle mouse button is pressed. { MarkPointOnScreen(iPos_X,iPos_Y, WINHEIGHT , WINWIDTH, NULL, pfTemp); // Commented for temporarily.Using selection and picking for selection..This works only for the last point. //pfArray[i - THREE] = pfTemp[0]; //pfArray[i - TWO] = pfTemp[1]; //pfArray[i - ONE] = pfTemp[2]; //Modification required.Indexing of points neccessary. glGetIntegerv(GL_VIEWPORT,ViewPort); glSelectBuffer(BUF_SIZE,selectBuf); //Entering SELECT mode. (void)glRenderMode(GL_SELECT); //Initialising name stack. glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); //createpickmatrix.that is draw a viewing mode of size 1 * 1 pixel. gluPickMatrix((GLdouble)iPos_X , (GLdouble)(ViewPort[3] - iPos_Y) , 1.0 , 1.0 , ViewPort); glOrtho(LEFT , RIGHT , BOTTOM, TOP ,MIN_LIMIT, MAX_LIMIT); //Pick a point and turn its color as blue. drawPoint(GL_SELECT);//When mode is GL_SELECT then works as a Point picker.Aim is to return the index of the point picked. glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush(); //Exiting from SELECT mode and entering NORMAL mode. iHits = glRenderMode(GL_RENDER); processHits(iHits, selectBuf); } glutPostRedisplay(); }//End of function And the code underneath is for drawPoint() that actually draws points and displays them.Moreover, when draggin is performed, th aim of the function is to continuously display the changing positions of the point being dragged. void drawPoint(GLenum mode) { int i =0, j = 0, k = 0 ; static iVar = 0; int iIndex = 0; //if( mode != GL_SELECT) SHIFT_COORD_SIGN = SIGN(5.0 , 0.0); glEnable(GL_DEPTH_TEST); glEnable(GL_LINE_STIPPLE); // Set the material color to follow the current color glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // ...Deleting it gives weired effects. glPushMatrix(); glRotatef(fAngle_Y , 0.0 , 1.0 , 0.0); //Move left glRotatef(fAngle_X , 1.0 , 0.0 , 0.0); //Move above glRotatef(fAngle_Z , 0.0 , 0.0 , 1.0); //Move above glPointSize(POINT_SIZE); while( j < iNumOfClicks) { //SHIIFT_COOR_SIGN is used on assumption that camera moves along Z axis. //glVertex3f(SHIFT_COORD_SIGN * pfArray, pfArray[i + 1], pfArray[i + 2] ); if(bMiddleButton) // && mode == GL_SELECT) { glColor3f(0.0 ,1.0 ,0.0); //Section added w.ref to GameDev forum post. if (mode == GL_SELECT) glLoadName(j); //j is the point index here. glBegin(GL_POINTS); glVertex3f(SHIFT_COORD_SIGN * pfArray, pfArray[i + 1], pfArray[i + 2] ); glEnd(); // if(mode == GL_SELECT) // glPopName(); } else { glColor3f(1.0, 0.0, 1.0); glBegin(GL_POINTS); glVertex3f(SHIFT_COORD_SIGN * pfArray * fZoom_X, pfArray[i + 1] * fZoom_Y, pfArray[i + 2] *fZoom_Z); glEnd(); } bDefault = TRUE; //Reset Flag. i += 3; ++j; }//End of While Loop glPopMatrix(); i = 0; //Reset counter. j = 0; //Reset counter. glutSwapBuffers(); }//End of function drawPoint. Problem is: When I press middle button of mouse, the color of each vertex turns green from original color purple.But when I drag a point, , I observe that number of Hits remains 0. With more efforts , I was able to drag the last drawn point only by supplying to current mouse cursor position to glVertex3f function. I need a sceneario where , if I draw 4 points and I pick the 2nd point or 3rd and drag it, the point must move with respect to other points. ( i.e position of other points must not change and after dragging operation, all points should be displayed. Help is appreciated.
  13. I have a number of pixels of a particular color.I need to choose a,already rendered, pixel , using mouse click and then change its color. Q1 .How to do this? Q2. I need to add dragging feature in my application where in, I need to move a particular ,already rendered, point to a new location. Presently, I am able to do dragging on the point drawn most recently. That is the last point. Eg: I have 3 points A,B,C with C as the latest point.I am able to drag C only but not B or A. Thank you.
  14. I came to know about GLUt having its own window screens ( equivalent to JAV aplet or MFC) .Is there a way to display text in the task bar of the window,like what one can obtain in Java Applet?
  15. I am trying to mark points and form a loop around the face in front. Then I rotate my object to get another face as front face and try to enclose it in a loop. Problem is : When I successfully form the first loop and then rotate the object, the loop disappears. Secondly, I am unable to form 2 loops at a time that are disjoint. Here is code section I am trying to play with : if(bFlag_LineDraw) //removed temp { //while(piClickTracker[k]) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glRotatef(fAngle_Y , 0.0 , 1.0 , 0.0); //Move left glRotatef(fAngle_X , 1.0 , 0.0 , 0.0); //Move above glRotatef(fAngle_Z , 0.0 , 0.0 , 1.0); //Move above if(!(k % TWO)) glColor3f(1.0 , 0.0 , 0.0); else glColor3f(0.0 , 00 , 1.0); while(piClickTracker[k]) { glBegin(GL_LINE_LOOP); //glBegin(GL_LINES); while(j < piClickTracker[k]) { . glVertex3f(SHIFT_COORD_SIGN * pfArray[i + iTemp], pfArray[i + 1 + iTemp], pfArray[i + 2 + iTemp] ); //Modified ..temp i += 3; j++; } j = 0; iTemp += 1; ++k; glEnd(); glPopMatrix(); }//Outer While Ending. //glPopMatrix(); } bFlag_LineDraw = FALSE; }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!