Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualDarkHorseKnight

Posted 22 May 2012 - 03:06 PM

Hello yes I'm trying to draw a 3D Line here is the code thats most important in this case

The Setup :


void init ()
{
glClearColor(1.0,0.0,0.0,1.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(90,SCREEN_HEIGHT/SCREEN_WIDTH,0.0,1500.0);
		glMatrixMode(GL_MODELVIEW);
		glEnable(GL_DEPTH_TEST);		  
		glEnable(GL_LIGHTING);  //we enable lighting, to make the 3D object to 3D
		glEnable(GL_LIGHT0);
		float col[]={1.0,1.0,1.0,1.0};  //light color is white
		glLightfv(GL_LIGHT0,GL_DIFFUSE,col);

}
  

Drawing The Line :

	case WM_LBUTTONDOWN:
		
		  glBegin( GL_LINES );
		  glColor3f( 1.0f, 0.0f, 0.0f );
		  glVertex3f(posX, posY, 0.0f);
		  glVertex3f(posX, posY, posZ );
		  glEnd();
	  
		  cout << "Test" << endl;
	  

	break;

Displaying the graphics:

void display()
{

		glLoadIdentity();
		float pos[]={-1.0,1.0,-2.0,1.0};		//set the position
		glLightfv(GL_LIGHT0,GL_POSITION,pos);
		//glRotatef(angle,angle,0.0,2.0);
		cout << name << endl;
	 // glCallList(cube);
	  for(std::vector<GLuint>::iterator I = cube.begin(); I != cube.end(); ++I) {
	glCallList(*I);
	  }
	  
		  glGetIntegerv(GL_VIEWPORT, viewport);
		  glGetDoublev(GL_PROJECTION_MATRIX, projection);
		
		  GetCursorPos(&mouse);
		  ScreenToClient(hwnd, &mouse);
  
		  winX = (float)mouse.x;
		  winY = (float)mouse.y;
		  winY = (float)viewport[3] - winY;
		  glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
		  gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ );
		  cout << mouse.x << endl;
		  cout << mouse.y << endl;
	  
		  SwapBuffers(hDC);
		  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	  
	  
}


And theres not much to see accept a black background with a red line that shows on the frustum only if I left click many times  Posted Image

Hope that helps

#3DarkHorseKnight

Posted 22 May 2012 - 03:05 PM

Hello yes I'm trying to draw a 3D Line here is the code thats most important in this case

The Setup :


void init ()
{
glClearColor(1.0,0.0,0.0,1.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(90,SCREEN_HEIGHT/SCREEN_WIDTH,0.0,1500.0);
		glMatrixMode(GL_MODELVIEW);
		glEnable(GL_DEPTH_TEST);		  
		glEnable(GL_LIGHTING);  //we enable lighting, to make the 3D object to 3D
		glEnable(GL_LIGHT0);
		float col[]={1.0,1.0,1.0,1.0};  //light color is white
		glLightfv(GL_LIGHT0,GL_DIFFUSE,col);

}
  

Drawing The Line :

	case WM_LBUTTONDOWN:
		
		  glBegin( GL_LINES );
		  glColor3f( 1.0f, 0.0f, 0.0f );
		  glVertex3f(posX, posY, 0.0f);
		  glVertex3f(posX, posY, posZ );
		  glEnd();
	  
		  cout << "Test" << endl;
	  

	break;

Displaying the graphics:
void display()
{

		glLoadIdentity();
		float pos[]={-1.0,1.0,-2.0,1.0};		//set the position
		glLightfv(GL_LIGHT0,GL_POSITION,pos);
		//glRotatef(angle,angle,0.0,2.0);
		cout << name << endl;
	 // glCallList(cube);
	  for(std::vector<GLuint>::iterator I = cube.begin(); I != cube.end(); ++I) {
	glCallList(*I);
	  }
	  
		  glGetIntegerv(GL_VIEWPORT, viewport);
		  glGetDoublev(GL_PROJECTION_MATRIX, projection);
		
		  GetCursorPos(&mouse);
		  ScreenToClient(hwnd, &mouse);
  
		  winX = (float)mouse.x;
		  winY = (float)mouse.y;
		  winY = (float)viewport[3] - winY;
		  glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
		  gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ );
		  cout << mouse.x << endl;
		  cout << mouse.y << endl;
	  
		  SwapBuffers(hDC);
		  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	  
	  
}


And theres not much to see accept a black background with a red line that shows on the frustum only if I left click many times  Posted Image

Hope that helps

#2DarkHorseKnight

Posted 22 May 2012 - 03:04 PM

Hello yes I'm trying to draw a 3D Line here is the code thats most important in this case

The Setup :


void init ()
{
glClearColor(1.0,0.0,0.0,1.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(90,SCREEN_HEIGHT/SCREEN_WIDTH,0.0,1500.0);
		glMatrixMode(GL_MODELVIEW);
		glEnable(GL_DEPTH_TEST);		  
		glEnable(GL_LIGHTING);  //we enable lighting, to make the 3D object to 3D
		glEnable(GL_LIGHT0);
		float col[]={1.0,1.0,1.0,1.0};  //light color is white
		glLightfv(GL_LIGHT0,GL_DIFFUSE,col);

}
  

Drawing The Line :

	case WM_LBUTTONDOWN:
		
		  glBegin( GL_LINES );
		  glColor3f( 1.0f, 0.0f, 0.0f );
		  glVertex3f(posX, posY, 0.0f);
		  glVertex3f(posX, posY, posZ );
		  glEnd();
	  
		  cout << "Test" << endl;
	  

	break;


void display()
{

		glLoadIdentity();
		float pos[]={-1.0,1.0,-2.0,1.0};		//set the position
		glLightfv(GL_LIGHT0,GL_POSITION,pos);
		//glRotatef(angle,angle,0.0,2.0);
		cout << name << endl;
	 // glCallList(cube);
	  for(std::vector<GLuint>::iterator I = cube.begin(); I != cube.end(); ++I) {
	glCallList(*I);
	  }
	  
		  glGetIntegerv(GL_VIEWPORT, viewport);
		  glGetDoublev(GL_PROJECTION_MATRIX, projection);
		
		  GetCursorPos(&mouse);
		  ScreenToClient(hwnd, &mouse);
  
		  winX = (float)mouse.x;
		  winY = (float)mouse.y;
		  winY = (float)viewport[3] - winY;
		  glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
		  gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ );
		  cout << mouse.x << endl;
		  cout << mouse.y << endl;
	  
		  SwapBuffers(hDC);
		  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	  
	  
}


And theres not much to see accept a black background with a red line that shows on the frustum only if I left click many times  Posted Image

Hope that helps

#1DarkHorseKnight

Posted 22 May 2012 - 03:04 PM

Hello yes I'm trying to draw a 3D Line here is the code thats most important in this case :

The Setup :


void init ()
{
glClearColor(1.0,0.0,0.0,1.0);
	    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	    glMatrixMode(GL_PROJECTION);
	    glLoadIdentity();
	    gluPerspective(90,SCREEN_HEIGHT/SCREEN_WIDTH,0.0,1500.0);
	    glMatrixMode(GL_MODELVIEW);
	    glEnable(GL_DEPTH_TEST);		  
	    glEnable(GL_LIGHTING);  //we enable lighting, to make the 3D object to 3D
	    glEnable(GL_LIGHT0);
	    float col[]={1.0,1.0,1.0,1.0};  //light color is white
	    glLightfv(GL_LIGHT0,GL_DIFFUSE,col);

}
  

Drawing The Line :

    case WM_LBUTTONDOWN:
		
		  glBegin( GL_LINES ); 
		  glColor3f( 1.0f, 0.0f, 0.0f ); 
		  glVertex3f(posX, posY, 0.0f);
		  glVertex3f(posX, posY, posZ );
		  glEnd(); 
	   
		  cout << "Test" << endl;
	   
 
    break;


void display()
{
 
	    glLoadIdentity();
	    float pos[]={-1.0,1.0,-2.0,1.0};	    //set the position
	    glLightfv(GL_LIGHT0,GL_POSITION,pos);
	    //glRotatef(angle,angle,0.0,2.0);
	    cout << name << endl;
	 // glCallList(cube);
	  for(std::vector<GLuint>::iterator I = cube.begin(); I != cube.end(); ++I) {
    glCallList(*I);
	  }
	   
		  glGetIntegerv(GL_VIEWPORT, viewport);
		  glGetDoublev(GL_PROJECTION_MATRIX, projection);
		 
		  GetCursorPos(&mouse);
		  ScreenToClient(hwnd, &mouse);
   
		  winX = (float)mouse.x;
		  winY = (float)mouse.y;
		  winY = (float)viewport[3] - winY;
		  glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
		  gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ );
		  cout << mouse.x << endl;
		  cout << mouse.y << endl;
	   
		  SwapBuffers(hDC);
		  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	   
	  
}


And theres not much to see accept a black background with a red line that shows on the frustum only if I left click many times  :)

Hope that helps

PARTNERS