示例#1
0
文件: drv_sdlgl.c 项目: adsr/agar
static void
SDLGL_PushClipRect(void *obj, AG_Rect r)
{
	AG_DriverSDLGL *sgl = obj;
	AG_ClipRect *cr, *crPrev;

	sgl->clipRects = Realloc(sgl->clipRects, (sgl->nClipRects+1)*
	                                         sizeof(AG_ClipRect));
	crPrev = &sgl->clipRects[sgl->nClipRects-1];
	cr = &sgl->clipRects[sgl->nClipRects++];

	cr->eqns[0][0] = 1.0;
	cr->eqns[0][1] = 0.0;
	cr->eqns[0][2] = 0.0;
	cr->eqns[0][3] = MIN(crPrev->eqns[0][3], -(double)(r.x));
	glClipPlane(GL_CLIP_PLANE0, (const GLdouble *)&cr->eqns[0]);
	
	cr->eqns[1][0] = 0.0;
	cr->eqns[1][1] = 1.0;
	cr->eqns[1][2] = 0.0;
	cr->eqns[1][3] = MIN(crPrev->eqns[1][3], -(double)(r.y));
	glClipPlane(GL_CLIP_PLANE1, (const GLdouble *)&cr->eqns[1]);
		
	cr->eqns[2][0] = -1.0;
	cr->eqns[2][1] = 0.0;
	cr->eqns[2][2] = 0.0;
	cr->eqns[2][3] = MIN(crPrev->eqns[2][3], (double)(r.x+r.w));
	glClipPlane(GL_CLIP_PLANE2, (const GLdouble *)&cr->eqns[2]);
		
	cr->eqns[3][0] = 0.0;
	cr->eqns[3][1] = -1.0;
	cr->eqns[3][2] = 0.0;
	cr->eqns[3][3] = MIN(crPrev->eqns[3][3], (double)(r.y+r.h));
	glClipPlane(GL_CLIP_PLANE3, (const GLdouble *)&cr->eqns[3]);
}
示例#2
0
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();

    GLdouble eqn1[4] = {0.0, 1.0, 0.0, 0.0};
    GLdouble eqn2[4] = {1.0, 0.0, 0.0, 0.0};

    glPushMatrix();
    glTranslated(0.0, 0.0, -5.0);
    
    glClipPlane(GL_CLIP_PLANE0, eqn1);
    glEnable(GL_CLIP_PLANE0);

    glClipPlane(GL_CLIP_PLANE1, eqn2);
    glEnable(GL_CLIP_PLANE1);

    glRotated(90.0, 1.0, 0.0, 0.0);
    
    glutWireSphere(1.0, 20, 20);

    glPopMatrix();
    glFlush();
}
示例#3
0
文件: clip.c 项目: slavablind91/code
void display(void) {
    int i, j;
    for(i=0; i<=360; i++) {
        GLdouble eqn[4] = {0.0, 0.0, 0.0, 0.0};
        GLdouble eqn2[4] = {0.0, 0.0, 0.0, 0.0};

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

        // отсекаем нижнюю половину - y<0
        glClipPlane(GL_CLIP_PLANE0, eqn);
        glEnable(GL_CLIP_PLANE0);

        // отсекаем левую половину - x<0
        glClipPlane(GL_CLIP_PLANE1, eqn2);
        glEnable(GL_CLIP_PLANE1);

        glRotatef(i*1.0, 0.0, 1.0, 0.0);
        glRotatef(i*1.0, 1.0, 0.0, 0.0);
        glutWireSphere(1.0, 20, 16);
        glPopMatrix();
        glFlush();

        usleep(10000);
    }
}
void TrimmedSphereShape::draw() const
{
	const GLenum drawingFace = getDrawingFace() == swl::attrib::POLYGON_FACE_FRONT ? GL_FRONT :
		(getDrawingFace() == swl::attrib::POLYGON_FACE_BACK ? GL_BACK :
		(getDrawingFace() == swl::attrib::POLYGON_FACE_FRONT_AND_BACK ? GL_FRONT_AND_BACK :
		(getDrawingFace() == swl::attrib::POLYGON_FACE_NONE ? GL_NONE : GL_FRONT)));
	const GLenum polygonMode = getPolygonMode() == swl::attrib::POLYGON_FILL ? GL_FILL :
		(getPolygonMode() == swl::attrib::POLYGON_LINE ? GL_LINE :
		(getPolygonMode() == swl::attrib::POLYGON_POINT ? GL_POINT : GL_FILL));

	// save states
	GLint oldPolygonMode[2];
	glGetIntegerv(GL_POLYGON_MODE, oldPolygonMode);
	glPolygonMode(drawingFace, polygonMode);
	//glPolygonMode(GL_FRONT, polygonMode);  // not working !!!

	glPushMatrix();
		//glLoadIdentity();
		glTranslatef(-250.0f, 250.0f, -250.0f);

		const double clippingPlane0[] = { 1.0, 0.0, 0.0, 100.0 };
		const double clippingPlane1[] = { -1.0, 0.0, 0.0, 300.0 };

		// draw clipping areas
		drawClippingRegion(GL_CLIP_PLANE0, clippingPlane0);
		drawClippingRegion(GL_CLIP_PLANE1, clippingPlane1);

		// enables clipping planes
		glEnable(GL_CLIP_PLANE0);
		glClipPlane(GL_CLIP_PLANE0, clippingPlane0);
		glEnable(GL_CLIP_PLANE1);
		glClipPlane(GL_CLIP_PLANE1, clippingPlane1);

		const GLuint id = reinterpret_cast<GLuint>(this);
		glPushName(id);
			// draw a sphere
			if (swl::ObjectPickerMgr::getInstance().isPicking() && swl::ObjectPickerMgr::getInstance().isTemporarilyPickedObject(id))
			{
				const swl::ObjectPickerMgr::color_type &pickedColor = swl::ObjectPickerMgr::getInstance().getTemporarilyPickedColor();
				glColor4f(pickedColor.r, pickedColor.g, pickedColor.b, pickedColor.a);
			}
			else if (swl::ObjectPickerMgr::getInstance().isPickedObject(id))
			{
				const swl::ObjectPickerMgr::color_type &pickedColor = swl::ObjectPickerMgr::getInstance().getPickedColor();
				glColor4f(pickedColor.r, pickedColor.g, pickedColor.b, pickedColor.a);
			}
			else glColor4f(red(), green(), blue(), alpha());
			GL_LINE == polygonMode ? glutWireSphere(500.0, 20, 20) : glutSolidSphere(500.0, 20, 20);
		glPopName();

		// disables clipping planes
		glDisable(GL_CLIP_PLANE0);
		glDisable(GL_CLIP_PLANE1);
	glPopMatrix();

	// restore states
	//glPolygonMode(oldPolygonMode[0], oldPolygonMode[1]);  // not working. don't know why.
	glPolygonMode(drawingFace, oldPolygonMode[1]);
}
示例#5
0
void Scene :: DrawCageDome()
{
  GLdouble z_clip_pane[4] = {0.0, 0.0, -1.0, 925.0};
  GLdouble y_clip_pane[4] = {0.0, 1.0, 0.0, 0.0};
  glClipPlane(GL_CLIP_PLANE0, z_clip_pane);
  glClipPlane(GL_CLIP_PLANE4, y_clip_pane);
  glEnable(GL_CLIP_PLANE0);
  glEnable(GL_CLIP_PLANE4);

  glPushMatrix();
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
    DrawVerticalGirder();
    glRotatef(20, 0, 1, 0);
  glPopMatrix();

  glPushMatrix();
    DrawHorizontalGirder(-5);
	DrawHorizontalGirder(100);
	DrawHorizontalGirder(200);
	DrawHorizontalGirder(300);
	DrawHorizontalGirder(400);
	DrawHorizontalGirder(500);
	DrawHorizontalGirder(600);
	DrawHorizontalGirder(700);
	DrawHorizontalGirder(800);
	DrawHorizontalGirder(900);
	DrawHorizontalGirder(1000);
  glPopMatrix();
  
  glDisable(GL_CLIP_PLANE0);

  glPushMatrix();
    glTranslatef(0, 0, 700 + 225);
    glRotatef(90, 1, 0, 0);
    TaperedCylinder(600, 380, 380, 30);
  glPopMatrix();

  glDisable(GL_CLIP_PLANE4);
}  // DrawDome
  void AttitudeIndicatorPlugin::drawBall()
  {
    GLdouble eqn[4] = {0.0, 0.0, 1.0, 0.0};
    GLdouble eqn2[4] = {0.0, 0.0, -1.0, 0.0};
    GLdouble eqn4[4] = {0.0, 0.0, 1.0, 0.05};
    GLdouble eqn3[4] = {0.0, 0.0, -1.0, 0.05};

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glPushMatrix();

    glColor3f(0.392156863f, 0.584313725f, 0.929411765f);
    glRotated(90.0 + pitch_, 1.0, 0.0, 0.0);

    glRotated(roll_, 0.0, 1.0, 0.0);
    glRotated(yaw_, 0.0, 0.0, 1.0);
    glClipPlane(GL_CLIP_PLANE1, eqn2);
    glEnable(GL_CLIP_PLANE1);
    glutSolidSphere(.8, 20, 16);
    glDisable(GL_CLIP_PLANE1);
    glPopMatrix();

    glPushMatrix();

    glLineWidth(2);
    glColor3f(1.0f, 1.0f, 1.0f);
    glRotated(90.0 + pitch_, 1.0, 0.0, 0.0);
    glRotated(roll_, 0.0, 1.0, 0.0);
    glRotated(yaw_, 0.0, 0.0, 1.0);
    glClipPlane(GL_CLIP_PLANE3, eqn4);
    glClipPlane(GL_CLIP_PLANE2, eqn3);
    glEnable(GL_CLIP_PLANE2);
    glEnable(GL_CLIP_PLANE3);
    glutWireSphere(.801, 10, 16);
    glDisable(GL_CLIP_PLANE2);
    glDisable(GL_CLIP_PLANE3);
    glPopMatrix();

    glPushMatrix();
    glColor3f(0.62745098f, 0.321568627f, 0.176470588f);
    glRotated(90.0 + pitch_, 1.0, 0.0, 0.0);//x
    glRotated(roll_, 0.0, 1.0, 0.0);//y
    glRotated(yaw_, 0.0, 0.0, 1.0);//z
    glClipPlane(GL_CLIP_PLANE0, eqn);
    glEnable(GL_CLIP_PLANE0);
    glutSolidSphere(.8, 20, 16);
    glDisable(GL_CLIP_PLANE0);
    glPopMatrix();
    glDisable(GL_DEPTH_TEST);
  }
示例#7
0
void do_display(void)
{
    glDisable(GL_DEPTH_TEST);
    /* glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); */
    if (reflection) {
      glEnable(GL_STENCIL_TEST);
      glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
      glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
    }
    do_vlakje();
    glEnable(GL_DEPTH_TEST);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

    if (reflection)
    {
	glStencilFunc(GL_EQUAL, 1, 0xffffffff);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

	glPushMatrix();
	glScalef(1.0, -1.0, 1.0);
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	glClipPlane(GL_CLIP_PLANE1, ClipPlane);
	glEnable(GL_CLIP_PLANE1);
	do_pieces();
	glPopMatrix();
	glDisable(GL_CLIP_PLANE1);
        glDisable(GL_STENCIL_TEST);

	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
    }

/*
 * Also without texturing I want to blend, to keep the contrast of the board
 * consistent.
 */

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    do_board();

    glDisable(GL_BLEND);

    do_border();

    glClipPlane(GL_CLIP_PLANE1, ClipPlane);
    glEnable(GL_CLIP_PLANE1);
    do_pieces();
    glDisable(GL_CLIP_PLANE1);
}
示例#8
0
void Widget::SetClipping(float width, float height)
{
    const GLdouble eqn1[4] = {1,0,0,0};
    const GLdouble eqn2[4] = {0,1,0,0};
    const GLdouble eqn3[4] = {-1,0,0,width};
    const GLdouble eqn4[4] = {0,-1,0,height};
    glClipPlane(GL_CLIP_PLANE0, eqn1);
    glClipPlane(GL_CLIP_PLANE1, eqn2);
    glClipPlane(GL_CLIP_PLANE2, eqn3);
    glClipPlane(GL_CLIP_PLANE3, eqn4);
    glEnable(GL_CLIP_PLANE0);
    glEnable(GL_CLIP_PLANE1);
    glEnable(GL_CLIP_PLANE2);
    glEnable(GL_CLIP_PLANE3);
}
示例#9
0
void Scene :: DrawFloor()
{
  GLfloat mat_ambient[] = {0.2, 0.2, 0.2, 1.0};
  GLfloat mat_diffuse[] = {0.2, 0.2, 0.2, 1.0};
  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

  GLdouble y_clip_pane[4] = {0.0, -1.0, 0.0, 0.0};
  glClipPlane(GL_CLIP_PLANE0, y_clip_pane);
  glEnable(GL_CLIP_PLANE0);
  
  glPushMatrix();
    glScalef(1, 0.3, 1);
    glutSolidSphere(1000, 30, 30);
  glPopMatrix();

  glDisable(GL_CLIP_PLANE0);

  glPushMatrix();
    TaperedCylinder(0, 1000, 0, 30);

    glBegin(GL_POLYGON);
	  glNormal3f(0, 1, 0);
	  glVertex3f(-380, 0, 925);
	  glVertex3f(380, 0, 925);
	  glVertex3f(380, 0, 1525);
	  glVertex3f(-380, 0, 1525);
	glEnd();
  glPopMatrix();
}  // DrawFloor
示例#10
0
文件: gematrix.c 项目: lmorel3/libge
void geUpdateMatrix(){
	ge_matrix_update[ge_current_mode] = ge_current_matrix_update;

	CalculateModelMatrices();

	geSendMatrix(GE_MATRIX_MODEL, (float*)&ge_matrices[GE_MATRIX_MODEL]);
	geSendMatrix(GE_MATRIX_SUBMODEL, (float*)&ge_matrices[GE_MATRIX_SUBMODEL]);
	geSendMatrix(GE_MATRIX_VIEW, (float*)&ge_matrices[GE_MATRIX_VIEW]);
	geSendMatrix(GE_MATRIX_PROJECTION, (float*)&ge_matrices[GE_MATRIX_PROJECTION]);
//	if(ge_matrix_update[GE_MATRIX_MODEL] || ge_matrix_update[GE_MATRIX_VIEW]){
		SendModelMatrices();
//	}

	geSendMatrix(GE_MATRIX_TEXTURE0, (float*)&ge_matrices[GE_MATRIX_TEXTURE0]);
	geSendMatrix(GE_MATRIX_TEXTURE1, (float*)&ge_matrices[GE_MATRIX_TEXTURE1]);
	geSendMatrix(GE_MATRIX_TEXTURE2, (float*)&ge_matrices[GE_MATRIX_TEXTURE2]);
	geSendMatrix(GE_MATRIX_TEXTURE3, (float*)&ge_matrices[GE_MATRIX_TEXTURE3]);
	geSendMatrix(GE_MATRIX_TEXTURE4, (float*)&ge_matrices[GE_MATRIX_TEXTURE4]);
	geSendMatrix(GE_MATRIX_TEXTURE5, (float*)&ge_matrices[GE_MATRIX_TEXTURE5]);
	geSendMatrix(GE_MATRIX_TEXTURE6, (float*)&ge_matrices[GE_MATRIX_TEXTURE6]);
	geSendMatrix(GE_MATRIX_TEXTURE7, (float*)&ge_matrices[GE_MATRIX_TEXTURE7]);
	
	glActiveTexture(GL_TEXTURE0);
	if(!ge_current_shader)return;
	GLdouble cp[4] = { ge_clip_plane[0], ge_clip_plane[1], ge_clip_plane[2], ge_clip_plane[3] };
	glClipPlane(GL_CLIP_PLANE0, cp);
}
示例#11
0
void
gl_clip_plane (void)
{
  int i, max_planes;
  GLdouble planes[4];
  char buf[BUFSIZ];

  glGetIntegerv (GL_MAX_CLIP_PLANES, &max_planes);

  for (i = 0; i < max_planes; i++)
    {
      planes[0] = (1.0 * (float) i);
      planes[1] = planes[0] + 10.0;
      planes[2] = planes[0] + 100.0;
      planes[3] = planes[0] + 1000.0;

      snprintf (buf, BUFSIZ, "GL_CLIP_PLANE%d", i);
      test_prologue (buf);
      glEnable (GL_CLIP_PLANE0 + i);
      glClipPlane (GL_CLIP_PLANE0 + i, planes);
      tri ();
      glDisable (GL_CLIP_PLANE0 + i);
      test_epilogue (true);
    }
}
示例#12
0
void GLPlaneMirrorPortal::DrawContents()
{
	if (renderdepth>r_mirror_recursions) 
	{
		ClearScreen();
		return;
	}

	int old_pm=PlaneMirrorMode;

	fixed_t planez = origin->ZatPoint(viewx, viewy);
	viewz = 2*planez - viewz;
	GLRenderer->mViewActor = NULL;
	PlaneMirrorMode = ksgn(origin->c);

	validcount++;

	PlaneMirrorFlag++;
	GLRenderer->SetupView(viewx, viewy, viewz, viewangle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
	ClearClipper();

	glEnable(GL_CLIP_PLANE0+renderdepth);
	// This only works properly for non-sloped planes so don't bother with the math.
	//double d[4]={origin->a/65536., origin->c/65536., origin->b/65536., FIXED2FLOAT(origin->d)};
	double d[4]={0, static_cast<double>(PlaneMirrorMode), 0, FIXED2FLOAT(origin->d)};
	glClipPlane(GL_CLIP_PLANE0+renderdepth, d);

	GLRenderer->DrawScene();
	glDisable(GL_CLIP_PLANE0+renderdepth);
	PlaneMirrorFlag--;
	PlaneMirrorMode=old_pm;
}
示例#13
0
文件: glext.c 项目: AMDmi3/neverball
void glClipPlane4f_(GLenum p, GLfloat a, GLfloat b, GLfloat c, GLfloat d)
{
#if ENABLE_OPENGLES

    GLfloat v[4];

    v[0] = a;
    v[1] = b;
    v[2] = c;
    v[3] = d;

    glClipPlanef(p, v);

#else

    GLdouble v[4];

    v[0] = a;
    v[1] = b;
    v[2] = c;
    v[3] = d;

    glClipPlane(p, v);

#endif
}
示例#14
0
void Draw1stReflectedSceneToBuffer(int lookback,FrameBuffer *fbo)
{
	fbo->BindBuffer();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();

	glMultMatrixf(reflectmatrix);
	if(lookback != 0)	Draw2ndReflectedSceneToBuffer(lookback,Temp2);
	scene->SetupEnabledLightsWithCurrentModelview();

	glClipPlane(GL_CLIP_PLANE1,mirror1plane);
	glEnable(GL_CLIP_PLANE1);

	glDisable(GL_CULL_FACE);
	glCullFace(GL_FRONT);
//	DrawSceneStuff();
	DrawFan();
	scene->Draw();
	DrawFloorMirror();
	DrawSilModel();
	DrawExtraWalls();
	DrawSelectionObjects(GL_RENDER);
	if(Mirror2Drawn != 0)
		DrawSecondMirror(0);
	else
		Mirror2Drawn = 1;
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);

	glDisable(GL_CLIP_PLANE1);

	glPopMatrix();
	fbo->UnbindBuffer();
}
示例#15
0
文件: Water.cpp 项目: DCubix/1.4.0
void CWater::CreateRefractionDepthTexture(int textureSize)
{
	// To create the refraction and depth textures we do the same thing
	// we did for the reflection texture, except we don't need to turn
	// the world upside down.  We want to find the depth of the water,
	// not the depth of the sky and above water terrain.
	
    glViewport(0,0, textureSize, textureSize);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

	// If the camera is above water, render the data below the water
	double plane[4] = {0.0, -1.0, 0.0, m_fWaterCPos[1]}; 
	glEnable(GL_CLIP_PLANE0);
	glClipPlane(GL_CLIP_PLANE0, plane);
	//RenderWorld(true); I need to add some extra code to specify the objects that are under water
	glDisable(GL_CLIP_PLANE0);

	g_render.PopMatrix();
	glFlush();

    // Bind the current scene to our refraction texture
    glBindTexture(GL_TEXTURE_2D, m_waterTexture[WATER_REFRACTION_ID]);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);

    // Bind the current scene to our depth texture
    glBindTexture(GL_TEXTURE_2D, m_waterTexture[WATER_DEPTH_ID]);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);

}
void TrimmedSphereShape::drawClippingRegion(const unsigned int clippingPlaneId, const double *clippingPlaneEqn) const
{
	glEnable(clippingPlaneId);
	glClipPlane(clippingPlaneId, clippingPlaneEqn);

	//----- rendering the mesh_'s clip edge
	glEnable(GL_STENCIL_TEST);
	glEnable(GL_CULL_FACE);
	glClear(GL_STENCIL_BUFFER_BIT);
	glDisable(GL_DEPTH_TEST);
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

	// first pass: increment stencil buffer value on back faces
	glStencilFunc(GL_ALWAYS, 0, 0);
	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
	glCullFace(GL_FRONT);  // render back faces only

	glutSolidSphere(500.0, 20, 20);

	// second pass: decrement stencil buffer value on front faces
	glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
	glCullFace(GL_BACK);  // render front faces only

	glutSolidSphere(500.0, 20, 20);

	// drawing clip planes masked by stencil buffer content
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	glDisable(clippingPlaneId);
	glStencilFunc(GL_NOTEQUAL, 0, ~0); 
	// stencil test will pass only when stencil buffer value = 0. (~0 = 0x11...11)

	// rendering the plane quad. Note, it should be big enough to cover all clip edge area.
	glCullFace(GL_BACK);  // render back faces only
	glBegin(GL_QUADS);
		glColor3f(0.0f, 0.0f, 0.0f);
		// FIXME [correct] >> to be generalized
		if (clippingPlaneEqn[0] < 0.0f)
		{
			const GLfloat x = -clippingPlaneEqn[3] / clippingPlaneEqn[0];
			glVertex3f(x, -1000.0f, -1000.0f);
			glVertex3f(x, 1000.0f, -1000.0f);
			glVertex3f(x, 1000.0f, 1000.0f);
			glVertex3f(x, -1000.0f, 1000.0f);
		}
		else
		{
			const GLfloat x = -clippingPlaneEqn[3] / clippingPlaneEqn[0];
			glVertex3f(x, -1000.0f, -1000.0f);
			glVertex3f(x, -1000.0f, 1000.0f);
			glVertex3f(x, 1000.0f, 1000.0f);
			glVertex3f(x, 1000.0f, -1000.0f);
		}
	glEnd();

	glDisable(GL_STENCIL_TEST);
	glDisable(GL_CULL_FACE);
	//----- end rendering mesh_'s clip edge
}
示例#17
0
void
iil4mitkImage::display (iil4mitkWidget* widget)
{
  GLdouble planeX [] = {-1, 0, 0, regionWidth ()};
  GLdouble planeY [] = {0, -1, 0, regionHeight ()};

  if (!visible () 
    || (constraint () && (widget != constraint ())))
  {
    return;
  }

  if (_pixels)
  {
    assert (_rx + _rw <= _width);
    assert (_ry + _rh <= _height);

    GLboolean texturing = glIsEnabled (GL_TEXTURE_2D);
    GLboolean blending = glIsEnabled (GL_BLEND);

    glClipPlane (GL_CLIP_PLANE4, planeX);
    glEnable (GL_CLIP_PLANE4);
    glClipPlane (GL_CLIP_PLANE5, planeY);
    glEnable (GL_CLIP_PLANE5);

    if ((_model == INTENSITY_ALPHA) || (_model == COLOR_ALPHA) || (_model == RGB) || (_model == RGBA))
    {
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    glEnable (GL_TEXTURE_2D);
    glMatrixMode (GL_MODELVIEW);
    glPushMatrix ();
    glColor4f (red (), green (), blue (), alpha ());
    glTranslatef (x (), y (), 0.0);
    drawTextures (widget);
    glPopMatrix ();

    glDisable (GL_CLIP_PLANE4);
    glDisable (GL_CLIP_PLANE5);

    if (texturing == GL_FALSE) glDisable (GL_TEXTURE_2D);
    if (blending  == GL_FALSE) glDisable (GL_BLEND);
  }
}
示例#18
0
bool Component::setupClipping(Graphics* const Graphics) const
{
    if(getClipping())
    {    
        //Get Clipping initial settings
        Pnt2f ClipTopLeft,ClipBottomRight;
        getClipBounds(ClipTopLeft,ClipBottomRight);

        Vec4d LeftPlaneEquation  (1.0,0.0,0.0, -ClipTopLeft.x()     + Graphics->getClipPlaneOffset()),
              RightPlaneEquation (-1.0,0.0,0.0, ClipBottomRight.x() + Graphics->getClipPlaneOffset()),
              TopPlaneEquation   (0.0,1.0,0.0, -ClipTopLeft.y()     + Graphics->getClipPlaneOffset()),
              BottomPlaneEquation(0.0,-1.0,0.0, ClipBottomRight.y() + Graphics->getClipPlaneOffset());

        //glClipPlane
        //Clip with the Intersection of this components RenderingSurface bounds
        //and its parents RenderingSurface bounds
        if(ClipBottomRight.x()-ClipTopLeft.x() <= 0 || ClipBottomRight.y()-ClipTopLeft.y()<= 0)
        {
            return false;
        }

        if(!glIsEnabled(GL_CLIP_PLANE0)) { glEnable(GL_CLIP_PLANE0); }
        if(!glIsEnabled(GL_CLIP_PLANE1)) { glEnable(GL_CLIP_PLANE1); }
        if(!glIsEnabled(GL_CLIP_PLANE2)) { glEnable(GL_CLIP_PLANE2); }
        if(!glIsEnabled(GL_CLIP_PLANE3)) { glEnable(GL_CLIP_PLANE3); }

        //Clip Plane Equations
        //Clip Planes get transformed by the ModelViewMatrix when set
        //So we can rely on the fact that our current coordinate space
        //is relative to the this components position

        glClipPlane(GL_CLIP_PLANE0,LeftPlaneEquation.getValues());
        glClipPlane(GL_CLIP_PLANE1,RightPlaneEquation.getValues());
        glClipPlane(GL_CLIP_PLANE2,TopPlaneEquation.getValues());
        glClipPlane(GL_CLIP_PLANE3,BottomPlaneEquation.getValues());
    }
    else
    {
        if(glIsEnabled(GL_CLIP_PLANE0)) { glDisable(GL_CLIP_PLANE0); }
        if(glIsEnabled(GL_CLIP_PLANE1)) { glDisable(GL_CLIP_PLANE1); }
        if(glIsEnabled(GL_CLIP_PLANE2)) { glDisable(GL_CLIP_PLANE2); }
        if(glIsEnabled(GL_CLIP_PLANE3)) { glDisable(GL_CLIP_PLANE3); }
    }
    return true;
}
示例#19
0
文件: drv_sdlgl.c 项目: adsr/agar
static void
SDLGL_PopClipRect(void *obj)
{
	AG_DriverSDLGL *sgl = obj;
	AG_ClipRect *cr;
	
#ifdef AG_DEBUG
	if (sgl->nClipRects < 1)
		AG_FatalError("PopClipRect() without PushClipRect()");
#endif
	cr = &sgl->clipRects[sgl->nClipRects-2];
	sgl->nClipRects--;

	glClipPlane(GL_CLIP_PLANE0, (const GLdouble *)&cr->eqns[0]);
	glClipPlane(GL_CLIP_PLANE1, (const GLdouble *)&cr->eqns[1]);
	glClipPlane(GL_CLIP_PLANE2, (const GLdouble *)&cr->eqns[2]);
	glClipPlane(GL_CLIP_PLANE3, (const GLdouble *)&cr->eqns[3]);
}
示例#20
0
void redraw()
{
	// Clear the screen and the depth buffer
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
    // Set matrices
    glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glOrtho(0, 640, 0, 480, -1, 1);
	glViewport(0, 0, 640, 480);
	glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
	
	// STAGE 0
	glClientActiveTextureARB( GL_TEXTURE0_ARB );
	glActiveTextureARB( GL_TEXTURE0_ARB );
	glBindTexture( GL_TEXTURE_2D, datatexID );
	glEnable( GL_TEXTURE_2D );
	
	glColor3f( 1.0, 1.0, 1.0 );
	
	GLdouble plane[4] = {1.0, 0.0, 0.0, 0.0};
	
	glClipPlane (GL_CLIP_PLANE0, plane);
    glEnable (GL_CLIP_PLANE0);
	
	if(enabled)
	{
		glUseProgramObjectARB( g_programObj );
		
		GLint texture = glGetUniformLocationARB( g_programObj, "OGL2Texture" );
		GLfloat param = glGetUniformLocationARB( g_programObj, "OGL2Param" );
		glUniform1iARB( texture, 0 );
		glUniform4fARB( param, 0, 0, brightness, 0 );
	}
	
	// Draw
	glBegin( GL_QUADS );
		glTexCoord2f( 0.0f, 0.0f );
		glVertex3f( 0.0f, 0.0f, 0.0f );
		glTexCoord2f( 1.0f, 0.0f );
		glVertex3f( 640.0f, 0.0f, 0.0f );
		glTexCoord2f( 1.0f, 1.0f );
		glVertex3f( 640.0f, 480.0f, 0.0f );
		glTexCoord2f( 0.0f, 1.0f );
		glVertex3f( 0.0f, 480.0f, 0.0f );
	glEnd();
	
	if(enabled)
	{
		glUseProgramObjectARB( NULL );
	}
	
	glDisable (GL_CLIP_PLANE0);
	
	glXSwapBuffers( dpy, win );
}
示例#21
0
static void
set_clip_plane (GLint plane_num,
		const float *vertex_a,
		const float *vertex_b)
{
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
  GLfloat plane[4];
#else
  GLdouble plane[4];
#endif
  GLfloat angle;
  CoglHandle framebuffer = _cogl_get_framebuffer ();
  CoglMatrixStack *modelview_stack =
    _cogl_framebuffer_get_modelview_stack (framebuffer);
  CoglMatrixStack *projection_stack =
    _cogl_framebuffer_get_projection_stack (framebuffer);
  CoglMatrix inverse_projection;

  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  _cogl_matrix_stack_get_inverse (projection_stack, &inverse_projection);

  /* Calculate the angle between the axes and the line crossing the
     two points */
  angle = atan2f (vertex_b[1] - vertex_a[1],
                  vertex_b[0] - vertex_a[0]) * (180.0/G_PI);

  _cogl_matrix_stack_push (modelview_stack);

  /* Load the inverse of the projection matrix so we can specify the plane
   * in screen coordinates */
  _cogl_matrix_stack_set (modelview_stack, &inverse_projection);

  /* Rotate about point a */
  _cogl_matrix_stack_translate (modelview_stack,
                                vertex_a[0], vertex_a[1], vertex_a[2]);
  /* Rotate the plane by the calculated angle so that it will connect
     the two points */
  _cogl_matrix_stack_rotate (modelview_stack, angle, 0.0f, 0.0f, 1.0f);
  _cogl_matrix_stack_translate (modelview_stack,
                                -vertex_a[0], -vertex_a[1], -vertex_a[2]);

  _cogl_matrix_stack_flush_to_gl (modelview_stack, COGL_MATRIX_MODELVIEW);

  plane[0] = 0;
  plane[1] = -1.0;
  plane[2] = 0;
  plane[3] = vertex_a[1];
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
  GE( glClipPlanef (plane_num, plane) );
#else
  GE( glClipPlane (plane_num, plane) );
#endif

  _cogl_matrix_stack_pop (modelview_stack);
}
示例#22
0
bool
test_clipping(enum mode m)
{
	bool pass = true;
	/* TODO: Implement MODE_NAN and MODE_DENORM */
	double plane[4];

	/* Start w/ nice values */
	plane[0] = plane[1] = plane[2] = plane[3] = 0.0;

	/* Set problematic values */
	switch (m) {
	case MODE_INFINITY:
		make_pos_inf_double(&plane[0]);
		make_neg_inf_double(&plane[3]);
		break;
	/*
	 * case MODE_NAN:
	 *	 make_signaling_nan_double(&plane[0]);
	 *	 make_quiet_nan_double(&plane[3]);
	 *	 break;
	 */
	case MODE_DIVZERO:
		/* nothing */
		break;
	/*
	 * case MODE_DENORM:
	 * 	 make_denorm_double(&plane[0], 0, 1);
	 * 	 make_denorm_double(&plane[3], 1, 1);
	 * 	 break;
	 */
	case MODE_OVERFLOW:
		plane[0] = 1.0e300;
		plane[3] = 1.0e-300;
		break;
	default:
		; /* nothing */
	}

	/* Send plane to GL to use for clipping */
	glClipPlane(GL_CLIP_PLANE0, plane);
	pass &= piglit_check_gl_error(GL_NO_ERROR);
	glEnable(GL_CLIP_PLANE0);

	/* Some vertex positions */
	glBegin(GL_POLYGON);
	glVertex2f(-1, -1);
	glVertex2f( 1, -1);
	glVertex2f( 0,  1);
	glEnd();
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	glDisable(GL_CLIP_PLANE0);

	return pass;
}
示例#23
0
void Eye::applyClippingPlanes()
{
	QMap<int,QVector4D>::const_iterator i = mClippingPlanes.constBegin();
	while( i != mClippingPlanes.constEnd() )
	{
		double plane[4]={ i.value().x(), i.value().y(), i.value().z(), i.value().w() };
		glClipPlane( GL_CLIP_PLANE0 + i.key(), plane );
		++i;
	}
}
示例#24
0
void shell(GLUquadricObj *quadObj)
{
    GLdouble plane[] = { 0.0, 0.0, 1.0, 0.0 };
    glClipPlane(GL_CLIP_PLANE0, plane);
 
    glEnable(GL_CLIP_PLANE0);
    glEnable(GL_TEXTURE_2D);
    gluSphere(quadObj, 1.0, 50, 50);
    glDisable(GL_CLIP_PLANE0);
}
示例#25
0
文件: Clipping.c 项目: xpika/winhugs
static void hugsprim_glClipPlane_0(HugsStackPtr hugs_root)
{
    HsWord32 arg1;
    HsPtr arg2;
    arg1 = hugs->getWord32();
    arg2 = hugs->getPtr();
    glClipPlane(arg1, arg2);
    
    hugs->returnIO(hugs_root,0);
}
示例#26
0
static void Display(GLvoid)									// Draw Everything
{
    // Clear Screen, Depth Buffer & Stencil Buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    // Clip Plane Equations
    double eqr[] = {0.0f,-1.0f, 0.0f, 0.0f};			// Plane Equation To Use For The Reflected Objects

    glLoadIdentity();									// Reset The Modelview Matrix
    glTranslatef(0.0f, -0.6f, zoom);					// Zoom And Raise Camera Above The Floor (Up 0.6 Units)
    glColorMask(0,0,0,0);								// Set Color Mask
    glEnable(GL_STENCIL_TEST);							// Enable Stencil Buffer For "marking" The Floor
    glStencilFunc(GL_ALWAYS, 1, 1);						// Always Passes, 1 Bit Plane, 1 As Mask
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);			// We Set The Stencil Buffer To 1 Where We Draw Any Polygon
    // Keep If Test Fails, Keep If Test Passes But Buffer Test Fails
    // Replace If Test Passes
    glDisable(GL_DEPTH_TEST);							// Disable Depth Testing
    DrawFloor();										// Draw The Floor (Draws To The Stencil Buffer)
    // We Only Want To Mark It In The Stencil Buffer
    glEnable(GL_DEPTH_TEST);							// Enable Depth Testing
    glColorMask(1,1,1,1);								// Set Color Mask to true, true, true, true
    glStencilFunc(GL_EQUAL, 1, 1);						// We Draw Only Where The Stencil Is 1
    // (I.E. Where The Floor Was Drawn)
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);				// Don't Change The Stencil Buffer
    glEnable(GL_CLIP_PLANE0);							// Enable Clip Plane For Removing Artifacts
    // (When The Object Crosses The Floor)
    glClipPlane(GL_CLIP_PLANE0, eqr);					// Equation For Reflected Objects
    glPushMatrix();										// Push The Matrix Onto The Stack
    glScalef(1.0f, -1.0f, 1.0f);					// Mirror Y Axis
    glLightfv(GL_LIGHT0, GL_POSITION, LightPos);	// Set Up Light0
    glTranslatef(0.0f, height, 0.0f);				// Position The Object
    glRotatef(xrot, 1.0f, 0.0f, 0.0f);				// Rotate Local Coordinate System On X Axis
    glRotatef(yrot, 0.0f, 1.0f, 0.0f);				// Rotate Local Coordinate System On Y Axis
    DrawObject();									// Draw The Sphere (Reflection)
    glPopMatrix();										// Pop The Matrix Off The Stack
    glDisable(GL_CLIP_PLANE0);							// Disable Clip Plane For Drawing The Floor
    glDisable(GL_STENCIL_TEST);							// We Don't Need The Stencil Buffer Any More (Disable)
    glLightfv(GL_LIGHT0, GL_POSITION, LightPos);		// Set Up Light0 Position
    glEnable(GL_BLEND);									// Enable Blending (Otherwise The Reflected Object Wont Show)
    glDisable(GL_LIGHTING);								// Since We Use Blending, We Disable Lighting
    glColor4f(1.0f, 1.0f, 1.0f, 0.8f);					// Set Color To White With 80% Alpha
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	// Blending Based On Source Alpha And 1 Minus Dest Alpha
    DrawFloor();										// Draw The Floor To The Screen
    glEnable(GL_LIGHTING);								// Enable Lighting
    glDisable(GL_BLEND);								// Disable Blending
    glTranslatef(0.0f, height, 0.0f);					// Position The Ball At Proper Height
    glRotatef(xrot, 1.0f, 0.0f, 0.0f);					// Rotate On The X Axis
    glRotatef(yrot, 0.0f, 1.0f, 0.0f);					// Rotate On The Y Axis
    DrawObject();										// Draw The Ball
    xrot += xrotspeed;									// Update X Rotation Angle By xrotspeed
    yrot += yrotspeed;									// Update Y Rotation Angle By yrotspeed
    glFlush();											// Flush The GL Pipeline

    glutSwapBuffers();
}
示例#27
0
void display(void){
    GLdouble eqn0[4] = {0.0, 1.0, 0.0, 0.0}; // plane y = 0
    GLdouble eqn1[4] = {1.0, 1.0, 0.0, 0.0}; // plane x + y = 0
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    glTranslatef(0.0, 0.0, -5.0);

    // отсекаем нижнюю половину y < 0
    glClipPlane(GL_CLIP_PLANE0, eqn0);
    glEnable(GL_CLIP_PLANE0);
   
    // отсекаем нижнюю половину x < 0
    glClipPlane(GL_CLIP_PLANE1, eqn1);
    glEnable(GL_CLIP_PLANE1);

    glRotatef(90.0, 1.0, 0.0, 0.0);
    glutWireSphere(1.0, 20, 16);
    glFlush();
}
示例#28
0
void Scene :: DrawHorizontalGirder(double start_value)
{
  GLfloat mat_ambient[] = {0.4, 0.4, 0.4, 1.0};
  GLfloat mat_diffuse[] = {0.4, 0.4, 0.4, 1.0};
  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

  GLdouble y_clip_pane1[4] = {0.0, 1.0, 0.0, -start_value};
  GLdouble y_clip_pane2[4] = {0.0, -1.0, 0.0, start_value + 25};

  glClipPlane(GL_CLIP_PLANE1, y_clip_pane1);
  glClipPlane(GL_CLIP_PLANE2, y_clip_pane2);
  glEnable(GL_CLIP_PLANE1);
  glEnable(GL_CLIP_PLANE2);

  glutSolidSphere(1000, 20, 20);

  glDisable(GL_CLIP_PLANE1);
  glDisable(GL_CLIP_PLANE2);
}  // DrawHorizontalGirder
示例#29
0
void enable_vertical_clipping_plane(bsp_t *bsp)
{
	float max_z = bsp->models[0].maxs[2];
	float min_z = bsp->models[0].mins[2];
	double plane[4] = {0.0, 0.0, -1.0, 0.0};
	glPushMatrix();
	glEnable(GL_CLIP_PLANE0);
	glTranslatef(0.0, 0.0, max_z * config.clip_height);
	glClipPlane(GL_CLIP_PLANE0, plane);
	glPopMatrix();
}
示例#30
0
文件: Main.cpp 项目: liminl789/OpenGL
void display(void)
{
	GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0};
	GLdouble eqn2[4] = {1.0, 0.0, 0.0, 0.0};

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

	glClipPlane(GL_CLIP_PLANE0, eqn);
	glEnable(GL_CLIP_PLANE0);

	glClipPlane(GL_CLIP_PLANE1, eqn2);
	glEnable(GL_CLIP_PLANE1);

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