Example #1
0
void HPoint::glCommands(bool select, bool marked, bool no_color)
{
	if(!no_color){
		wxGetApp().glColorEnsuringContrast(color);
	}
	GLfloat save_depth_range[2];
	if(marked){
		glGetFloatv(GL_DEPTH_RANGE, save_depth_range);
		glDepthRange(0, 0);
	}
	else if(!m_draw_unselected)
	{
		glBegin(GL_POINTS);
		glVertex3d(m_p.X(), m_p.Y(), m_p.Z());
		glEnd();
		return;
	}


	glRasterPos3d(m_p.X(), m_p.Y(), m_p.Z());
	glBitmap(16, 16, 8, 8, 10.0, 0.0, marked ? cross16_selected : cross16);
	if(marked){
		glDepthRange(save_depth_range[0], save_depth_range[1]);
	}
}
Example #2
0
/*
=============
R_DrawViewModel -- johnfitz -- gutted
=============
*/
void R_DrawViewModel (void)
{
	if (!r_drawviewmodel.value || !r_drawentities.value || chase_active.value)
		return;

	if (cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0)
		return;

	if (vr_enabled.value && vr_crosshair.value)
		VR_ShowCrosshair();

	currententity = &cl.viewent;
	if (!currententity->model)
		return;

	//johnfitz -- this fixes a crash
	if (currententity->model->type != mod_alias)
		return;
	//johnfitz

	// hack the depth range to prevent view model from poking into walls
	glDepthRange (0, 0.3);
	R_DrawAliasModel (currententity);
	glDepthRange (0, 1);
}
Example #3
0
void R_DrawSkyChain (msurface_t *surf)
{
	msurface_t *reversechain = NULL;
	int numindexes = 0;

	if (!surf) return;

	// push the depth range back to far end of the z-buffer
	// rogue has some pretty - unusual - brush placement and needs this
	glDepthRange (gldepthmax, gldepthmax);
	glProgramUniformMatrix4fv (gl_skycubeprog, u_skylocalMatrix, 1, GL_FALSE, r_mvpmatrix.m[0]);
	glEnable (GL_TEXTURE_CUBE_MAP_SEAMLESS);

	GL_UseProgram (gl_skycubeprog);
	GL_BindTexture (GL_TEXTURE0, GL_TEXTURE_CUBE_MAP, r_skysampler, r_skytexture);
	GL_Enable (DEPTHTEST_BIT | (gl_cull->value ? CULLFACE_BIT : 0));

	for (; surf; surf = surf->texturechain)
	{
		surf->reversechain = reversechain;
		reversechain = surf;
		numindexes += surf->numindexes;
	}

	R_DrawSurfaceChain (reversechain, numindexes);

	glDepthRange (gldepthmin, gldepthmax);
	glDisable (GL_TEXTURE_CUBE_MAP_SEAMLESS);
}
Example #4
0
// 使用OpenGL來繪圖
void RenderFrameOpenGL(void)
{
	Vector4 vPlane(0.0f, 0.0f, 1.0f, -g_mirror_z);

	// 清除畫面
	glClearColor(0.0f, 0.0f, 0.5f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	// 畫出茶壼
	RenderModelOpenGL(false, NULL);
	// 設定轉換矩陣
	Matrix4x4 view_matrix = g_Control.GetViewMatrix();;
	Matrix4x4 world_view_matrix = view_matrix;

	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf( (float *) &g_projection_matrix);

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf( (float *) &world_view_matrix);

	sModelMaterial_OpenGL material;
	material.Submit(NULL);
	// 設定頂點資料格式
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(Vertex_V), &g_Quad_v[0].m_Position);

	// 畫出鏡子, 同時把鏡子部分的stencil buffer設為1.
	{
		glEnable(GL_STENCIL_TEST);
		glStencilFunc(GL_ALWAYS, 1, 0xff);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	}
	// 把鏡子部分的zbuffer清為1.0
	{
		glStencilFunc(GL_EQUAL, 1, 0xff);
		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		// 把z值的輸出范圍設定為1~1, 也就是z永遠輸出1.
		glDepthRange(1.0f, 1.0f);
		glDepthFunc(GL_ALWAYS);
		// 只更新zbuffer,不需要更新顏色.
		glColorMask(false, false, false, false);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		// 恢復更新顏色的功能
		glColorMask(true, true, true, true);
		glDepthFunc(GL_LESS);
		// 把z值的范圍還原為0~1
		glDepthRange(0.0f, 1.0f);
	}
	// 畫出鏡子里的茶壼
	{
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		RenderModelOpenGL(true, &vPlane);
		glDisable(GL_STENCIL_TEST);
	}
	// 把背景backbuffer的畫面呈現出來
	GutSwapBuffersOpenGL();
}
static void MyDisplay( void )
{
	static int starttime, stoptime;
	starttime = glutGet( GLUT_ELAPSED_TIME );

    glViewport( 0, 0, winWidth, winHeight );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0, (double)winWidth/winHeight, model.radius, 10.0 * model.radius );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslated( 0.0, 0.0, -2.5 * model.radius );
	glPushMatrix();
		tb.applyTransform();
		glTranslatef( -model.center[0], -model.center[1], -model.center[2] );

		glDepthRange( DEPTH_OFFSET, 1.0 );  // This is for outlined fill.

		// Draw axes.
		if ( drawAxes ) DrawAxes( 2.0 * model.radius );

		if ( drawStyle == 0 || drawStyle == 2 ) 
			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );	// Filled or outlined fill.
		else
			glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );	// Wireframe.

		glCallList( gathererQuadsDList );	// Draw gatherer quads.

		if ( drawStyle == 2 )	// Draw the outlines of the outlined fill style.
		{
			glPushAttrib( GL_ALL_ATTRIB_BITS );
			glDisable( GL_LIGHTING );
			glDepthFunc( GL_LEQUAL );
			glDepthRange( 0.0, 1.0 - DEPTH_OFFSET );
			glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );	// Wireframe.
			glLineWidth( 1.0 );
			glColor3f( 0.0f, 0.0f, 0.0f );
			glCallList( gathererQuadsNoColorDList );	// Draw gatherer quads.
			glPopAttrib();
		}

	glPopMatrix();

    glutSwapBuffers();

	stoptime = glutGet( GLUT_ELAPSED_TIME );
	double fps = 1.0 / ((stoptime - starttime) / 1000.0);

	static char s[256];
	sprintf( s, "Radiosity Viewer  (%.1f FPS)", fps );
	glutSetWindowTitle( s );
}
Example #6
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	int x, y;
	static float red[]   = {1.0, 0.0, 0.0, 0.0};
	static float green[] = {0.0, 1.0, 0.0, 0.0};

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glEnable(GL_DEPTH_TEST);

	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glColor4fv(red);

	glClearDepth(0.5);
	glClear(GL_DEPTH_BUFFER_BIT);
	draw_rect_set(10);

	glDepthRange(0.5, 1.0);
	glClearDepth(0.5);
	glClear(GL_DEPTH_BUFFER_BIT);
	glDepthRange(0.0, 1.0);
	draw_rect_set(30);

	glDepthRange(0.0, 0.5);
	glClearDepth(0.5);
	glClear(GL_DEPTH_BUFFER_BIT);
	glDepthRange(0.0, 1.0);
	draw_rect_set(50);

	for (y = 0; y < 3; y++) {
		for (x = 0; x < 4; x++) {
			float *expected;

			if (x < 2)
				expected = green;
			else
				expected = red;

			pass &= piglit_probe_pixel_rgb(15 + x * 20, 15 + y * 20,
						       expected);
		}
	}

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
void MouseCursorFaker::glRenderActionTransparent(GLContextData& contextData) const
	{
	/* Get the data item: */
	DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);
	
	/* Calculate the device's ray equation: */
	Ray deviceRay(device->getPosition(),device->getRayDirection());
	
	/* Find the nearest screen intersected by the device ray: */
	std::pair<VRScreen*,Scalar> fsResult=findScreen(deviceRay);
	if(fsResult.first!=0)
		{
		/* Calculate the cursor position on the screen: */
		Point cursorPos=deviceRay(fsResult.second);
		Vector x=fsResult.first->getScreenTransformation().getDirection(0)*cursorSize[0];
		Vector y=fsResult.first->getScreenTransformation().getDirection(1)*cursorSize[1];
		cursorPos-=x*cursorHotspot[0];
		cursorPos-=y*cursorHotspot[1];
		
		/* Draw the mouse cursor: */
		glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT);
		GLdouble depthRange[2];
		glGetDoublev(GL_DEPTH_RANGE,depthRange);
		glDepthRange(0.0,0.0);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId);
		glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GEQUAL,0.5f);
		glDisable(GL_BLEND);
		glDepthMask(GL_TRUE);
		glBegin(GL_QUADS);
		glTexCoord(cursorTexCoordBox.getVertex(0));
		glVertex(cursorPos);
		glTexCoord(cursorTexCoordBox.getVertex(1));
		cursorPos+=x;
		glVertex(cursorPos);
		glTexCoord(cursorTexCoordBox.getVertex(3));
		cursorPos+=y;
		glVertex(cursorPos);
		glTexCoord(cursorTexCoordBox.getVertex(2));
		cursorPos-=x;
		glVertex(cursorPos);
		glEnd();
		glBindTexture(GL_TEXTURE_2D,0);
		glDepthRange(depthRange[0],depthRange[1]);
		glPopAttrib();
		}
	}
Example #8
0
void QSceneWidget::resizeGL(int width, int height)
{
  //makeCurrent();
  glViewport(0, 0, width, height);
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glDepthRange(0.0f, 1.0f);
  glClearDepth(1.0f);
  
  double znear = 0.1;
  double zfar = 500.0;
  double aspect = (double)width / (double)height;
  double fov = 90.0 / aspect;
#if !defined(QT_OPENGL_ES_2)
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  const double DEG2RAD = 3.14159265 / 180;

  double tangent = tan(fov/2 * DEG2RAD);   // tangent of half fovY
  double h = znear * tangent;          // half height of near plane
  double w = h * aspect;      // half width of near plane
  // params: left, right, bottom, top, near, far
  glFrustum(-w, w, -h, h, znear, zfar);
#else
  perspectiveMatrix.setToIdentity();
  perspectiveMatrix.perspective(fov, aspect, znear, zfar);
  std::cout << "OpenGL ES 2" << std::endl;
  glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
#endif
  glMatrixMode(GL_MODELVIEW);
}
/*-----------------------------------------------------------------------------------------------
Description:
    Governs window creation, the initial OpenGL configuration (face culling, depth mask, even
    though this is a 2D demo and that stuff won't be of concern), the creation of geometry, and
    the creation of a texture.
Parameters:
    argc    (From main(...)) The number of char * items in argv.  For glut's initialization.
    argv    (From main(...)) A collection of argument strings.  For glut's initialization.
Returns:
    False if something went wrong during initialization, otherwise true;
Exception:  Safe
Creator:    John Cox (3-7-2016)
-----------------------------------------------------------------------------------------------*/
void Init()
{
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);

    GLuint particleProgramId = GenerateVertexShaderProgram();
    GLuint computeProgramId = GenerateComputeShaderProgram();

    // all values are in windows space (X and Y limited to [-1,+1])
    // Note: Toy with the values as you will.
    //unsigned int totalParticles = 20000;
    unsigned int totalParticles = 600000;
    unsigned int maxParticlesEmittedPerFrame = 200;
    glm::vec2 center = glm::vec2(+0.3f, +0.3f);
    float radius = 1.1f;
    float minVelocity = 0.05f;
    float maxVelocity = 0.6f;
    gParticleManager.Init(particleProgramId,
        computeProgramId,
        totalParticles,
        maxParticlesEmittedPerFrame,
        center,
        radius, 
        minVelocity, 
        maxVelocity);
}
/*-----------------------------------------------------------------------------------------------
Description:
    Governs window creation, the initial OpenGL configuration (face culling, depth mask, even
    though this is a 2D demo and that stuff won't be of concern), the creation of geometry, and
    the creation of a texture.
Parameters:
    argc    (From main(...)) The number of char * items in argv.  For glut's initialization.
    argv    (From main(...)) A collection of argument strings.  For glut's initialization.
Returns:
    False if something went wrong during initialization, otherwise true;
Exception:  Safe
Creator:    John Cox (3-7-2016)
-----------------------------------------------------------------------------------------------*/
void Init()
{
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CCW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);

    gProgramId = GenerateShaderProgram();
    gUnifMatrixTransform = glGetUniformLocation(gProgramId, "translateMatrixWindowSpace");
    gUnifTextureSampler = glGetUniformLocation(gProgramId, "tex");

    GenerateTriangle(&gTriangle);
    GenerateBox(&gBox);
    GenerateCircle(&gCircle);
    InitializeGeometry(gProgramId, &gTriangle);
    InitializeGeometry(gProgramId, &gBox);
    InitializeGeometry(gProgramId, &gCircle);

    gTexture1Id = CreateRandom3BeamTexture();
    gTexture2Id = CreateRandom3BeamTexture();
    gTexture3Id = CreateRandom3BeamTexture();

    // the textures all share the same properties, so I'll use the same sampler for all
    gSamplerId = CreateGenericSampler();
}
Example #11
0
void init(void){
//Erase the window and the depth buffer
	glClearColor(0.0f, 0.88f, 1.0f, 1.0f);
	//Enable Z-buffering in OpenGL
	glEnable(GL_DEPTH_TEST);
	glDepthRange(0.0, 1.0);  /* The default z mapping */
}
Example #12
0
/*!
    \internal
*/
void QGLView::initializeGL()
{
    d->logEnter("QGLView::initializeGL");
    QGLPainter painter;
    painter.begin();

    // Set the default depth buffer options.
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif

    // Set the default blend options.
    if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendColor))
        painter.glBlendColor(0, 0, 0, 0);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendEquation))
        painter.glBlendEquation(GL_FUNC_ADD);
    else if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate))
        painter.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);

    glDisable(GL_CULL_FACE);
    initializeGL(&painter);
    d->logLeave("QGLView::initializeGL");
}
Example #13
0
Display::Display(int width, int height, const std::string& title) {
    
    if (!glfwInit()) {
        throw -1;
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    window_ = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
    //window_ = glfwCreateWindow(width, height, title.c_str(), glfwGetPrimaryMonitor(), NULL);
    
    if (!window_) {
        glfwTerminate();
        
        throw Exception("GLFW window could not be created");
    }
    
    glfwMakeContextCurrent(window_);
    glfwSwapInterval(1);
    
    glClearColor(0.f, 0.f, 0.f, 0.f);
    glClearDepth(1.0f);
    glFrontFace(GL_CW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glDepthRange(0.0f, 1.0f);
}
Example #14
0
GLUSboolean init()
{
    g_program = loadProgram("./position_texture.vert", "./texture_color.frag");

    g_pCorridor = new Mesh("./model/Corridor.xml");
    g_pPlane = new Mesh("./model/BigPlane.xml");

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    const float depthZNear = 0.0f;
    const float depthZFar = 1.0f;

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(depthZNear, depthZFar);
    glEnable(GL_DEPTH_CLAMP);

    glGenBuffers(1, &g_projectionUniformBuffer);
    glBindBuffer(GL_UNIFORM_BUFFER, g_projectionUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, sizeof(ProjectionBlock), NULL, GL_DYNAMIC_DRAW);

    glBindBufferRange(GL_UNIFORM_BUFFER, g_projectionBlockIndex, g_projectionUniformBuffer,
            0, sizeof(ProjectionBlock));

    glBindBuffer(GL_UNIFORM_BUFFER, 0);

    initCheckerTexture();
    initdMipmapTexture();
    initSamplers();

    return GLUS_TRUE;
}
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
    InitializeProgram();

    try
    {
        coneMesh = new Framework::Mesh("UnitConeTint.xml");
        cylinderMesh = new Framework::Mesh("UnitCylinderTint.xml");
        cubeTintMesh = new Framework::Mesh("UnitCubeTint.xml");
        cubeColorMesh = new Framework::Mesh("UnitCubeColor.xml");
        planeMesh = new Framework::Mesh("UnitPlane.xml");
    }
    catch(std::exception &except)
    {
        printf("%s\n", except.what());
        throw;
    }

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);
    glEnable(GL_DEPTH_CLAMP);
}
Example #16
0
int main(int argc, char** argv){
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
	glutInitWindowSize( 600, 600);
	glutCreateWindow( "Demo" );

	glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
	glEnable( GL_DEPTH_TEST );
	glDepthRange(0.0, 1.0);
	glDepthFunc(GL_LEQUAL);

	setCubes();

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );
	glFrontFace(GL_CCW);
	glEnable(GL_NORMALIZE);
	glutKeyboardFunc( keyboardDown );
	glutReshapeFunc( reshape );
	glutDisplayFunc( display );
	glutTimerFunc(16, update, 0);
	glutMainLoop( );
	return(0);
}
Example #17
0
static void
fboEpilogue (CompScreen *s)
{
    (*s->bindFramebuffer) (GL_FRAMEBUFFER_EXT, 0);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    glDepthRange (0, 1);
    glViewport (-1, -1, 2, 2);
    glRasterPos2f (0, 0);

    s->rasterX = s->rasterY = 0;

    setDefaultViewport (s);

    glMatrixMode (GL_PROJECTION);
    glPopMatrix ();
    glMatrixMode (GL_MODELVIEW);
    glPopMatrix ();

    glDrawBuffer (GL_BACK);
    glReadBuffer (GL_BACK);
}
Example #18
0
void init(void){
	gouraudShading = createShaderProgram("vertexShaderSource.vert","fragmentShaderSource.frag", g_projectionBlockIndex);
	if(gouraudShading->linkStatus == GL_FALSE)
		exit(0);
	initWireRect();

	setPrespectiveProjection();
	genUniformBuffer();

	loadLights();

	gLoadIdentity();
	gSaveTop(orientationMatrix);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_DEPTH_CLAMP);

	objectsArray = (meshObject**)malloc(sizeof(meshObject*) * MAX_OBJECTS);
	loadPointMeshFile();
	loadPointMeshFile();
	userDefinedSegmentVertex = createArrayListf();
	userDefinedSegmentColor = createArrayListui();
	setMarkingColor();
}
Example #19
0
void sa::MeshRenderer::init() {
	glClearColor(0.2f, 0.3f, 0.5f, 1.0f);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LESS);
	glDepthRange(0, 1);
	glClearDepth(1);
	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	m_rectangle = PolygonTesselator<vec3<float>>().tesselate(Shape::makeBox(2.f));
	m_rectangle->build();

	sa::vec4<float> uvLimits = sa::TextureHandler::getSingleton().textureLimits("Empty", vec4<float>(0.5f, 0.5f, 1.0f, 1.0f));
	m_line = PolygonTesselator<vec3<float>>().tesselate(Shape::makeBox(1.f), uvLimits);
	m_line->build();
	
	std::shared_ptr<Shader> shader2d = m_shaders->loadShader("renderer2d", "../shaders/2d_shader_130.vs.glsl", "../shaders/2d_shader_130.fs.glsl");
	m_shaders->switchToShader("renderer2d");

	m_modelUniform = shader2d->uniform("model");
	m_viewUniform  = shader2d->uniform("view");
	m_projectionUniform = shader2d->uniform("projection");
	m_colorUniform = shader2d->uniform("color");

	m_texSamplerUniform = shader2d->uniform("tex");
	glUniform1i(m_texSamplerUniform, 0);
}
Example #20
0
/*!
    \internal
*/
void QGLView::initializeGL()
{
    d->logEnter("QGLView::initializeGL");
    QGLPainter painter;
    painter.begin();

    // Set the default depth buffer options.
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif

    // Set the default blend options.
    qt_gl_BlendColor(0, 0, 0, 0);
    qt_gl_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    qt_gl_BlendEquation(GL_FUNC_ADD);

    painter.setCullFaces(QGL::CullDisabled);
    initializeGL(&painter);
    d->logLeave("QGLView::initializeGL");
}
Example #21
0
/*
 * OpenGL implementation of glWindowPos*MESA()
 */
void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
{
   GLfloat fx, fy;

   /* Push current matrix mode and viewport attributes */
   glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );

   /* Setup projection parameters */
   glMatrixMode( GL_PROJECTION );
   glPushMatrix();
   glLoadIdentity();
   glMatrixMode( GL_MODELVIEW );
   glPushMatrix();
   glLoadIdentity();

   glDepthRange( z, z );
   glViewport( (int) x - 1, (int) y - 1, 2, 2 );

   /* set the raster (window) position */
   fx = x - (int) x;
   fy = y - (int) y;
   glRasterPos4f( fx, fy, 0.0, w );

   /* restore matrices, viewport and matrix mode */
   glPopMatrix();
   glMatrixMode( GL_PROJECTION );
   glPopMatrix();

   glPopAttrib();
}
Example #22
0
//------------------------------------------------------------------------------
int main(int argc, char **argv ){
    // init GLUT and create Window
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
    glutInitWindowSize( 320, 320 );
    glutCreateWindow( "Onion World" );

    initializeProgram();
    initializeVertexBuffer();
    initializeVertexArrayObjects();

    glEnable( GL_CULL_FACE );
    glCullFace( GL_BACK );
    glFrontFace( GL_CW );

    glEnable( GL_DEPTH_TEST );
    glDepthMask( GL_TRUE );
    glDepthFunc( GL_LEQUAL );
    glDepthRange( 0.0, 1.0f );

    // register callbacks
    glutDisplayFunc( renderScene );
    glutReshapeFunc( reshape );
    glutKeyboardFunc( keyPressed );
    glutMainLoop();

    return EXIT_SUCCESS;
}
Example #23
0
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
	InitializeProgram();

	try
	{
		for(int iLoop = 0; iLoop < 3; iLoop++)
		{
			g_Gimbals[iLoop] = new Framework::Mesh(g_strGimbalNames[iLoop]);
		}

		g_pObject = new Framework::Mesh("Ship.xml");
	}
	catch(std::exception &except)
	{
		printf("%s\n", except.what());
		throw;
	}


	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
}
Example #24
0
void init(void)
{
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_FLAT);
   glDepthRange(0.0, 1.0);  /* The default z mapping */
}
Example #25
0
void GLWidget::EnableDepthOverlay()
{
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);
}
Example #26
0
/*!
  The draw function for the viewport sets up all of the lighting parameters for the scene before
  iterating through the top level items in the scene and drawing them using \a painter.

  As a matter of course each item will draw its child items, and so on, until the entire image has
  been populated.
*/
void Viewport::draw(QGLPainter *painter)
{
    // Set up the initial depth, blend, and other options.
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif
    painter->setBlendingEnabled(d->blending);
    qt_gl_BlendColor(0, 0, 0, 0);
    qt_gl_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    qt_gl_BlendEquation(GL_FUNC_ADD);
    painter->setCullFaces(QGL::CullDisabled);
    if (!d->view)
        painter->setPicking(d->showPicking);

    painter->setObjectPickId(-1);
    QObjectList list = QObject::children();    
    bool haveLights = false;
    foreach (QObject *child, list) {
        QGLLightParameters *light = qobject_cast<QGLLightParameters *>(child);
        if (light) {
            painter->setMainLight(light, QMatrix4x4());
            break;
        }
    }
Example #27
0
void reset_opengl_state()
{
	glShadeModel(GL_SMOOTH);
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
#if !defined(USE_SHADERS)
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
#endif

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

#if defined(USE_SHADERS)
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glClearColor(0.0,0.0,0.0,0.0);
	gles2::init_default_shader();
#else
	glColor4ub(255,255,255,255);
#endif
	glDepthFunc(GL_LEQUAL);
	glDepthMask(GL_TRUE);
	glDepthRange(0.0f, 1.0f);
	glClearDepth(1.0);
}
Example #28
0
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
	InitializeProgram();
	InitializeVertexBuffer();

	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	size_t colorDataOffset = sizeof(float) * 3 * numberOfVertices;
	glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)colorDataOffset);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);

	glBindVertexArray(0);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LESS);
	glDepthRange(0.0f, 1.0f);
}
void MapNode::restoreDefaults(QGLPainter *painter)
{
    // Disable the effect to return control to the GL paint engine.
    painter->disableEffect();

    // Try to restore the default options
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    // Set the default depth buffer options.
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif
    // Set the default blend options.
    glDisable(GL_BLEND);
    if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendColor))
        painter->glBlendColor(0, 0, 0, 0);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendEquation))
        painter->glBlendEquation(GL_FUNC_ADD);
    else if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate))
        painter->glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
}
Example #30
0
void _scene_base::initilize_scene (void) {
	glClearColor( 0.6f, 0.0f, 0.6f, 1.0f );
	glEnable( GL_DEPTH_TEST );
	glDepthRange( 0.0f, 1.0f );
	glFrontFace( GL_CCW );
	//cull face
	glEnable( GL_CULL_FACE );
	glCullFace( GL_BACK );

	//
	/* GLenum err = glewInit (); */
        /* if( err != GLEW_OK ) { */
	/* 	cout << glewGetErrorString( err ) << endl; */
	/* 	exit( 1 ); */
        /* } */
	//need initilize_shader
	//

	_light_base_set_in_scene = std::make_shared<_light_base_set>();
	_controller_in_scene = std::make_shared<_controller_base>();
	//initilize the physics world
	_collision_configuration = std::make_shared<btDefaultCollisionConfiguration>();
	_dispatcher = std::make_shared<btCollisionDispatcher>( _collision_configuration.get() );
	_broadphase = std::make_shared<btDbvtBroadphase>();
	_solver = std::make_shared<btSequentialImpulseConstraintSolver>();
	_physics_world = std::make_shared<btDiscreteDynamicsWorld>(	_dispatcher.get(),
									_broadphase.get(),
									_solver.get(),
									_collision_configuration.get() );
}	//initilize_scene