void SAssPiece::DrawForList() const
{
	if (isEmpty) {
		return;
	}
	LOG_SL(LOG_SECTION_PIECE, L_DEBUG, "Compiling piece %s", name.c_str());
	//! Add GL commands to the pieces displaylist

	const SAssVertex* sAssV = &vertices[0];

	//! pass the tangents as 3D texture coordinates
	//! (array elements are float3's, which are 12
	//! bytes in size and each represent a single
	//! xyz triple)
	//! TODO: test if we have this many texunits
	//! (if not, could only send the s-tangents)?

	if (!sTangents.empty()) {
		glClientActiveTexture(GL_TEXTURE5);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(3, GL_FLOAT, sizeof(float3), &sTangents[0].x);
	}
	if (!tTangents.empty()) {
		glClientActiveTexture(GL_TEXTURE6);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(3, GL_FLOAT, sizeof(float3), &tTangents[0].x);
	}

	glClientActiveTexture(GL_TEXTURE0);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, sizeof(SAssVertex), &sAssV->textureX);

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(SAssVertex), &sAssV->pos.x);

	glEnableClientState(GL_NORMAL_ARRAY);
	glNormalPointer(GL_FLOAT, sizeof(SAssVertex), &sAssV->normal.x);

	/*
	 * since aiProcess_SortByPType is being used,
	 * we're sure we'll get only 1 type here,
	 * so combination check isn't needed, also
	 * anything more complex than triangles is
	 * being split thanks to aiProcess_Triangulate
	 */
	glDrawElements(GL_TRIANGLES, vertexDrawOrder.size(), GL_UNSIGNED_INT, &vertexDrawOrder[0]);

	if (!sTangents.empty()) {
		glClientActiveTexture(GL_TEXTURE6);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}
	if (!tTangents.empty()) {
		glClientActiveTexture(GL_TEXTURE5);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}

	glClientActiveTexture(GL_TEXTURE0);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	LOG_SL(LOG_SECTION_PIECE, L_DEBUG, "Completed compiling piece %s",
			name.c_str());
}
Example #2
0
//Set up openGL
bool GLInit()
{
	//set viewport
	int height = 480;
	int width = 640;

	
	glViewport(0, 0, width, height);					//reset viewport

	//set up projection matrix
	glMatrixMode(GL_PROJECTION);							//select projection matrix
	glLoadIdentity();										//reset
	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f);
	
	//load identity modelview
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//other states
	//shading
	glShadeModel(GL_SMOOTH);
	glClearColor(	backgroundColor.r,
					backgroundColor.g,
					backgroundColor.b,
					backgroundColor.a);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	//depth
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	//hints
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	//Set up vertex arrays for torus
	//Fixed 17th November 2002
	//Instead of passing tangents as texture coords 1 and 2, use aliased attributes 9 and 10.
	//This way, these texture coordinates will reach the vertex program on a geforce 2
	//which only has 2 texture units.
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].position);

	glEnableClientState(GL_NORMAL_ARRAY);
	glNormalPointer(GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].normal);

	//Pass texture coords to unit 0
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].s);

	//Pass tangent,binormal to attributes 9, 10
	glEnableClientState(GL_VERTEX_ATTRIB_ARRAY9_NV);
	glVertexAttribPointerNV(9, 3, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].sTangent);
	
	glEnableClientState(GL_VERTEX_ATTRIB_ARRAY10_NV);
	glVertexAttribPointerNV(10, 3, GL_FLOAT, sizeof(TORUS_VERTEX), &torus.vertices[0].tTangent);
	
	//Use compiled vertex arrays
	glLockArraysEXT(0, torus.numVertices);


	//Load vertex programs
	glGenProgramsNV(1, &singlePassVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, singlePassVertexProgram);
	LoadNV_vertex_program("single pass vertex program.txt", singlePassVertexProgram);

	glGenProgramsNV(1, &diffuseDecalVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, diffuseDecalVertexProgram);
	LoadNV_vertex_program("diffuse decal vertex program.txt", diffuseDecalVertexProgram);

	glGenProgramsNV(1, &lookUpSpecularVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, lookUpSpecularVertexProgram);
	LoadNV_vertex_program("look up specular vertex program.txt", lookUpSpecularVertexProgram);

	glGenProgramsNV(1, &diffuseVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, diffuseVertexProgram);
	LoadNV_vertex_program("diffuse vertex program.txt", diffuseVertexProgram);
	
	glGenProgramsNV(1, &decalVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, decalVertexProgram);
	LoadNV_vertex_program("decal vertex program.txt", decalVertexProgram);

	glGenProgramsNV(1, &simpleSpecularVertexProgram);
	glBindProgramNV(GL_VERTEX_PROGRAM_NV, simpleSpecularVertexProgram);
	LoadNV_vertex_program("simple specular vertex program.txt", simpleSpecularVertexProgram);

	//Set Tracking Matrix
	//Modelview Projection in registers c[0]-c[3]
	glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);

	return true;
}
Example #3
0
void DrawVolumeUsingCurrentDisplayMode(void)
{
    if (use_arrays)
    {
        if (regenerate_arrays == 1)
        {
            printf("Filling vertex/normal arrays... ");
            fflush(stdout);

            ClearArrays();

            switch (display_mode)
            {
            case 0:
                FillArrayWithPoints();
                break;
            case 1:
                FillArrayWithCubes();
                break;
            case 2:
                FillArrayWithIsosurface();
                break;
            }

            printf("done, %d array vertices used (1 per point, 4 per quad, 3 per triangle)\n", num_vertices_in_array);

            regenerate_arrays = 0;
        }

        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 0, vertices);

        if (display_mode > 0)
        {
            glEnableClientState(GL_NORMAL_ARRAY);
            glNormalPointer(GL_FLOAT, 0, normals);
        }
    }

    glColor3f(0.6, 0.0, 0.0);

    if (display_mode == 0)
        glDisable(GL_LIGHTING);
    else
        glEnable(GL_LIGHTING);

    if (display_mode == 0)
    {
        /* points */
        glPointSize(8.0);
        if (use_arrays)
            glDrawArrays(GL_POINTS, 0, num_vertices_in_array);
        else
            DrawVolumeAsPoints();
    }
    else if (display_mode == 1)
    {
        /* cubes */
        if (use_arrays)
            glDrawArrays(GL_QUADS, 0, num_vertices_in_array);
        else
        {
            glEnable(GL_RESCALE_NORMAL);
            DrawVolumeAsCubes();
            glDisable(GL_RESCALE_NORMAL);
        }
    }
    else if (display_mode == 2)
    {
        /* isosurface */
        if (use_arrays)
            glDrawArrays(GL_TRIANGLES, 0, num_vertices_in_array);
        else
            DrawVolumeAsIsosurface();
    }

    if (use_arrays)
    {
        glDisableClientState(GL_VERTEX_ARRAY);
        if (display_mode > 0)
            glDisableClientState(GL_NORMAL_ARRAY);
    }
}
Example #4
0
void DrawTriangleList(int iTriangleCount, Triangle *pTriangles, Point *pPoints)
{
	static int iBufferSize=0;
	static float *pfVertexBuffer=NULL;
	static float *pfNormalBuffer=NULL;

	if(iBufferSize < iTriangleCount*3)
	{
		iBufferSize=3*iTriangleCount;

		if( pfVertexBuffer )
		delete[] pfVertexBuffer;
		pfVertexBuffer = new float[iBufferSize*3];

		if( pfNormalBuffer )
		delete[] pfNormalBuffer;
		pfNormalBuffer = new float[iBufferSize*3];
	}

	float *pfDestinationVertex=pfVertexBuffer;
	float *pfDestinationNormal=pfNormalBuffer;

	for(int iTriangle=0; iTriangle<iTriangleCount; iTriangle++)
	{
		*pfDestinationVertex++=pPoints[pTriangles->p0].x;
		*pfDestinationVertex++=pPoints[pTriangles->p0].y;
		*pfDestinationVertex++=pPoints[pTriangles->p0].z;
		*pfDestinationVertex++=pPoints[pTriangles->p1].x;
		*pfDestinationVertex++=pPoints[pTriangles->p1].y;
		*pfDestinationVertex++=pPoints[pTriangles->p1].z;
		*pfDestinationVertex++=pPoints[pTriangles->p2].x;
		*pfDestinationVertex++=pPoints[pTriangles->p2].y;
		*pfDestinationVertex++=pPoints[pTriangles->p2].z;

		NxVec3 edge1 = pPoints[pTriangles->p1] - pPoints[pTriangles->p0];
		NxVec3 edge2 = pPoints[pTriangles->p2] - pPoints[pTriangles->p0];
		NxVec3 normal = edge1.cross(edge2);
		normal.normalize();

		*pfDestinationNormal++=normal.x;
		*pfDestinationNormal++=normal.y;
		*pfDestinationNormal++=normal.z;
		*pfDestinationNormal++=normal.x;
		*pfDestinationNormal++=normal.y;
		*pfDestinationNormal++=normal.z;
		*pfDestinationNormal++=normal.x;
		*pfDestinationNormal++=normal.y;
		*pfDestinationNormal++=normal.z;

		pTriangles++;
	}

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);

	glVertexPointer(3, GL_FLOAT, 0, iTriangleCount*3, pfVertexBuffer);
	glNormalPointer(GL_FLOAT, 0, iTriangleCount*3, pfNormalBuffer);

	glDrawArrays(GL_TRIANGLES, 0, 3*iTriangleCount);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

}
/*!
* \brief	Render the OpenGL ES scene.
* \param	time Current time in milliseconds
* \note	Renders the OpenGL ES scene
*//*-------------------------------------------------------------------*/
void renderGLESScene(unsigned int time)
{

    int width = 0;
    int height = 0;
#if defined(TEST_LOCKSURFACE)
    KDuint16 *fb = KD_NULL;
    int y = 0;
    EGLint pitch = 0;
    EGLint origin = 0;
    EGLint r, g, b;
#else
    /* Time needed for the rotation */
    const KDfloat32 effectTime	= kdFmodf(time / 4000.0f, 360.0f);
#endif

    /* Query the current window surface size from EGL */
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_WIDTH, (EGLint *)&width);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_HEIGHT, (EGLint *)&height);

#if !defined(TEST_LOCKSURFACE)
    /* Update the GLES state */
    updateOpenGLESState		(width, height);
    glClear 				(GL_COLOR_BUFFER_BIT);

    /* Rotate the world matrix and translate it on the z-axis */
    glMatrixMode			(GL_MODELVIEW);
    glLoadIdentity			();
    glTranslatex			(F2F(0.f), F2F(0.f), F2F(-30.f));
    glRotatex				(F2F((float)(effectTime*29.77f)), F2F(1.0f), F2F(2.0f), F2F(0.0f));
    glRotatex				(F2F((float)(effectTime*22.311f)), F2F(-0.1f), F2F(0.0f), -F2F(5.0f));

    glBindTexture(GL_TEXTURE_2D, GLOBALS->tex);

    /* Set the pointer to the arrays containing the cube vertices, normals 
    and texture coordinates */
    glVertexPointer			(3, GL_BYTE, 0, s_cubeVertices);
    glNormalPointer			(GL_BYTE, 0, s_cubeNormals);
    glTexCoordPointer		(2, GL_BYTE, 0, s_cubeTexCoords);

    /* Draw the cube one face at a time in the same order thay have been defined 
    in the s_cubeVertices array */
    glDrawArrays			(GL_TRIANGLE_STRIP, 0, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 4, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 8, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 12, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 16, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 20, 4);

#else

    /* Lock the surface and query for the properties */
    eglLockSurfaceKHR(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, KD_NULL);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_POINTER_KHR, (EGLint *)&fb);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PITCH_KHR, &pitch);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_ORIGIN_KHR, &origin);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PIXEL_RED_OFFSET_KHR, &r);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR, &g);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR, &b);

    /* Fill the surface with random noise */
    for(y = 0; y < height; y++)
    {
        kdCryptoRandom((KDuint8 *)fb, width * 2);
        fb += pitch / 2;
    }

    eglUnlockSurfaceKHR(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface);
#endif

    /* Display the result on the screen */
    eglSwapBuffers			(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface);

}
Example #6
0
void CVertMeshInstance::Draw(unsigned flags)
{
	guard(CVertMeshInstance::Draw);

	if (!Sections.Num()) return;		// empty mesh

	int i;

	// get 2 frames for interpolation
	int FrameNum1, FrameNum2;
	float frac;
	if (AnimIndex != INDEX_NONE)
	{
		const FMeshAnimSeq &A = pMesh->AnimSeqs[AnimIndex];
		FrameNum1 = appFloor(AnimTime);
		FrameNum2 = FrameNum1 + 1;
		if (FrameNum2 >= A.NumFrames)
			FrameNum2 = 0;
		frac      = AnimTime - FrameNum1;
		FrameNum1 += A.StartFrame;
		FrameNum2 += A.StartFrame;
		// clamp frame numbers (has mesh with wrong frame count in last animation:
		// UT1/BotPack/cdgunmainM; this animation is shown in UnrealEd as lerping to null size)
		if (FrameNum1 >= pMesh->FrameCount)
			FrameNum1 = pMesh->FrameCount-1;
		if (FrameNum2 >= pMesh->FrameCount)
			FrameNum2 = pMesh->FrameCount-1;
	}
	else
	{
		FrameNum1 = 0;
		FrameNum2 = 0;
		frac      = 0;
	}

	int base1 = pMesh->VertexCount * FrameNum1;
	int base2 = pMesh->VertexCount * FrameNum2;

	float backLerp = 1 - frac;
	CVec3 Scale1, Scale2;
	Scale1 = Scale2 = CVT(pMesh->MeshScale);
	Scale1.Scale(backLerp);
	Scale2.Scale(frac);

	// compute deformed mesh
	const FMeshWedge *W = &pMesh->Wedges[0];
	CVec3 *pVec    = Verts;
	CVec3 *pNormal = Normals;
	for (i = 0; i < pMesh->Wedges.Num(); i++, pVec++, pNormal++, W++)
	{
		CVec3 tmp;
#if 0
		// path with no frame lerp
		// vertex
		const FMeshVert &V = pMesh->Verts[base1 + W->iVertex];
		tmp[0] = V.X * pMesh->MeshScale.X;
		tmp[1] = V.Y * pMesh->MeshScale.Y;
		tmp[2] = V.Z * pMesh->MeshScale.Z;
		BaseTransform.TransformPoint(tmp, *pVec);
		// normal
		const FMeshNorm &N = pMesh->Normals[base1 + W->iVertex];
		tmp[0] = (N.X - 512.0f) / 512;
		tmp[1] = (N.Y - 512.0f) / 512;
		tmp[2] = (N.Z - 512.0f) / 512;
		BaseTransform.axis.TransformVector(tmp, *pNormal);
#else
		// vertex
		const FMeshVert &V1 = pMesh->Verts[base1 + W->iVertex];
		const FMeshVert &V2 = pMesh->Verts[base2 + W->iVertex];
		tmp[0] = V1.X * Scale1[0] + V2.X * Scale2[0];
		tmp[1] = V1.Y * Scale1[1] + V2.Y * Scale2[1];
		tmp[2] = V1.Z * Scale1[2] + V2.Z * Scale2[2];
		BaseTransform.TransformPoint(tmp, *pVec);
		// normal
		const FMeshNorm &N1 = pMesh->Normals[base1 + W->iVertex];
		const FMeshNorm &N2 = pMesh->Normals[base2 + W->iVertex];
		tmp[0] = (N1.X * backLerp + N2.X * frac - 512.0f) / 512;
		tmp[1] = (N1.Y * backLerp + N2.Y * frac - 512.0f) / 512;
		tmp[2] = (N1.Z * backLerp + N2.Z * frac - 512.0f) / 512;
		BaseTransform.axis.TransformVector(tmp, *pNormal);
#endif
	}

#if 0
	glBegin(GL_POINTS);
	for (i = 0; i < pMesh->Wedges.Num(); i++)
	{
		glVertex3fv(Verts[i].v);
	}
	glEnd();
	return;
#endif

	// draw mesh
	glEnable(GL_LIGHTING);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);

	glVertexPointer(3, GL_FLOAT, sizeof(CVec3), Verts);
	glNormalPointer(GL_FLOAT, sizeof(CVec3), Normals);
	glTexCoordPointer(2, GL_FLOAT, sizeof(FMeshWedge), &pMesh->Wedges[0].TexUV.U);

	for (i = 0; i < Sections.Num(); i++)
	{
		const CMeshSection &Sec = Sections[i];
		if (!Sec.NumFaces) continue;
		SetMaterial(Sec.Material, i);
		glDrawElements(GL_TRIANGLES, Sec.NumFaces * 3, GL_UNSIGNED_SHORT, &Indices[Sec.FirstIndex]);
	}

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	glDisable(GL_LIGHTING);
	BindDefaultMaterial(true);

	// draw mesh normals
	if (flags & DF_SHOW_NORMALS)
	{
		glBegin(GL_LINES);
		glColor3f(0.5, 1, 0);
		for (i = 0; i < pMesh->Wedges.Num(); i++)
		{
			glVertex3fv(Verts[i].v);
			CVec3 tmp;
			VectorMA(Verts[i], 2, Normals[i], tmp);
			glVertex3fv(tmp.v);
		}
		glEnd();
	}

	unguard;
}
Example #7
0
void drawScene2(){
	glTranslatef(0,0,-16);

	glPushMatrix();
		glTranslatef(0, 0, -ZOOM);
		glPushMatrix();
			static float lightRotate = 0.0f;
			lightRotate += 0.3;
			glRotatef(lightRotate / 80.0 * 180.0, 0.11111, 0.3, 1.0);
			glLightfv(GL_LIGHT0, GL_POSITION, std_light_pos);
			glLightfv(GL_LIGHT1, GL_POSITION, std_light_pos);
			glLightfv(GL_LIGHT2, GL_POSITION, std_light_pos);
			glLightfv(GL_LIGHT0, GL_POSITION, light_position1);
			glLightfv(GL_LIGHT1, GL_POSITION, light_position2);
			glLightfv(GL_LIGHT2, GL_POSITION, light_position3);
		glPopMatrix();


		glShadeModel(GL_FLAT);
// TOP ROW
		glPushMatrix();
			glTranslatef(-3, 3, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);
			drawGeodesicPoints(&geodesicV3);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(0, 3, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);
			drawGeodesicLines(&geodesicV3);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(3, 3, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);
			drawGeodesicTriangles(&geodesicV3);
		glPopMatrix();

// MIDDLE ROW
		glPushMatrix();
			glTranslatef(-3, 0, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			drawGeodesicExtrudedTriangles(&m);
		glPopMatrix();

		glPushMatrix();
		glScalef(1.618, 1.618, 1.618);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);
			drawGeodesicLines(&geodesicV2);

			glDisable(GL_LIGHTING);
			glColor3f(1.0, 1.0, 1.0);
			drawGeodesicVertexNormalLines(&normalsV2);
			glColor3f(0.0, 1.0, 1.0);
			drawGeodesicLineNormalLines(&normalsV2);
			glColor3f(1.0, 0.0, 1.0);
			drawGeodesicFaceNormalLines(&normalsV2);
			glEnable(GL_LIGHTING);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(3, 0, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);

			glEnableClientState(GL_VERTEX_ARRAY);
			glEnableClientState(GL_NORMAL_ARRAY);    
			glVertexPointer(3, GL_FLOAT, 0, t.data);
			glNormalPointer(GL_FLOAT, 0, geo.pointNormals);
			glDrawElements(GL_TRIANGLES, geo.numFaces*3, GL_UNSIGNED_SHORT, geo.faces);
			glDisableClientState(GL_NORMAL_ARRAY);
			glDisableClientState(GL_VERTEX_ARRAY);

		glPopMatrix();

// BOTTOM ROW
		glPushMatrix();
			glTranslatef(-3, -3, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glPushMatrix();
				glRotatef(-90, 0, 0, 1);
				drawGeodesicExtrudedTriangles(&m);
			glPopMatrix();
		
			glDisable(GL_LIGHTING);
			glDisable(GL_CULL_FACE);
			glColor3f(0.5, 0.5, 0.5);
			drawGeodesicCropPlanes(&planes);
			glEnable(GL_CULL_FACE);
			glEnable(GL_LIGHTING);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(0, -3, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);
			drawDomeMeshTriangles(&domeV3, &domeMeshV3);
		glPopMatrix();

		glPushMatrix();
			glTranslatef(3, -3, 0);
			glRotatef(-mouseDragSumY * MOUSE_SENSITIVITY, 1, 0, 0);
			glRotatef(-mouseDragSumX * MOUSE_SENSITIVITY, 0, 1, 0);
			glRotatef(-90, 0, 0, 1);
			drawDomeMeshTriangles(&domeV8, &domeMeshV8);
		glPopMatrix();

	glPopMatrix();	
}
Example #8
0
//--------------------------------------------------------------
void ofVbo::bind(){
	if(supportVAOs){
		if(vaoID==0){
			glGenVertexArrays(1, &vaoID);
			if(vaoID!=0){
				retainVAO(vaoID);
			}else{
				supportVAOs = false;
				ofLogVerbose("ofVbo") << "bind(): error allocating VAO, disabling VAO support";
			}
		}

		glBindVertexArray(vaoID);
	}

	if(vaoChanged || !supportVAOs){
		bool programmable = ofIsGLProgrammableRenderer();
		if(bUsingVerts){
			glBindBuffer(GL_ARRAY_BUFFER, vertId);
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glEnableClientState(GL_VERTEX_ARRAY);
				glVertexPointer(vertSize, GL_FLOAT, vertStride, 0);
				#endif
			}else{
				glEnableVertexAttribArray(ofShader::POSITION_ATTRIBUTE);
				glVertexAttribPointer(ofShader::POSITION_ATTRIBUTE, vertSize, GL_FLOAT, GL_FALSE, vertStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glDisableClientState(GL_VERTEX_ARRAY);
				#endif
			}else{
				glDisableVertexAttribArray(ofShader::POSITION_ATTRIBUTE);
			}
		}

		if(bUsingColors) {
			glBindBuffer(GL_ARRAY_BUFFER, colorId);
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glEnableClientState(GL_COLOR_ARRAY);
				glColorPointer(4, GL_FLOAT, colorStride, 0);
				#endif
			}else{
				glEnableVertexAttribArray(ofShader::COLOR_ATTRIBUTE);
				glVertexAttribPointer(ofShader::COLOR_ATTRIBUTE, 4, GL_FLOAT, GL_FALSE, colorStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glDisableClientState(GL_COLOR_ARRAY);
				#endif
			}else{
				glDisableVertexAttribArray(ofShader::COLOR_ATTRIBUTE);
			}
		}

		if(bUsingNormals) {
			glBindBuffer(GL_ARRAY_BUFFER, normalId);
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glEnableClientState(GL_NORMAL_ARRAY);
				glNormalPointer(GL_FLOAT, normalStride, 0);
				#endif
			}else{
				// tig: note that we set the 'Normalize' flag to true here, assuming that mesh normals need to be
				// normalized while being uploaded to GPU memory.
				// http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml
				// Normalizing the normals on the shader is probably faster, but sending non-normalized normals is
				// more prone to lead to artifacts difficult to diagnose, especially with the built-in 3D primitives.
				// If you need to optimise this, and you've dug this far through the code, you are most probably
				// able to roll your own client code for binding & rendering vbos anyway...
				glEnableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE);
				glVertexAttribPointer(ofShader::NORMAL_ATTRIBUTE, 3, GL_FLOAT, GL_TRUE, normalStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glDisableClientState(GL_NORMAL_ARRAY);
				#endif
			}else{
				glDisableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE);
			}
		}

		if(bUsingTexCoords) {
			glBindBuffer(GL_ARRAY_BUFFER, texCoordId);
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glEnableClientState(GL_TEXTURE_COORD_ARRAY);
				glTexCoordPointer(2, GL_FLOAT, texCoordStride, 0);
				#endif
			}else{
				glEnableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE);
				glVertexAttribPointer(ofShader::TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, texCoordStride, 0);
			}
		}else if(supportVAOs){
			if(!programmable){
				#ifndef TARGET_PROGRAMMABLE_GL
				glDisableClientState(GL_TEXTURE_COORD_ARRAY);
				#endif
			}else{
				glDisableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE);
			}
		}
        
        if (bUsingIndices) {
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
        }

		map<int,GLuint>::iterator it;
		for(it=attributeIds.begin();it!=attributeIds.end();it++){
			glBindBuffer(GL_ARRAY_BUFFER, attributeIds[it->first]);
			glEnableVertexAttribArray(it->first);
			glVertexAttribPointer(it->first, attributeNumCoords[it->first], GL_FLOAT, GL_FALSE, attributeStrides[it->first], 0);
			if(ofIsGLProgrammableRenderer()){
				bUsingVerts |= it->first == ofShader::POSITION_ATTRIBUTE;
				bUsingColors |= it->first == ofShader::COLOR_ATTRIBUTE;
				bUsingTexCoords |= it->first == ofShader::TEXCOORD_ATTRIBUTE;
				bUsingNormals |= it->first == ofShader::NORMAL_ATTRIBUTE;
			}
		}

		vaoChanged=false;
	}


	shared_ptr<ofGLProgrammableRenderer> renderer = ofGetGLProgrammableRenderer();
	if(renderer){
		renderer->setAttributes(bUsingVerts,bUsingColors,bUsingTexCoords,bUsingNormals);
	}
	bBound   = true;
}
Example #9
0
// Nastavi poly na rendering
void poly_vertex_array_set_arb(EDIT_MESH_POLY * p_poly)
{
  VERTEX_ARRAYS *p_va = &p_poly->varray;
  int spec = p_poly->m2flag & (MAT2_SPECULAR | MAT2_ENV_SPEC)
    || p_poly->kflag & KONT_DRAW_SPEC;
  int norm = glstav_pn_triangles
    || p_poly->m2flag & (MAT2_CALC_MAP1 | MAT2_CALC_MAP2 | MAT2_CALC_MAP3 |
    MAT2_CALC_MAP4);
  int *p_int, ind;

  glBindBufferARB(GL_ARRAY_BUFFER_ARB, p_va->ati_handle);
  glVertexPointer(3, GL_FLOAT, sizeof(p_poly->p_koord[0]), BUFFER_OFFSET(0));

  array_diffuse_on();
  glColorPointer(4, GL_FLOAT, sizeof(p_poly->p_koord[0]),
    BUFFER_OFFSET(16 * sizeof(float)));

  if (norm) {
    array_normal_on();
    glNormalPointer(GL_FLOAT, sizeof(p_poly->p_koord[0]),
      BUFFER_OFFSET(3 * sizeof(float)));
  }
  else {
    array_normal_off();
  }

  if (spec) {
    array_specular_on();
    glSecondaryColorPointerEXT(3, GL_FLOAT, sizeof(p_poly->p_koord[0]),
      BUFFER_OFFSET(24 * sizeof(float)));
  }
  else {
    array_specular_off();
  }

  p_int = glstav_text_map_indicie;

  if (glstav_text_poly_indicie > 0) {
    array_text_set_num(0);
    if ((ind = *p_int) != K_CHYBA) {
      array_text_on();
      glTexCoordPointer(2, GL_FLOAT, sizeof(p_poly->p_koord[0]),
        BUFFER_OFFSET((6 + ((ind) << 1)) * sizeof(float)));
    }
    else {
      array_text_off();
    }
  }
  p_int++;

  if (glstav_text_poly_indicie > 1) {
    array_text_set_num(1);
    if ((ind = *p_int) != K_CHYBA) {
      array_text_on();
      glTexCoordPointer(2, GL_FLOAT, sizeof(p_poly->p_koord[0]),
        BUFFER_OFFSET((6 + ((ind) << 1)) * sizeof(float)));
    }
    else {
      array_text_off();
    }
  }
  p_int++;

  if (glstav_text_poly_indicie > 2) {
    array_text_set_num(2);
    if ((ind = *p_int) != K_CHYBA) {
      array_text_on();
      glTexCoordPointer(2, GL_FLOAT, sizeof(p_poly->p_koord[0]),
        BUFFER_OFFSET((6 + ((ind) << 1)) * sizeof(float)));
    }
    else {
      array_text_off();
    }
  }
  p_int++;


  if (glstav_text_poly_indicie > 3) {
    array_text_set_num(3);
    if ((ind = *p_int) != K_CHYBA) {
      array_text_on();
      glTexCoordPointer(2, GL_FLOAT, sizeof(p_poly->p_koord[0]),
        BUFFER_OFFSET((6 + ((ind) << 1)) * sizeof(float)));
    }
    else {
      array_text_off();
    }
  }

  array_text_set_num(glstav_text_poly_indicie);
  array_text_on();
  glTexCoordPointer(2, GL_FLOAT, sizeof(p_poly->p_koord[0]),
    BUFFER_OFFSET(14 * sizeof(float)));
}
Example #10
0
void draw_3d_object_detail(object3d * object_id, Uint32 material_index, Uint32 use_lightning,
	Uint32 use_textures, Uint32 use_extra_textures)
{
	e3d_vertex_data* vertex_layout;
	Uint8 * data_ptr;

	// check for having to load the arrays
	load_e3d_detail_if_needed(object_id->e3d_data);

	CHECK_GL_ERRORS();
	//also, update the last time this object was used
	object_id->last_acessed_time = cur_time;

	//debug

	if (object_id->self_lit && (!is_day || dungeon) && use_lightning) 
	{
		glColor3fv(object_id->color);
	}

	CHECK_GL_ERRORS();

	glPushMatrix();//we don't want to affect the rest of the scene

	glMultMatrixf(object_id->matrix);

	CHECK_GL_ERRORS();

	if (!dungeon && (clouds_shadows || use_shadow_mapping) && use_extra_textures)
	{
		VECTOR4 plane;

		ELglActiveTextureARB(detail_unit);
		memcpy(plane, object_id->clouds_planes[0], sizeof(VECTOR4));
		plane[3] += clouds_movement_u;
		glTexGenfv(GL_S, GL_EYE_PLANE, plane);
		memcpy(plane, object_id->clouds_planes[1], sizeof(VECTOR4));
		plane[3] += clouds_movement_v;
		glTexGenfv(GL_T, GL_EYE_PLANE, plane);
		ELglActiveTextureARB(base_unit);
	}

	// watch for a change
	if (object_id->e3d_data != cur_e3d)
	{
		if ((cur_e3d != NULL) && (use_compiled_vertex_array))
		{
			ELglUnlockArraysEXT();
		}

		if (use_vertex_buffers)
		{
			ELglBindBufferARB(GL_ARRAY_BUFFER_ARB,
				object_id->e3d_data->vertex_vbo);
			data_ptr = 0;
		}
		else
		{
			data_ptr = object_id->e3d_data->vertex_data;
		}

		vertex_layout = object_id->e3d_data->vertex_layout;

		if ((vertex_layout->normal_count > 0) && use_lightning)
		{
			glEnableClientState(GL_NORMAL_ARRAY);
			glNormalPointer(vertex_layout->normal_type, vertex_layout->size,
				data_ptr + vertex_layout->normal_offset);
		}
		else
		{
			glDisableClientState(GL_NORMAL_ARRAY);
			glNormal3f(0.0f, 0.0f, 1.0f);
		}

		if (use_textures)
		{
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer(vertex_layout->texture_count, vertex_layout->texture_type,
				vertex_layout->size, data_ptr + vertex_layout->texture_offset);
		}
		else
		{
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		}

		glVertexPointer(vertex_layout->position_count, vertex_layout->position_type,
			vertex_layout->size, data_ptr + vertex_layout->position_offset);

		if (use_vertex_buffers)
		{
			ELglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
				object_id->e3d_data->indices_vbo);
		}

		// lock this new one
		if (use_compiled_vertex_array)
		{
			ELglLockArraysEXT(0, object_id->e3d_data->vertex_no);
		}
		// gather statistics
		if (object_id->e3d_data != cur_e3d)
		{
#ifdef  DEBUG
			if ((cur_e3d_count > 0) && (cur_e3d != NULL))
			{
				e3d_count++;
				e3d_total += cur_e3d_count;
			}
			cur_e3d_count = 0;
#endif    //DEBUG
			cur_e3d = object_id->e3d_data;
		}
	}
#ifdef  DEBUG
	cur_e3d_count++;
#endif  //DEBUG

	if (use_textures)
	{
		glEnable(GL_TEXTURE_2D);
#ifdef	NEW_TEXTURES
		bind_texture(object_id->e3d_data->materials[material_index].texture);
#else	/* NEW_TEXTURES */
		get_and_set_texture_id(object_id->e3d_data->materials[material_index].texture);
#endif	/* NEW_TEXTURES */
	}
	else
	{
		glDisable(GL_TEXTURE_2D);		
	}


	if (use_draw_range_elements && ELglDrawRangeElementsEXT)
		ELglDrawRangeElementsEXT(GL_TRIANGLES,
			object_id->e3d_data->materials[material_index].triangles_indices_min,
			object_id->e3d_data->materials[material_index].triangles_indices_max,
			object_id->e3d_data->materials[material_index].triangles_indices_count,
			object_id->e3d_data->index_type,
			object_id->e3d_data->materials[material_index].triangles_indices_index);
	else
		glDrawElements(GL_TRIANGLES,
			object_id->e3d_data->materials[material_index].triangles_indices_count,
			object_id->e3d_data->index_type,
			object_id->e3d_data->materials[material_index].triangles_indices_index);

	glPopMatrix();//restore the scene
	CHECK_GL_ERRORS();

	//OK, let's check if our mouse is over...
#ifdef MAP_EDITOR2
	if (selected_3d_object == -1 && read_mouse_now && mouse_in_sphere(object_id->x_pos, object_id->y_pos, object_id->z_pos, object_id->e3d_data->radius))
		anything_under_the_mouse(object_id->id, UNDER_MOUSE_3D_OBJ);
#endif
}
Example #11
0
void X_MODEL::Draw() {

	glPushMatrix();
	glEnable(GL_NORMALIZE);

	for (int nodeCount = 0; nodeCount < m_nodeArray.size(); ++nodeCount) {

		glMultMatrixf(&m_nodeArray[nodeCount].nodeMat[0][0]);

		for (int i = 0; i < m_nodeArray[nodeCount].materialArray.size(); ++i) {
			glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (const GLfloat *)&m_nodeArray[nodeCount].materialArray[i].ambient);
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (const GLfloat *)&m_nodeArray[nodeCount].materialArray[i].diffuse);
			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (const GLfloat *)&m_nodeArray[nodeCount].materialArray[i].specular);
			glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, m_nodeArray[nodeCount].materialArray[i].shininess);

			if (m_nodeArray[nodeCount].materialArray[i].texNo > 0) {
				glEnableClientState(GL_TEXTURE_COORD_ARRAY);
				glEnable(GL_TEXTURE_2D);

				glBindTexture(
					GL_TEXTURE_2D,
					m_nodeArray[nodeCount].texID[m_nodeArray[nodeCount].materialArray[i].texNo - 1]
					);
			}
			else {
				glDisable(GL_TEXTURE_2D);
				glDisableClientState(GL_TEXTURE_COORD_ARRAY);
			}
		}

		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_NORMAL_ARRAY);


		glVertexPointer(
			3,
			GL_FLOAT,
			0,
			m_nodeArray[nodeCount].vertexArray.data());

		glNormalPointer(
			GL_FLOAT,
			0,
			m_nodeArray[nodeCount].normalArray.data());

		if (m_nodeArray[nodeCount].materialArray[0].texNo > 0) {

			glTexCoordPointer(
				2,
				GL_FLOAT,
				0,
				m_nodeArray[nodeCount].texcoordArray.data());

		}
		glDrawElements(
			GL_TRIANGLES,
			m_nodeArray[nodeCount].indexArray.size(),
			GL_UNSIGNED_INT,
			m_nodeArray[nodeCount].indexArray.data());

	}
	glDisable(GL_NORMALIZE);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_TEXTURE_2D);



	glPopMatrix();

}
Example #12
0
//===========================================================================
void cDrawFrame(const double a_axisLengthScale, const double a_axisThicknessScale,
                const bool a_modifyMaterialState)
{
    // Triangle vertices:
    static int nTriangles = 8;

    static float triangle_vertices[72] = 
    {
        0.000000f, 0.040000f,-0.800000f, 0.028284f, 0.028284f,-0.800000f,
        0.000000f, 0.000000f,-1.000000f, 0.028284f, 0.028284f,-0.800000f,
        0.040000f, 0.000000f,-0.800000f, 0.000000f, 0.000000f,-1.000000f,
        0.040000f, 0.000000f,-0.800000f, 0.028284f,-0.028284f,-0.800000f,
        0.000000f, 0.000000f,-1.000000f, 0.028284f,-0.028284f,-0.800000f,
        0.000000f,-0.040000f,-0.800000f, 0.000000f, 0.000000f,-1.000000f,
        0.000000f,-0.040000f,-0.800000f,-0.028284f,-0.028284f,-0.800000f,
        0.000000f, 0.000000f,-1.000000f,-0.028284f,-0.028284f,-0.800000f,
       -0.040000f, 0.000000f,-0.800000f, 0.000000f, 0.000000f,-1.000000f,
       -0.040000f, 0.000000f,-0.800000f,-0.028284f, 0.028284f,-0.800000f,
        0.000000f, 0.000000f,-1.000000f,-0.028284f, 0.028284f,-0.800000f,
        0.000000f, 0.040000f,-0.800000f, 0.000000f, 0.000000f,-1.000000f
    };

    // Triangle normals:
    static float triangle_normals[72] = {
         0.000000f, 0.980581f,-0.196116f, 0.693375f, 0.693375f,-0.196116f,
         0.357407f, 0.862856f,-0.357407f, 0.693375f, 0.693375f,-0.196116f,
         0.980581f, 0.000000f,-0.196116f, 0.862856f, 0.357407f,-0.357407f,
         0.980581f, 0.000000f,-0.196116f, 0.693375f,-0.693375f,-0.196116f,
         0.862856f,-0.357407f,-0.357407f, 0.693375f,-0.693375f,-0.196116f,
         0.000000f,-0.980581f,-0.196116f, 0.357407f,-0.862856f,-0.357407f,
         0.000000f,-0.980581f,-0.196116f,-0.693375f,-0.693375f,-0.196116f,
        -0.357407f,-0.862856f,-0.357407f,-0.693375f,-0.693375f,-0.196116f,
        -0.980581f, 0.000000f,-0.196116f,-0.862856f,-0.357407f,-0.357407f,
        -0.980581f, 0.000000f,-0.196116f,-0.693375f, 0.693375f,-0.196116f,
        -0.862856f, 0.357407f,-0.357407f,-0.693375f, 0.693375f,-0.196116f,
         0.000000f, 0.980581f,-0.196116f,-0.357407f, 0.862856f,-0.357407f
    };

    // Quad vertices:
    static int nQuads = 16;

    static float quad_vertices[192] = 
    {
        0.000000f, 0.010000f, 0.000000f, 0.007000f, 0.007000f, 0.000000f,
        0.007000f, 0.007000f,-0.800000f, 0.000000f, 0.010000f,-0.800000f,
        0.000000f,-0.010000f, 0.000000f,-0.007000f,-0.007000f, 0.000000f,
       -0.007000f,-0.007000f,-0.800000f, 0.000000f,-0.010000f,-0.800000f,
       -0.007000f,-0.007000f, 0.000000f,-0.010000f, 0.000000f, 0.000000f,
       -0.010000f, 0.000000f,-0.800000f,-0.007000f,-0.007000f,-0.800000f,
       -0.010000f, 0.000000f, 0.000000f,-0.007000f, 0.007000f, 0.000000f,
       -0.007000f, 0.007000f,-0.800000f,-0.010000f, 0.000000f,-0.800000f,
       -0.007000f, 0.007000f, 0.000000f, 0.000000f, 0.010000f, 0.000000f,
        0.000000f, 0.010000f,-0.800000f,-0.007000f, 0.007000f,-0.800000f,
        0.007000f, 0.007000f, 0.000000f, 0.010000f, 0.000000f, 0.000000f,
        0.010000f, 0.000000f,-0.800000f, 0.007000f, 0.007000f,-0.800000f,
        0.010000f, 0.000000f, 0.000000f, 0.007000f,-0.007000f, 0.000000f,
        0.007000f,-0.007000f,-0.800000f, 0.010000f, 0.000000f,-0.800000f,
        0.007000f,-0.007000f, 0.000000f, 0.000000f,-0.010000f, 0.000000f,
        0.000000f,-0.010000f,-0.800000f, 0.007000f,-0.007000f,-0.800000f,
       -0.007000f, 0.007000f,-0.800000f,-0.028284f, 0.028284f,-0.800000f,
       -0.040000f, 0.000000f,-0.800000f,-0.010000f, 0.000000f,-0.800000f,
       -0.010000f, 0.000000f,-0.800000f,-0.040000f, 0.000000f,-0.800000f,
       -0.028284f,-0.028284f,-0.800000f,-0.007000f,-0.007000f,-0.800000f,
       -0.007000f,-0.007000f,-0.800000f,-0.028284f,-0.028284f,-0.800000f,
        0.000000f,-0.040000f,-0.800000f, 0.000000f,-0.010000f,-0.800000f,
        0.000000f,-0.010000f,-0.800000f, 0.000000f,-0.040000f,-0.800000f,
        0.028284f,-0.028284f,-0.800000f, 0.007000f,-0.007000f,-0.800000f,
        0.028284f,-0.028284f,-0.800000f, 0.040000f, 0.000000f,-0.800000f,
        0.010000f, 0.000000f,-0.800000f, 0.007000f,-0.007000f,-0.800000f,
        0.040000f, 0.000000f,-0.800000f, 0.028284f, 0.028284f,-0.800000f,
        0.007000f, 0.007000f,-0.800000f, 0.010000f, 0.000000f,-0.800000f,
        0.007000f, 0.007000f,-0.800000f, 0.028284f, 0.028284f,-0.800000f,
        0.000000f, 0.040000f,-0.800000f, 0.000000f, 0.010000f,-0.800000f,
        0.000000f, 0.010000f,-0.800000f, 0.000000f, 0.040000f,-0.800000f,
       -0.028284f, 0.028284f,-0.800000f,-0.007000f, 0.007000f,-0.800000f
    };

    // Quad normals:
    static float quad_normals[192] = 
    {
         0.000000f, 1.000000f, 0.000000f, 0.707107f, 0.707107f, 0.000000f,
         0.707107f, 0.707107f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
         0.000000f,-1.000000f, 0.000000f,-0.707107f,-0.707107f, 0.000000f,
        -0.707107f,-0.707107f, 0.000000f, 0.000000f,-1.000000f, 0.000000f,
        -0.707107f,-0.707107f, 0.000000f,-1.000000f, 0.000000f, 0.000000f,
        -1.000000f, 0.000000f, 0.000000f,-0.707107f,-0.707107f, 0.000000f,
        -1.000000f, 0.000000f, 0.000000f,-0.707107f, 0.707107f, 0.000000f,
        -0.707107f, 0.707107f, 0.000000f,-1.000000f, 0.000000f, 0.000000f,
        -0.707107f, 0.707107f, 0.000000f, 0.000000f, 1.000000f, 0.000000f,
         0.000000f, 1.000000f, 0.000000f,-0.707107f, 0.707107f, 0.000000f,
         0.707107f, 0.707107f, 0.000000f, 1.000000f, 0.000000f, 0.000000f,
         1.000000f, 0.000000f, 0.000000f, 0.707107f, 0.707107f, 0.000000f,
         1.000000f, 0.000000f, 0.000000f, 0.707107f,-0.707107f, 0.000000f,
         0.707107f,-0.707107f, 0.000000f, 1.000000f, 0.000000f, 0.000000f,
         0.707107f,-0.707107f, 0.000000f, 0.000000f,-1.000000f, 0.000000f,
         0.000000f,-1.000000f, 0.000000f, 0.707107f,-0.707107f, 0.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f,
         0.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, 1.000000f
    };

    // set material properties
    float fnull[4] = {0,0,0,0};
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (const float *)&fnull);
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (const float *)&fnull);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // enable vertex and normal arrays
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);

    if (a_modifyMaterialState)
    {
    //  glEnable(GL_COLOR_MATERIAL);
    //  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    //  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }

    for(int k=0; k<3; k++)
    {
        glPushMatrix();

        // Rotate to the appropriate axis
        if (k==0) {
          glRotatef(-90.0,0,1,0);
          glColor3f(1.0f,0.0f,0.0f);
        }
        else if (k==1) {
          glRotatef(90.0,1,0,0);
          glColor3f(0.0f,1.0f,0.0f);
        }
        else {
          glRotatef(180.0,1,0,0);
          glColor3f(0.0f,0.0f,1.0f);
        }

        // scaling
        glScaled(a_axisThicknessScale,a_axisThicknessScale,a_axisLengthScale);

        // render frame object
        glVertexPointer(3, GL_FLOAT, 0, triangle_vertices);
        glNormalPointer(GL_FLOAT, 0, triangle_normals);
        glDrawArrays(GL_TRIANGLES, 0, nTriangles*3);

        glVertexPointer(3, GL_FLOAT, 0, quad_vertices);
        glNormalPointer(GL_FLOAT, 0, quad_normals);
        glDrawArrays(GL_QUADS, 0, nQuads*4);

        glPopMatrix();
    }

    // disable vertex and normal arrays
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
}
Example #13
0
void	CRenderer::BindVertexBuffer( void* pBufferId, size_t vertexCount, const CVertexFormat& vertexFormat )
{
	glBindBuffer( GL_ARRAY_BUFFER, *((GLuint*)pBufferId) );
	static_cast< CSpecificData* >( m_pSpecificData )->m_boundVertexBuffer = *((GLuint*)pBufferId);

	// Position
	GLuint attribIndex = 0;
	glEnableVertexAttribArray( attribIndex );
	glVertexAttribPointer( 0, 3, GL_FLOAT, false, (GLsizei)vertexFormat.GetSize(), 0 );
	++attribIndex;

	// Normal
	if ( vertexFormat.HasSingleElement( CVertexFormat::eSE_Normal ) )
	{
		glEnableVertexAttribArray( attribIndex );
		glVertexAttribPointer( attribIndex, 3, GL_FLOAT, false, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_Normal ) );
		++attribIndex;
	}

	// Color
	if  (vertexFormat.HasSingleElement( CVertexFormat::eSE_Color ))
	{
		glEnableVertexAttribArray( attribIndex );
		glVertexAttribPointer( attribIndex, 3, GL_FLOAT, false, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_Color ) );
		++attribIndex;
	}

	// UV
	for ( size_t iInstance = 0; iInstance < vertexFormat.GetMultipleElementCount(CVertexFormat::eME_UV); ++iInstance )
	{
		glEnableVertexAttribArray( attribIndex );
		glVertexAttribPointer( attribIndex, 2, GL_FLOAT, false, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetMultipleElementOffset( CVertexFormat::eME_UV, iInstance ) );
		++attribIndex;
	}

	// Bones
	if  (vertexFormat.HasSingleElement( CVertexFormat::eSE_BoneWeights ))
	{
		glEnableVertexAttribArray( attribIndex );
		glVertexAttribPointer( attribIndex, 4, GL_FLOAT, false, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_BoneWeights ) );
		++attribIndex;

		glEnableVertexAttribArray( attribIndex );
		glVertexAttribPointer( attribIndex, 4, GL_FLOAT, false, (GLsizei)vertexFormat.GetSize(), (void*)(vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_BoneWeights ) + sizeof(float)*4) );
		++attribIndex;
	}

#if defined(OLD_OPENGL)
	// Position
	glEnableClientState( GL_VERTEX_ARRAY );
	glVertexPointer( 3, GL_FLOAT, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_Position ) );

	// Normal
	if ( vertexFormat.HasSingleElement( CVertexFormat::eSE_Normal ) )
	{
		glEnableClientState( GL_NORMAL_ARRAY );
		glNormalPointer( GL_FLOAT, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_Normal ) );
	}

	// Color
	if ( vertexFormat.HasSingleElement( CVertexFormat::eSE_Color ) )
	{
		glEnableClientState( GL_COLOR_ARRAY );
		glColorPointer( 3, GL_FLOAT, vertexFormat.GetSize(), (void*)vertexFormat.GetSingleElementOffset( CVertexFormat::eSE_Color ) );
	}
	
	// UV
	for( size_t iInstance = 0 ; iInstance < vertexFormat.GetMultipleElementCount( CVertexFormat::eME_UV ) ; ++iInstance )
	{
		glEnableClientState( GL_TEXTURE_COORD_ARRAY );
		glTexCoordPointer( 2, GL_FLOAT, (GLsizei)vertexFormat.GetSize(), (void*)vertexFormat.GetMultipleElementOffset( CVertexFormat::eME_UV, iInstance ) );
	}
#endif
}
Example #14
0
void Renderer::drawRoom()
{
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_DOUBLE, 0, vertexBuffer);

	if(lighting){
		glEnableClientState(GL_NORMAL_ARRAY);
		glNormalPointer(GL_DOUBLE, 0, normalBuffer);
	}

	if(materials){
		glMaterialfv(GL_FRONT,GL_AMBIENT,brickAmbient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,brickDiffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,brickSpecular);
		glMaterialfv(GL_FRONT,GL_EMISSION,brickEmission);
		glMaterialf (GL_FRONT,GL_SHININESS,brickShininess);
	}

	if(textured){
		glEnable(GL_TEXTURE_2D);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

		//animate the sky texture
		double x1,x2;
		
		x1 = textureCoord[24];
		x2 = textureCoord[28];
		
		x1 += 0.0002;
		x2 += 0.0002;
		
		textureCoord[24] = textureCoord[26] = x1;
		textureCoord[28] = textureCoord[30] = x2;
		
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_DOUBLE, 0, textureCoord);
		
		glEnable(GL_TEXTURE_2D);
		
		glBindTexture(GL_TEXTURE_2D, textureID[0]);
		glDrawArrays(GL_QUADS,0,8);
		glDrawArrays(GL_QUADS,16,8);
		glBindTexture(GL_TEXTURE_2D, textureID[1]);
		glMaterialfv(GL_FRONT, GL_EMISSION, skyEmission);
		glDrawArrays(GL_QUADS,12,4);
		glBindTexture(GL_TEXTURE_2D, textureID[2]);
		glDrawArrays(GL_QUADS,8,4);
		glMaterialfv(GL_FRONT, GL_EMISSION, defEmission);
		
		glDisable(GL_TEXTURE_2D);
	}
	else {
		glColor3d(1,1,0);
		glDrawArrays(GL_QUADS,0,4);
		glColor3d(1,0,0);
		glDrawArrays(GL_QUADS,4,4);
		glColor3d(1,.5,0);
		glDrawArrays(GL_QUADS,8,4);
		glColor3d(0,1,0);
		glDrawArrays(GL_QUADS,12,4);
		glColor3d(0,0,1);
		glDrawArrays(GL_QUADS,16,4);
		glColor3d(1,0,1);
		glDrawArrays(GL_QUADS,20,4);
	}
}
Example #15
0
void primitive::render(u32 hints)
{
#ifdef _EE
    ps2_renderer::get()->render(0,m_size,&m_positions[0].x,&m_normals[0].x,&m_colours[0].x);
#else
#ifdef FLX_LINUX
    float *fltpos=new float[m_size*3];
    float *fltnrm=new float[m_size*3];
    float *fltcol=new float[m_size*3];
    float *flttex=new float[m_size*3];
    int pos=0;
    int cpos=0;
    for (int i=0; i<m_size; i++)
    {
        fltpos[pos]=m_positions[i].x;
        fltnrm[pos]=m_normals[i].x;
        fltcol[pos]=m_colours[i].x;
        flttex[pos++]=m_tex[i].x;
        fltpos[pos]=m_positions[i].y;
        fltnrm[pos]=m_normals[i].y;
        fltcol[pos]=m_colours[i].y;
        flttex[pos++]=m_tex[i].y;
        fltpos[pos]=m_positions[i].z;
        fltnrm[pos]=m_normals[i].z;
        fltcol[pos]=m_colours[i].z;
        flttex[pos++]=m_tex[i].z;
    }
    glVertexPointer(3, GL_FLOAT, 0, fltpos);
    glNormalPointer(GL_FLOAT, 0, fltnrm);
    glColorPointer(3, GL_FLOAT, 0, fltcol);
    glTexCoordPointer(3, GL_FLOAT, 0, flttex);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glColor3f(1,1,1);

    if (hints&HINT_SOLID)
    {
        glDrawArrays(m_type, 0, m_size);
    }

    if (hints&HINT_WIRE)
    {
        glDisableClientState(GL_COLOR_ARRAY);
        glColor3f(0,0,0);
        glDrawArrays(GL_LINE_STRIP, 0, m_size);
    }

    delete[] fltpos;
    delete[] fltnrm;
    delete[] fltcol;
    delete[] flttex;

#else

    glVertexPointer(3, GL_FIXED, 0, &m_positions[0]);

    if (m_colours!=NULL)
    {
        for (int i=0; i<m_size; i++)
        {
            m_colours_[i*4]=(float)m_colours[i].x*255.0f;
            m_colours_[i*4+1]=(float)m_colours[i].y*255.0f;
            m_colours_[i*4+2]=(float)m_colours[i].z*255.0f;
            m_colours_[i*4+3]=255;
        }

        glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_colours_);
        glEnableClientState(GL_COLOR_ARRAY);
    }
    else
    {
        glDisableClientState(GL_COLOR_ARRAY);
    }

    if (m_normals!=NULL)
    {
        glNormalPointer(GL_FIXED, 0, &m_normals[0]);
        glEnableClientState(GL_NORMAL_ARRAY);
    }
    else
    {
        glDisableClientState(GL_NORMAL_ARRAY);
    }

    if (m_tex!=NULL)
    {
        glTexCoordPointer(3, GL_FIXED, 0, &m_tex[0]);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    }
    else
    {
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    }

    if (hints&HINT_SOLID)
    {
        glDrawArrays(m_type, 0, m_size);
    }

    if (hints&HINT_WIRE)
    {
        glDisableClientState(GL_COLOR_ARRAY);
        glDrawArrays(GL_LINE_STRIP, 0, m_size);
    }
#endif
#endif // _EE
}
Example #16
0
void Model::renderMesh(bool bWireframe, bool bLight)
{
  // get the renderer of the model
  CalRenderer *pCalRenderer;
  pCalRenderer = m_calModel->getRenderer();

  // begin the rendering loop
  if(!pCalRenderer->beginRendering()) return;

  // set wireframe mode if necessary
  if(bWireframe)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  }

  // set the global OpenGL states
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);

  // set the lighting mode if necessary
  if(bLight)
  {
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
  }

  // we will use vertex arrays, so enable them
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);

  // get the number of meshes
  int meshCount;
  meshCount = pCalRenderer->getMeshCount();

  // render all meshes of the model
  int meshId;
  for(meshId = 0; meshId < meshCount; meshId++)
  {
    // get the number of submeshes
    int submeshCount;
    submeshCount = pCalRenderer->getSubmeshCount(meshId);

    // render all submeshes of the mesh
    int submeshId;
    for(submeshId = 0; submeshId < submeshCount; submeshId++)
    {
      // select mesh and submesh for further data access
      if(pCalRenderer->selectMeshSubmesh(meshId, submeshId))
      {
        unsigned char meshColor[4];
        GLfloat materialColor[4];

        // set the material ambient color
        pCalRenderer->getAmbientColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor);

        // set the material diffuse color
        pCalRenderer->getDiffuseColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor);

        // set the vertex color if we have no lights
        if(!bLight)
        {
          glColor4fv(materialColor);
        }

        // set the material specular color
        pCalRenderer->getSpecularColor(&meshColor[0]);
        materialColor[0] = meshColor[0] / 255.0f;  materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f;
        glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor);

        // set the material shininess factor
        float shininess;
        shininess = 50.0f; //TODO: pCalRenderer->getShininess();
        glMaterialfv(GL_FRONT, GL_SHININESS, &shininess);

        // get the transformed vertices of the submesh
        static float meshVertices[30000][3];
        int vertexCount;
        vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);

        // get the transformed normals of the submesh
        static float meshNormals[30000][3];
        pCalRenderer->getNormals(&meshNormals[0][0]);

        // get the texture coordinates of the submesh
        static float meshTextureCoordinates[30000][2];
        int textureCoordinateCount;
        textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);

        // get the faces of the submesh
        static CalIndex meshFaces[50000][3];
        int faceCount;
        faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);

        // set the vertex and normal buffers
        glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
        glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);

        // set the texture coordinate buffer and state if necessary
        if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
        {
          glEnable(GL_TEXTURE_2D);
          glEnableClientState(GL_TEXTURE_COORD_ARRAY);
          glEnable(GL_COLOR_MATERIAL);

          // set the texture id we stored in the map user data
          glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));

          // set the texture coordinate buffer
          glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0]);
          glColor3f(1.0f, 1.0f, 1.0f);
        }

        // draw the submesh
        
        if(sizeof(CalIndex)==2)
			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
		  else
			  glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);

        // disable the texture coordinate state if necessary
        if((pCalRenderer->getMapCount() > 0) && (textureCoordinateCount > 0))
        {
          glDisable(GL_COLOR_MATERIAL);
          glDisableClientState(GL_TEXTURE_COORD_ARRAY);
          glDisable(GL_TEXTURE_2D);
        }
      }
    }
  }

  // clear vertex array state
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);

  // reset the lighting mode
  if(bLight)
  {
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
  }

  // reset the global OpenGL states
  glDisable(GL_DEPTH_TEST);

  // reset wireframe mode if necessary
  if(bWireframe)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  }

  // end the rendering
  pCalRenderer->endRendering();
}
Example #17
0
void draw_mesh(t_draw *draw, t_scene *scene, t_mesh *mesh)
{
	t_node *node;
	t_texture *texture=NULL;

	// BUFFERS
	if(mesh->state.buffer_type!=buffer_vbo) mesh_init_buffers(mesh,buffer_vbo); 

	float *color=draw->front_color;


	// TEXTURE
	if(draw->with_texture && mesh->state.with_texture)
	{
		node = scene_get_node_by_type_name( scene, dt_texture, mesh->texture_name);
		texture = ( t_texture *) node->data;

		if(texture && mesh->quad_uv)
		{
			glEnable(GL_TEXTURE_2D);

			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer( 2, GL_INT, 0, mesh->quad_uv->data);
			glBindTexture(GL_TEXTURE_2D,texture->id_gl); 

		}
	}

	// MATERIAL
	if (draw->with_material)
	{
		t_material *material = mesh->material;

		if(material)
		{
			float color[4];

			color[0]=material->color[0];
			color[1]=material->color[1]; 
			color[2]=material->color[2];
			color[3]=material->color[3];

			glMaterialfv(GL_FRONT,GL_SPECULAR, mesh->material->specular);
			glMaterialfv(GL_FRONT,GL_SHININESS, mesh->material->shininess);
			glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE, color);
		}
	}


	// vertex arrays
	glEnableClientState(GL_VERTEX_ARRAY);

	glShadeModel(GL_FLAT);

	// draw node

	// SELECTION MODE for drawing wire cube to solid cube
	if(draw->mode==mode_selection)
	{
		if (draw->with_light)
		{
			glEnable(GL_LIGHTING);
			GLfloat model_ambient[] = {1,1,1,1};
			glLightModelfv(GL_LIGHT_MODEL_AMBIENT,model_ambient);
		}
		// quads 
		//if (mesh->quad_faces && mesh->state.has_quad)
		if (mesh->state.has_quad)
		{
			glVertexPointer(3,GL_FLOAT,0,(float *)mesh->quad_vertex->data);
			if(mesh->quad_normal && draw->with_normal) glNormalPointer(GL_FLOAT,0,mesh->quad_normal->data);
			if(mesh->quad_color && draw->mode==mode_selection) glColorPointer(3,GL_FLOAT,0,mesh->quad_color->data);
			if(mesh->quad_face) glDrawElements(GL_QUADS,mesh->var.tot_quad_face*4,GL_UNSIGNED_INT,mesh->quad_face->data); 
		}

		// triangles
		if(mesh->state.has_tri)
		{
			glVertexPointer(3,GL_FLOAT,0,(float *)mesh->tri_vertex->data);
			if(mesh->tri_normal && draw->with_normal) glNormalPointer(GL_FLOAT,0,mesh->tri_normal->data);
			if(mesh->tri_color && draw->mode==mode_selection) glColorPointer(3,GL_FLOAT,0,mesh->tri_color->data);
			if(mesh->tri_face) glDrawElements(GL_TRIANGLES,mesh->var.tot_tri_face*3,GL_UNSIGNED_INT,mesh->tri_face->data); 

		}
	}
	// DRAW MODE draw faces
	else if(draw->with_face && mesh->state.has_face)
	{
		if (draw->with_light)
		{
			glEnable(GL_LIGHTING);
			GLfloat model_ambient[] = {1,1,1,1};
			glLightModelfv(GL_LIGHT_MODEL_AMBIENT,model_ambient);
		}
		
		if(draw->mode==mode_selection) glEnableClientState(GL_COLOR_ARRAY);
		if(draw->with_normal) glEnableClientState(GL_NORMAL_ARRAY);

		// quads 

		if (mesh->state.has_quad)
		{
			glVertexPointer(3,GL_FLOAT,0,(float *)mesh->quad_vertex->data);
			if(mesh->quad_normal && draw->with_normal) glNormalPointer(GL_FLOAT,0,mesh->quad_normal->data);
			if(mesh->quad_color && draw->mode==mode_selection) glColorPointer(3,GL_FLOAT,0,mesh->quad_color->data);
			if(mesh->quad_face) glDrawElements(GL_QUADS,mesh->var.tot_quad_face*4,GL_UNSIGNED_INT,mesh->quad_face->data); 
		}


		// triangles

		if(mesh->state.has_tri)
		{
			if (mesh->tri_vertex)
			{
				glVertexPointer(3,GL_FLOAT,0,mesh->tri_vertex->data);
				if(mesh->tri_normal && draw->with_normal) glNormalPointer(GL_FLOAT,0,mesh->tri_normal->data);
				if(mesh->tri_color && draw->mode==mode_selection) glColorPointer(3,GL_FLOAT,0,mesh->tri_color->data);//XXX
				if(mesh->tri_face) glDrawElements(GL_TRIANGLES,mesh->var.tot_tri_face*3,GL_UNSIGNED_INT,mesh->tri_face->data);
			}
		}
	}

	// edges
	if(mesh->state.with_line) draw_mesh_edge( draw, mesh);

	// outline
	if(
		mesh->state.is_selected
		&& draw->mode == mode_draw
		&& draw->with_face)
	{
		if(mesh->state.has_face)
		{
			glDisable(GL_LIGHTING);
			glPushAttrib( GL_ALL_ATTRIB_BITS );
			glEnable( GL_POLYGON_OFFSET_FILL );
			glPolygonOffset( -2.5f, -2.5f );
			glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
			glLineWidth( 4.0f );
			glColor3f(color[0],color[1],color[2]);

			if(mesh->state.has_quad) glDrawElements(GL_QUADS,mesh->var.tot_quad_face*4,GL_UNSIGNED_INT,mesh->quad_face->data); 

			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
			glEnable( GL_LIGHTING );
			glColor3f( 0.0f, 0.0f, 0.0f );

			if(mesh->state.has_quad) glDrawElements(GL_QUADS,mesh->var.tot_quad_face*4,GL_UNSIGNED_INT,mesh->quad_face->data); 

			glPopAttrib();

		}
	}


	// unbind texture
	if(texture) glBindTexture(GL_TEXTURE_2D,0); 

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

	// Points
	if(draw->with_point)
	{
		draw_mesh_points(draw,mesh);
	}
}
Example #18
0
void render() {
    int i;

    //Typical render pass
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //First render background and menu if it is enabled
    enable_2d();

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

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

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    glVertexPointer(2, GL_FLOAT, 0, background_vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, background_tex_coord);
    glBindTexture(GL_TEXTURE_2D, background);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    if (menu_active || menu_show_animation || menu_hide_animation) {
        glTranslatef(pos_x, pos_y, 0.0f);

        for (i = 0; i < 4; i++) {
            if (i == selected) {
                glVertexPointer(2, GL_FLOAT, 0, radio_btn_selected_vertices);
                glTexCoordPointer(2, GL_FLOAT, 0, radio_btn_selected_tex_coord);
                glBindTexture(GL_TEXTURE_2D, radio_btn_selected);
            } else {
                glVertexPointer(2, GL_FLOAT, 0, radio_btn_unselected_vertices);
                glTexCoordPointer(2, GL_FLOAT, 0,
                        radio_btn_unselected_tex_coord);
                glBindTexture(GL_TEXTURE_2D, radio_btn_unselected);
            }

            glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
            glTranslatef(0.0f, 60.0f, 0.0f);
        }

        bbutil_render_text(font, "Color Menu", 10.0f, 10.0f, 0.35f, 0.35f, 0.35f, 1.0f);
        bbutil_render_text(font, "Red", 70.0f, -40.0f, 0.35f, 0.35f, 0.35f, 1.0f);
        bbutil_render_text(font, "Green", 70.0f, -100.0f, 0.35f, 0.35f, 0.35f, 1.0f);
        bbutil_render_text(font, "Blue", 70.0f, -160.0f, 0.35f, 0.35f, 0.35f, 1.0f);
        bbutil_render_text(font, "Yellow", 70.0f, -220.0f, 0.35f, 0.35f, 0.35f, 1.0f);
    }

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_TEXTURE_2D);

    //Then render the cube
    enable_3d();
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_DEPTH_TEST);

    glTranslatef(cube_pos_x, cube_pos_y, cube_pos_z);

    glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
    glRotatef(15.0f, 0.0f, 0.0f, 1.0f);
    glRotatef(angle, 0.0f, 1.0f, 0.0f);

    glColor4f(cube_color[0], cube_color[1], cube_color[2], cube_color[3]);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    glVertexPointer(3, GL_FLOAT, 0, cube_vertices);
    glNormalPointer(GL_FLOAT, 0, cube_normals);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
    glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_DEPTH_TEST);

    //Use utility code to update the screen
    bbutil_swap();
}
Example #19
0
static void
setup_legacy_buffered_attribute (CoglContext *ctx,
                                 CoglPipeline *pipeline,
                                 CoglAttribute *attribute,
                                 uint8_t *base)
{
  switch (attribute->name_state->name_id)
    {
    case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
      _cogl_bitmask_set (&ctx->enable_builtin_attributes_tmp,
                         COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY, TRUE);
      GE (ctx, glColorPointer (attribute->d.buffered.n_components,
                               attribute->d.buffered.type,
                               attribute->d.buffered.stride,
                               base + attribute->d.buffered.offset));
      break;
    case COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY:
      _cogl_bitmask_set (&ctx->enable_builtin_attributes_tmp,
                         COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY, TRUE);
      GE (ctx, glNormalPointer (attribute->d.buffered.type,
                                attribute->d.buffered.stride,
                                base + attribute->d.buffered.offset));
      break;
    case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
      {
        int layer_number = attribute->name_state->layer_number;
        const CoglPipelineGetLayerFlags flags =
          COGL_PIPELINE_GET_LAYER_NO_CREATE;
        CoglPipelineLayer *layer =
          _cogl_pipeline_get_layer_with_flags (pipeline, layer_number, flags);

        if (layer)
          {
            int unit = _cogl_pipeline_layer_get_unit_index (layer);

            _cogl_bitmask_set (&ctx->enable_texcoord_attributes_tmp,
                               unit,
                               TRUE);

            GE (ctx, glClientActiveTexture (GL_TEXTURE0 + unit));
            GE (ctx, glTexCoordPointer (attribute->d.buffered.n_components,
                                        attribute->d.buffered.type,
                                        attribute->d.buffered.stride,
                                        base + attribute->d.buffered.offset));
          }
        break;
      }
    case COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY:
      _cogl_bitmask_set (&ctx->enable_builtin_attributes_tmp,
                         COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY, TRUE);
      GE (ctx, glVertexPointer (attribute->d.buffered.n_components,
                                attribute->d.buffered.type,
                                attribute->d.buffered.stride,
                                base + attribute->d.buffered.offset));
      break;
    case COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY:
#ifdef COGL_PIPELINE_PROGEND_GLSL
      if (ctx->private_feature_flags & COGL_PRIVATE_FEATURE_GL_PROGRAMMABLE)
        setup_generic_buffered_attribute (ctx, pipeline, attribute, base);
#endif
      break;
    default:
      g_warn_if_reached ();
    }
}
Example #20
0
void C3ds::render() {

  ShaderMgr::get().useProgram(shader);
  //glVertexPointer(3,GL_FLOAT,0,vertex);
  //glNormalPointer(GL_FLOAT,0,normal);
  glEnable(GL_TEXTURE_2D);
  //glEnable(GL_LIGHTING);
  //glDisable(GL_BLEND);
  //glEnable(GL_BLEND);
  glEnable(GL_COLOR_MATERIAL);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glPushMatrix();

  glMaterialfv(GL_FRONT, GL_AMBIENT, (float*) (&ambientColor));
  glMaterialfv(GL_FRONT, GL_DIFFUSE, (float*) (&diffuseColor));
  glMaterialfv(GL_FRONT, GL_SPECULAR, (float*) (&specColor));

  glMaterialf(GL_FRONT, GL_SHININESS, shininess);

  glScalef(scale, scale, scale);
  TextureMgr::get().use(texture);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
  glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer[1]);
  glVertexPointer(3, GL_FLOAT, 0, 0);
  glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer[2]);
  glNormalPointer(GL_FLOAT, 0, 0);
  if (numTexCoords == numVerts) {
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer[3]);
    glTexCoordPointer(2, GL_FLOAT, 0, 0);
  }
  glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer[0]);
  glDrawElements(GL_TRIANGLES, numFaces * 3, GL_UNSIGNED_SHORT, 0);
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);

  /*
   glBegin(GL_TRIANGLES);
   
   for(int i=0;i<numFaces;i++)
   {
   //glNormal3f(fnormal[i].x,fnormal[i].y,fnormal[i].z);
   if(texcoord)glTexCoord2f(texcoord[face[i].p1].u*TexCoordUScale,texcoord[face[i].p1].v*TexCoordVScale);
   glNormal3f(normal[face[i].p1].x,normal[face[i].p1].y,normal[face[i].p1].z);
   glVertex3f(vertex[face[i].p1].x,vertex[face[i].p1].y,vertex[face[i].p1].z);
   if(texcoord)glTexCoord2f(texcoord[face[i].p2].u*TexCoordUScale,texcoord[face[i].p2].v*TexCoordVScale);
   glNormal3f(normal[face[i].p2].x,normal[face[i].p2].y,normal[face[i].p2].z);
   glVertex3f(vertex[face[i].p2].x,vertex[face[i].p2].y,vertex[face[i].p2].z);
   if(texcoord)glTexCoord2f(texcoord[face[i].p3].u*TexCoordUScale,texcoord[face[i].p3].v*TexCoordVScale);
   glNormal3f(normal[face[i].p3].x,normal[face[i].p3].y,normal[face[i].p3].z);
   glVertex3f(vertex[face[i].p3].x,vertex[face[i].p3].y,vertex[face[i].p3].z);
   }
   glEnd();
   */
  glPopMatrix();
  glDisable(GL_COLOR_MATERIAL);
  ShaderMgr::get().useNone();
  //glEnable(GL_TEXTURE_2D);
}
Example #21
0
 void RenderBox(GLfloat size)
{
#if defined(_XBOX) | defined(__CELLOS_LV2__) | defined(__PPCGEKKO__)
    glutSolidCube(size);    // doesn't include texcoords
#elif defined (_GLES1_)

// Triangle fan method. Box is split into two triangle fans centered at diagonally opposite verts. Three box faces and six triangles per fan.

GLfloat v[24] = { 
					size * 1.0f,  size * 1.0f, size * 1.0f,
					size * 1.0f,  size * 1.0f,-size * 1.0f,
					size * 1.0f, -size * 1.0f,-size * 1.0f,
					size * 1.0f, -size * 1.0f, size * 1.0f,
					-size * 1.0f,-size * 1.0f, size * 1.0f,
					-size * 1.0f, size * 1.0f, size * 1.0f,
					-size * 1.0f, size * 1.0f, -size * 1.0f,
					-size * 1.0f,-size * 1.0f, -size * 1.0f
					};
					
					
GLfloat T1[18] = {

					v[0], v[1], v[2],
					v[0], v[2], v[3],
					v[0], v[3], v[4],
					v[0], v[4], v[5],
					v[0], v[5], v[6],
					v[0], v[6], v[1]
					};
GLfloat T2[18] = {
					v[7], v[6], v[5],
					v[7], v[5], v[4],
					v[7], v[4], v[3],
					v[7], v[3], v[2],
					v[7], v[2], v[1],
					v[7], v[1], v[6]
					};
GLfloat N1[21] = {
					1.0f, 0.0f, 0.0f,
					1.0f, 0.0f, 0.0f,
					1.0f, 0.0f, 0.0f,
					0.0f, 0.0f, 1.0f,
					0.0f, 0.0f, 1.0f,
					0.0f, 1.0f, 0.0f,
					0.0f, 1.0f, 0.0f
					};
GLfloat N2[18] = {
					-1.0f, 0.0f, 0.0f,
					-1.0f, 0.0f, 0.0f,
					 0.0f,-1.0f, 0.0f,
					 0.0f,-1.0f, 0.0f,
					 0.0f, 0.0f,-1.0f,
					 0.0f, 0.0f,-1.0f
					 };




	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	
	//glVertexPointer(3, GL_FLOAT, 2*3*sizeof(float), 6, gPlaneData);
    //glNormalPointer(GL_FLOAT, 2*3*sizeof(float), 6, gPlaneData+3);
	
    glVertexPointer(3, GL_FLOAT, 3*sizeof(float), T1);
    glNormalPointer(GL_FLOAT, 3*sizeof(float), N1);
	glDrawArrays(GL_TRIANGLES, 0, 6);
	glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	
	//glVertexPointer(3, GL_FLOAT, 3*sizeof(float), T2);
    //glNormalPointer(GL_FLOAT, 3*sizeof(float), N2);
	//glDrawArrays(GL_TRIANGLES, 0, 18);



#else
    static GLfloat n[6][3] =
    {
        {-1.0, 0.0, 0.0},
        {0.0, 1.0, 0.0},
        {1.0, 0.0, 0.0},
        {0.0, -1.0, 0.0},
        {0.0, 0.0, 1.0},
        {0.0, 0.0, -1.0}
    };
    static GLint faces[6][4] =
    {
        {0, 1, 2, 3},
        {3, 2, 6, 7},
        {7, 6, 5, 4},
        {4, 5, 1, 0},
        {5, 6, 2, 1},
        {7, 4, 0, 3}
    };
    GLfloat v[8][3];
    GLint i;

    v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
    v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
    v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
    v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
    v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
    v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;

    for (i = 5; i >= 0; i--) {
        glBegin(GL_QUADS);
        glNormal3fv(&n[i][0]);
        glTexCoord2f(0.0f, 0.0f); glVertex3fv(&v[faces[i][0]][0]);
        glTexCoord2f(1.0f, 0.0f); glVertex3fv(&v[faces[i][1]][0]);
        glTexCoord2f(1.0f, 1.0f); glVertex3fv(&v[faces[i][2]][0]);
        glTexCoord2f(0.0f, 1.0f); glVertex3fv(&v[faces[i][3]][0]);
        glEnd();
    }
#endif
}
Example #22
0
void NormalOffset(  int size, unsigned int type, int offset )
{
    glNormalPointer( type, 0,  (const GLvoid*)offset );
}
void RenderableBoxEntityItem::render(RenderArgs* args) {
    PerformanceTimer perfTimer("RenderableBoxEntityItem::render");
    assert(getType() == EntityTypes::Box);
    glm::vec3 position = getPositionInMeters();
    glm::vec3 center = getCenter() * (float)TREE_SCALE;
    glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE;
    glm::vec3 halfDimensions = dimensions / 2.0f;
    glm::quat rotation = getRotation();

    const bool useGlutCube = true;
    
    if (useGlutCube) {
        glColor3ub(getColor()[RED_INDEX], getColor()[GREEN_INDEX], getColor()[BLUE_INDEX]);
        glPushMatrix();
            glTranslatef(position.x, position.y, position.z);
            glm::vec3 axis = glm::axis(rotation);
            glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
            glPushMatrix();
                glm::vec3 positionToCenter = center - position;
                glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
                glScalef(dimensions.x, dimensions.y, dimensions.z);
                glutSolidCube(1.0f);
            glPopMatrix();
        glPopMatrix();
    } else {
        static GLfloat vertices[] = { 1, 1, 1,  -1, 1, 1,  -1,-1, 1,   1,-1, 1,   // v0,v1,v2,v3 (front)
                                      1, 1, 1,   1,-1, 1,   1,-1,-1,   1, 1,-1,   // v0,v3,v4,v5 (right)
                                      1, 1, 1,   1, 1,-1,  -1, 1,-1,  -1, 1, 1,   // v0,v5,v6,v1 (top)
                                     -1, 1, 1,  -1, 1,-1,  -1,-1,-1,  -1,-1, 1,   // v1,v6,v7,v2 (left)
                                     -1,-1,-1,   1,-1,-1,   1,-1, 1,  -1,-1, 1,   // v7,v4,v3,v2 (bottom)
                                      1,-1,-1,  -1,-1,-1,  -1, 1,-1,   1, 1,-1 }; // v4,v7,v6,v5 (back)

        // normal array
        static GLfloat normals[]  = { 0, 0, 1,   0, 0, 1,   0, 0, 1,   0, 0, 1,   // v0,v1,v2,v3 (front)
                                    1, 0, 0,   1, 0, 0,   1, 0, 0,   1, 0, 0,   // v0,v3,v4,v5 (right)
                                    0, 1, 0,   0, 1, 0,   0, 1, 0,   0, 1, 0,   // v0,v5,v6,v1 (top)
                                   -1, 0, 0,  -1, 0, 0,  -1, 0, 0,  -1, 0, 0,   // v1,v6,v7,v2 (left)
                                    0,-1, 0,   0,-1, 0,   0,-1, 0,   0,-1, 0,   // v7,v4,v3,v2 (bottom)
                                    0, 0,-1,   0, 0,-1,   0, 0,-1,   0, 0,-1 }; // v4,v7,v6,v5 (back)

        // index array of vertex array for glDrawElements() & glDrawRangeElement()
        static GLubyte indices[]  = { 0, 1, 2,   2, 3, 0,      // front
                                      4, 5, 6,   6, 7, 4,      // right
                                      8, 9,10,  10,11, 8,      // top
                                     12,13,14,  14,15,12,      // left
                                     16,17,18,  18,19,16,      // bottom
                                     20,21,22,  22,23,20 };    // back



        glEnableClientState(GL_NORMAL_ARRAY);
        glEnableClientState(GL_VERTEX_ARRAY);
        glNormalPointer(GL_FLOAT, 0, normals);
        glVertexPointer(3, GL_FLOAT, 0, vertices);

        glColor3ub(getColor()[RED_INDEX], getColor()[GREEN_INDEX], getColor()[BLUE_INDEX]);
        
        glPushMatrix();
            glTranslatef(position.x, position.y, position.z);
            glm::vec3 axis = glm::axis(rotation);
            glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
            glPushMatrix();
                glm::vec3 positionToCenter = center - position;
                glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
                // we need to do half the size because the geometry in the VBOs are from -1,-1,-1 to 1,1,1 
                glScalef(halfDimensions.x, halfDimensions.y, halfDimensions.z);
                glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
            glPopMatrix();
        glPopMatrix();

        glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays
        glDisableClientState(GL_NORMAL_ARRAY);
    }    
};
Example #24
0
	void cVertexBufferVBO::SetVertexStates(tVertexFlag aFlags)
	{
		/// COLOR 0 /////////////////////////
		if(aFlags & eVertexFlag_Color0)
		{
			glEnableClientState(GL_COLOR_ARRAY );

			int idx = cMath::Log2ToInt(eVertexFlag_Color0);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glColorPointer(kvVertexElements[idx],GL_FLOAT, 0, (char*)NULL);
		}
		else
		{
			glDisableClientState(GL_COLOR_ARRAY );
		}

		/// NORMAL /////////////////////////
		if(aFlags & eVertexFlag_Normal)
		{
			glEnableClientState(GL_NORMAL_ARRAY );

			int idx = cMath::Log2ToInt(eVertexFlag_Normal);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glNormalPointer(GL_FLOAT, 0, (char*)NULL);
		}
		else
		{
			glDisableClientState(GL_NORMAL_ARRAY );
		}

		/// TEXTURE 0 /////////////////////////
		if(aFlags & eVertexFlag_Texture0)
		{
			glClientActiveTextureARB(GL_TEXTURE0_ARB);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY );

			int idx =  cMath::Log2ToInt(eVertexFlag_Texture0);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glTexCoordPointer(kvVertexElements[idx],GL_FLOAT,0,(char*)NULL );
		}
		else {
			glClientActiveTextureARB(GL_TEXTURE0_ARB);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY );
		}

		/// TEXTURE 1 /////////////////////////
		if(aFlags & eVertexFlag_Texture1){
			glClientActiveTextureARB(GL_TEXTURE1_ARB);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY );

			int idx =  cMath::Log2ToInt(eVertexFlag_Texture1);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);

			if(mbTangents)
				glTexCoordPointer(4,GL_FLOAT,0,(char*)NULL );
			else
				glTexCoordPointer(kvVertexElements[idx],GL_FLOAT,0,(char*)NULL );
		}
		else {
			glClientActiveTextureARB(GL_TEXTURE1_ARB);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY );
		}

		/// TEXTURE 2 /////////////////////////
		if(aFlags & eVertexFlag_Texture2){
			glClientActiveTextureARB(GL_TEXTURE2_ARB);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY );

			int idx =  cMath::Log2ToInt(eVertexFlag_Texture2);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glTexCoordPointer(kvVertexElements[idx],GL_FLOAT,0,(char*)NULL );
		}
		else {
			glClientActiveTextureARB(GL_TEXTURE2_ARB);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY );
		}

		/// TEXTURE 3 /////////////////////////
		if(aFlags & eVertexFlag_Texture3){
			glClientActiveTextureARB(GL_TEXTURE3_ARB);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY );

			int idx =  cMath::Log2ToInt(eVertexFlag_Texture3);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glTexCoordPointer(kvVertexElements[idx],GL_FLOAT,0,(char*)NULL );
		}
		else {
			glClientActiveTextureARB(GL_TEXTURE3_ARB);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY );
		}

		/// TEXTURE 4 /////////////////////////
		if(aFlags & eVertexFlag_Texture4){
			glClientActiveTextureARB(GL_TEXTURE4_ARB);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY );

			int idx =  cMath::Log2ToInt(eVertexFlag_Texture4);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glTexCoordPointer(kvVertexElements[idx],GL_FLOAT,0,(char*)NULL );
		}
		else {
			glClientActiveTextureARB(GL_TEXTURE4_ARB);
			glDisableClientState(GL_TEXTURE_COORD_ARRAY );
		}

		/// POSITION /////////////////////////
		if(aFlags & eVertexFlag_Position){
			glEnableClientState(GL_VERTEX_ARRAY );

			int idx = cMath::Log2ToInt(eVertexFlag_Position);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB,mvArrayHandle[idx]);
			glVertexPointer(kvVertexElements[idx],GL_FLOAT, 0, (char*)NULL);
		}
		else
		{
			glDisableClientState(GL_VERTEX_ARRAY );
		}

		glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
	}
void IslandGame::redraw( )
{
	//static bool gfxInit = false;
	//if (!gfxInit)
	//{
	//	initGraphics();
	//	gfxInit = true;
	//}

	glClearColor( 0.3, 1.0, 1.0, 1.0 );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	// 3d stuff
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_TEXTURE_2D );
	glEnable( GL_TEXTURE );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();	

	int useOrtho = _TV(1);
	if (!useOrtho)
	{
		gluPerspective( _TV(2.0f), 800.0/600.0, 0.1, 1000.0 );
	}
	else
	{
		float aspect = 800.0 / 600.0;
		float hite = _TV(4.0f);
		glOrtho( -aspect * hite, aspect * hite, -hite, hite, 0.1, 1000.0 );
	}

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();	
	
	glDisable( GL_LIGHTING );

	// player
	MapSquare &mp = m_map[m_px][m_py];
	vec3f ppos( m_px + 0.5f, 
				(mp.m_elevation+1.0) * 0.3f, 
				m_py + 0.5f );
	
	//gluLookAt( ppos.x, ppos.y + 1, ppos.z + 1,
	//		   ppos.x, ppos.y, ppos.z,
	//		   0.0, 1.0, 0.0 );	
	glRotatef( _TV(29.7f), 1.0, 0.0, 0.0 );
	glTranslatef( _TV(0), _TV(-6), _TV(-8) );
	glRotatef( _TV(45.0f), 0.0, 1.0, 0.0 );

	glTranslatef( m_camPos.x * _TV(-1.0f), 
				  m_camPos.y * _TV( 0.0f), 
				  m_camPos.z  * _TV(-1.0f));
	

	//static float ang = 0;
	//glRotatef( ang, 0.0, 1.0, 0.0 );
	//ang += 1;	

	glDisable( GL_TEXTURE_2D );
#if 0	
	glLineWidth( 4.0 );
	glBegin( GL_LINES );

	glColor3f( 1.0, 0.0, 0.0 );
	glVertex3f( ppos.x-1.0, ppos.y + 0.01, ppos.z );
	glVertex3f( ppos.x+1.0, ppos.y + 0.01, ppos.z );

	glColor3f( 0.0, 1.0, 0.0 );
	glVertex3f( ppos.x, ppos.y -1.0, ppos.z );
	glVertex3f( ppos.x, ppos.y +1.0, ppos.z );

	glColor3f( 0.0, 0.0, 1.0 );
	glVertex3f( ppos.x, ppos.y + 0.01, ppos.z - 1.0 );
	glVertex3f( ppos.x, ppos.y + 0.01, ppos.z + 1.0 );

	glEnd();
#endif

	glColor3f( 1.0, 1.0, 1.0 );
	glEnable( GL_TEXTURE_2D );	

	// draw some stuff the easy way
	glBindTexture( GL_TEXTURE_2D, m_waterTexId );	
	glBegin( GL_QUADS );
	
	glTexCoord2f( 0.0, 0.0 );
	glVertex3f( -2000, 0, -2000 );

	glTexCoord2f( 0.0, 1000.0 );
	glVertex3f( -2000, 0, 2000 );

	glTexCoord2f( 1000.0, 1000.0 );
	glVertex3f( 2000, 0, 2000 );

	glTexCoord2f( 1000.0, 0.0 );
	glVertex3f( 2000, 0, -2000 );

	glEnd();

	glEnable( GL_TEXTURE_2D );	
	//glColor3f( 1.0, 0.0, 1.0 );	

	// draw player
	glPushMatrix();	
	glTranslatef( ppos.x, ppos.y, ppos.z );
	glScalef( 0.4f, 0.4f, 0.4f );
	glRotatef( getRotForDir(m_pdir), 0.0, 1.0, 0.0 );
	glBindTexture( GL_TEXTURE_2D, m_playerTex );
	glCallList( m_personMesh );
	glPopMatrix();

	// draw critters
	for (std::vector<Critter*>::iterator ci = m_critters.begin(); 
		 ci != m_critters.end(); ci++)
	{
		Critter *c = (*ci);
		float elev = (m_map[c->m_x][c->m_y].m_elevation + 1.0) * 0.3;
		glPushMatrix();	
		glTranslatef( c->m_x + 0.5f, elev, c->m_y + 0.5f );
		glScalef( 0.4f, 0.4f, 0.4f );

		if (c->m_behavior == BEHAVIOR_STATIC)
		{
			glRotatef( getRotLookAt( c->m_x, c->m_y ), 0.0, 1.0, 0.0 );
		}
		else
		{
			glRotatef( getRotForDir( c->m_dir ), 0.0, 1.0, 0.0 );
		}

		glBindTexture( GL_TEXTURE_2D, c->m_critterTex );
		glCallList( m_critterMesh );
		glPopMatrix();
	}

	// draw npcs
	for (std::vector<Npc*>::iterator ci = m_npcs.begin(); 
		 ci != m_npcs.end(); ci++)
	{
		Npc *npc = (*ci);
		float elev = (m_map[npc->m_x][npc->m_y].m_elevation + 1.0) * 0.3;
		glPushMatrix();	
		glTranslatef( npc->m_x + 0.5f, elev, npc->m_y + 0.5f );
		glScalef( 0.4f, 0.4f, 0.4f );
		glRotatef( getRotLookAt( npc->m_x, npc->m_y ), 0.0, 1.0, 0.0 );
		glBindTexture( GL_TEXTURE_2D, npc->m_personTex );
		glCallList( m_personMesh );
		glPopMatrix();
	}

	glEnable( GL_LIGHTING );
	glEnable( GL_LIGHT0 );
	glEnable( GL_LIGHT1 );	

	glBindTexture( GL_TEXTURE_2D, m_terrainTilesTexId );

	// Bind the island VBO
	glBindBuffer(GL_ARRAY_BUFFER, m_islandVBO);

	//glEnableVertexAttribArray( MapVert::ATTRIB_VERTEX);
	//glEnableVertexAttribArray( MapVert::ATTRIB_TEXCOORD );
	//glEnableVertexAttribArray( ATTRIB_NORMAL );
	
	//glVertexAttribPointer( MapVert::ATTRIB_VERTEX,   4, GL_FLOAT, GL_FALSE, sizeof(MapVert), 0);
	//glVertexAttribPointer( MapVert::ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof(MapVert), (void*)(3*sizeof(GLfloat)) );
	//glVertexAttribPointer( ATTRIB_NORMAL,   3, GL_FLOAT, GL_FALSE, sizeof(MapVert), (void*)(6*sizeof(GLfloat)) );
	
	//glBufferData( GL_ARRAY_BUFFER, sizeof(MapVert) * m_quadSize, 0, GL_STATIC_DRAW );
	//glVertexPointer( 4, GL_FLOAT, sizeof(MapVert), NULL );
	//

	glEnableClientState( GL_VERTEX_ARRAY );
	glVertexPointer( 3, GL_FLOAT, sizeof(MapVert), 0 );
	
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );	
	glTexCoordPointer( 2, GL_FLOAT, sizeof(MapVert), (void*)(4*sizeof(GLfloat)) );

	glEnableClientState( GL_NORMAL_ARRAY );
	glNormalPointer( GL_FLOAT, sizeof(MapVert), (void*)(6*sizeof(GLfloat)) );
	
	glDrawArrays( GL_QUADS, 0, m_quadSize );

	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	glDisableClientState( GL_NORMAL_ARRAY );
	glDisableClientState( GL_VERTEX_ARRAY );

	// 2D text and GUI stuff
	glDisable( GL_DEPTH_TEST );	
	
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glDisable( GL_LIGHTING );		
	

	glColor3f( 1.0, 1.0, 1.0 );
		
	if (m_showHudText)
	{
		gfEnableFont( m_fntFontId, 32 );
		gfBeginText();		

		// draw background box
		glDisable( GL_TEXTURE_2D );
		glColor4f( 0.0, 0.0, 0.0, 0.6 );
		glBegin( GL_QUADS );
		glVertex2f( 0, 0 ); glVertex2f( 0, 210 );
		glVertex2f( 800, 210 ); glVertex2f( 800, 0 );
		glEnd();
		glColor4f( 1.0, 1.0, 0.0, 1.0 );

		glEnable( GL_TEXTURE_2D );

		glTranslated( 20, 170, 0 );		
		gfDrawString( m_hudTitle.c_str() );
		gfEndText();

		glColor4f( 1.0, 1.0, 1.0, 1.0 );
		gfEnableFont( m_fntFontId, 20 );
		gfBeginText();		
		glTranslated( 20, 130, 0 );		
		gfDrawString( m_hudText.c_str() );
		gfEndText();
	}

}
Example #26
0
void ccGenericMesh::drawMeOnly(CC_DRAW_CONTEXT& context)
{
	ccGenericPointCloud* vertices = getAssociatedCloud();
	if (!vertices)
		return;

	handleColorRamp(context);

	//3D pass
	if (MACRO_Draw3D(context))
	{
		//any triangle?
		unsigned triNum = size();
		if (triNum == 0)
			return;

		//L.O.D.
		bool lodEnabled = (triNum > GET_MAX_LOD_FACES_NUMBER() && context.decimateMeshOnMove && MACRO_LODActivated(context));
		unsigned decimStep = (lodEnabled ? (unsigned)ceil((float)triNum*3 / (float)GET_MAX_LOD_FACES_NUMBER()) : 1);
		unsigned displayedTriNum = triNum / decimStep;

		//display parameters
		glDrawParams glParams;
		getDrawingParameters(glParams);
		glParams.showNorms &= bool(MACRO_LightIsEnabled(context));

		//vertices visibility
		const ccGenericPointCloud::VisibilityTableType* verticesVisibility = vertices->getTheVisibilityArray();
		bool visFiltering = (verticesVisibility && verticesVisibility->isAllocated());

		//wireframe ? (not compatible with LOD)
		bool showWired = isShownAsWire() && !lodEnabled;

		//per-triangle normals?
		bool showTriNormals = (hasTriNormals() && triNormsShown());
		//fix 'showNorms'
        glParams.showNorms = showTriNormals || (vertices->hasNormals() && m_normalsDisplayed);

		//materials & textures
		bool applyMaterials = (hasMaterials() && materialsShown());
		bool showTextures = (hasTextures() && materialsShown() && !lodEnabled);

		//GL name pushing
		bool pushName = MACRO_DrawEntityNames(context);
		//special case: triangle names pushing (for picking)
		bool pushTriangleNames = MACRO_DrawTriangleNames(context);
		pushName |= pushTriangleNames;

		if (pushName)
		{
			//not fast at all!
			if (MACRO_DrawFastNamesOnly(context))
				return;
			glPushName(getUniqueIDForDisplay());
			//minimal display for picking mode!
			glParams.showNorms = false;
			glParams.showColors = false;
			//glParams.showSF --> we keep it only if SF 'NaN' values are hidden
			showTriNormals = false;
			applyMaterials = false;
			showTextures = false;
		}

		//in the case we need to display scalar field colors
		ccScalarField* currentDisplayedScalarField = 0;
		bool greyForNanScalarValues = true;
		unsigned colorRampSteps = 0;
		ccColorScale::Shared colorScale(0);

		if (glParams.showSF)
		{
			assert(vertices->isA(CC_TYPES::POINT_CLOUD));
			ccPointCloud* cloud = static_cast<ccPointCloud*>(vertices);

			greyForNanScalarValues = (cloud->getCurrentDisplayedScalarField() && cloud->getCurrentDisplayedScalarField()->areNaNValuesShownInGrey());
			if (greyForNanScalarValues && pushName)
			{
				//in picking mode, no need to take SF into account if we don't hide any points!
				glParams.showSF = false;
			}
			else
			{
				currentDisplayedScalarField = cloud->getCurrentDisplayedScalarField();
				colorScale = currentDisplayedScalarField->getColorScale();
				colorRampSteps = currentDisplayedScalarField->getColorRampSteps();

				assert(colorScale);
				//get default color ramp if cloud has no scale associated?!
				if (!colorScale)
					colorScale = ccColorScalesManager::GetUniqueInstance()->getDefaultScale(ccColorScalesManager::BGYR);
			}
		}

		//materials or color?
		bool colorMaterial = false;
		if (glParams.showSF || glParams.showColors)
		{
			applyMaterials = false;
			colorMaterial = true;
			glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
			glEnable(GL_COLOR_MATERIAL);
		}

		//in the case we need to display vertex colors
		ColorsTableType* rgbColorsTable = 0;
		if (glParams.showColors)
		{
			if (isColorOverriden())
			{
				glColor3ubv(m_tempColor);
				glParams.showColors = false;
			}
			else
			{
				assert(vertices->isA(CC_TYPES::POINT_CLOUD));
				rgbColorsTable = static_cast<ccPointCloud*>(vertices)->rgbColors();
			}
		}
		else
		{
			glColor3fv(context.defaultMat.diffuseFront);
		}

		if (glParams.showNorms)
		{
			//DGM: Strangely, when Qt::renderPixmap is called, the OpenGL version can fall to 1.0!
			glEnable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE));
			glEnable(GL_LIGHTING);
			context.defaultMat.applyGL(true,colorMaterial);
		}

		//in the case we need normals (i.e. lighting)
		NormsIndexesTableType* normalsIndexesTable = 0;
		ccNormalVectors* compressedNormals = 0;
		if (glParams.showNorms)
		{
			assert(vertices->isA(CC_TYPES::POINT_CLOUD));
			normalsIndexesTable = static_cast<ccPointCloud*>(vertices)->normals();
			compressedNormals = ccNormalVectors::GetUniqueInstance();
		}

		//stipple mask
		if (stipplingEnabled())
			EnableGLStippleMask(true);

		if (!pushTriangleNames && !visFiltering && !(applyMaterials || showTextures) && (!glParams.showSF || greyForNanScalarValues))
		{
			//the GL type depends on the PointCoordinateType 'size' (float or double)
			GLenum GL_COORD_TYPE = sizeof(PointCoordinateType) == 4 ? GL_FLOAT : GL_DOUBLE;
			
			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(3,GL_COORD_TYPE,0,GetVertexBuffer());

			if (glParams.showNorms)
			{
				glEnableClientState(GL_NORMAL_ARRAY);
				glNormalPointer(GL_COORD_TYPE,0,GetNormalsBuffer());
			}
			if (glParams.showSF || glParams.showColors)
			{
				glEnableClientState(GL_COLOR_ARRAY);
				glColorPointer(3,GL_UNSIGNED_BYTE,0,GetColorsBuffer());
			}

			//we can scan and process each chunk separately in an optimized way
			//we mimic the way ccMesh beahves by using virtual chunks!
			unsigned chunks = static_cast<unsigned>(ceil((double)displayedTriNum/(double)MAX_NUMBER_OF_ELEMENTS_PER_CHUNK));
			unsigned chunkStart = 0;
			const colorType* col = 0;
			for (unsigned k=0; k<chunks; ++k, chunkStart += MAX_NUMBER_OF_ELEMENTS_PER_CHUNK)
			{
				//virtual chunk size
				const unsigned chunkSize = k+1 < chunks ? MAX_NUMBER_OF_ELEMENTS_PER_CHUNK : (displayedTriNum % MAX_NUMBER_OF_ELEMENTS_PER_CHUNK);

				//vertices
				PointCoordinateType* _vertices = GetVertexBuffer();
				for (unsigned n=0; n<chunkSize; n+=decimStep)
				{
					const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
					memcpy(_vertices,vertices->getPoint(ti->i1)->u,sizeof(PointCoordinateType)*3);
					_vertices+=3;
					memcpy(_vertices,vertices->getPoint(ti->i2)->u,sizeof(PointCoordinateType)*3);
					_vertices+=3;
					memcpy(_vertices,vertices->getPoint(ti->i3)->u,sizeof(PointCoordinateType)*3);
					_vertices+=3;
				}

				//scalar field
				if (glParams.showSF)
				{
					colorType* _rgbColors = GetColorsBuffer();
					assert(colorScale);
					for (unsigned n=0; n<chunkSize; n+=decimStep)
					{
						const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
						col = currentDisplayedScalarField->getValueColor(ti->i1);
						memcpy(_rgbColors,col,sizeof(colorType)*3);
						_rgbColors += 3;
						col = currentDisplayedScalarField->getValueColor(ti->i2);
						memcpy(_rgbColors,col,sizeof(colorType)*3);
						_rgbColors += 3;
						col = currentDisplayedScalarField->getValueColor(ti->i3);
						memcpy(_rgbColors,col,sizeof(colorType)*3);
						_rgbColors += 3;
					}
				}
				//colors
				else if (glParams.showColors)
				{
					colorType* _rgbColors = GetColorsBuffer();

					for (unsigned n=0; n<chunkSize; n+=decimStep)
					{
						const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
						memcpy(_rgbColors,rgbColorsTable->getValue(ti->i1),sizeof(colorType)*3);
						_rgbColors += 3;
						memcpy(_rgbColors,rgbColorsTable->getValue(ti->i2),sizeof(colorType)*3);
						_rgbColors += 3;
						memcpy(_rgbColors,rgbColorsTable->getValue(ti->i3),sizeof(colorType)*3);
						_rgbColors += 3;
					}
				}

				//normals
				if (glParams.showNorms)
				{
					PointCoordinateType* _normals = GetNormalsBuffer();
					if (showTriNormals)
					{
						for (unsigned n=0; n<chunkSize; n+=decimStep)
						{
							CCVector3 Na, Nb, Nc;
							getTriangleNormals(chunkStart + n, Na, Nb, Nc);
							memcpy(_normals,Na.u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,Nb.u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,Nc.u,sizeof(PointCoordinateType)*3);
							_normals+=3;
						}
					}
					else
					{
						for (unsigned n=0; n<chunkSize; n+=decimStep)
						{
							const CCLib::TriangleSummitsIndexes* ti = getTriangleIndexes(chunkStart + n);
							memcpy(_normals,vertices->getPointNormal(ti->i1).u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,vertices->getPointNormal(ti->i2).u,sizeof(PointCoordinateType)*3);
							_normals+=3;
							memcpy(_normals,vertices->getPointNormal(ti->i3).u,sizeof(PointCoordinateType)*3);
							_normals+=3;
						}
					}
				}

				if (!showWired)
				{
					glDrawArrays(lodEnabled ? GL_POINTS : GL_TRIANGLES,0,(chunkSize/decimStep)*3);
				}
				else
				{
					glDrawElements(GL_LINES,(chunkSize/decimStep)*6,GL_UNSIGNED_INT,GetWireVertexIndexes());
				}
			}

			//disable arrays
			glDisableClientState(GL_VERTEX_ARRAY);
			if (glParams.showNorms)
				glDisableClientState(GL_NORMAL_ARRAY);
			if (glParams.showSF || glParams.showColors)
				glDisableClientState(GL_COLOR_ARRAY);
		}
		else
		{
			//current vertex color
			const colorType *col1=0,*col2=0,*col3=0;
			//current vertex normal
			const PointCoordinateType *N1=0,*N2=0,*N3=0;
			//current vertex texture coordinates
			float *Tx1=0,*Tx2=0,*Tx3=0;

			//loop on all triangles
			int lasMtlIndex = -1;

			if (showTextures)
			{
				//#define TEST_TEXTURED_BUNDLER_IMPORT
#ifdef TEST_TEXTURED_BUNDLER_IMPORT
				glPushAttrib(GL_COLOR_BUFFER_BIT);
				glEnable(GL_BLEND);
				glBlendFunc(context.sourceBlend, context.destBlend);
#endif

				glEnable(GL_TEXTURE_2D);
			}

			if (pushTriangleNames)
				glPushName(0);

			GLenum triangleDisplayType = lodEnabled ? GL_POINTS : showWired ? GL_LINE_LOOP : GL_TRIANGLES;
			glBegin(triangleDisplayType);

			//per-triangle normals
			const NormsIndexesTableType* triNormals = getTriNormsTable();
			//materials
			const ccMaterialSet* materials = getMaterialSet();

			for (unsigned n=0; n<triNum; ++n)
			{
				//current triangle vertices
				const CCLib::TriangleSummitsIndexes* tsi = getTriangleIndexes(n);

				//LOD: shall we display this triangle?
				if (n % decimStep)
					continue;

				if (visFiltering)
				{
					//we skip the triangle if at least one vertex is hidden
					if ((verticesVisibility->getValue(tsi->i1) != POINT_VISIBLE) ||
						(verticesVisibility->getValue(tsi->i2) != POINT_VISIBLE) ||
						(verticesVisibility->getValue(tsi->i3) != POINT_VISIBLE))
						continue;
				}

				if (glParams.showSF)
				{
					assert(colorScale);
					col1 = currentDisplayedScalarField->getValueColor(tsi->i1);
					if (!col1)
						continue;
					col2 = currentDisplayedScalarField->getValueColor(tsi->i2);
					if (!col2)
						continue;
					col3 = currentDisplayedScalarField->getValueColor(tsi->i3);
					if (!col3)
						continue;
				}
				else if (glParams.showColors)
				{
					col1 = rgbColorsTable->getValue(tsi->i1);
					col2 = rgbColorsTable->getValue(tsi->i2);
					col3 = rgbColorsTable->getValue(tsi->i3);
				}

				if (glParams.showNorms)
				{
					if (showTriNormals)
					{
						assert(triNormals);
						int n1,n2,n3;
						getTriangleNormalIndexes(n,n1,n2,n3);
						N1 = (n1>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n1)).u : 0);
						N2 = (n1==n2 ? N1 : n1>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n2)).u : 0);
						N3 = (n1==n3 ? N1 : n3>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n3)).u : 0);

					}
					else
					{
						N1 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i1)).u;
						N2 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i2)).u;
						N3 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i3)).u;
					}
				}

				if (applyMaterials || showTextures)
				{
					assert(materials);
					int newMatlIndex = this->getTriangleMtlIndex(n);

					//do we need to change material?
					if (lasMtlIndex != newMatlIndex)
					{
						assert(newMatlIndex<(int)materials->size());
						glEnd();
						if (showTextures)
						{
							GLuint texID = (newMatlIndex>=0 ? (*materials)[newMatlIndex].texID : 0);
							if (texID>0)
								assert(glIsTexture(texID));
							glBindTexture(GL_TEXTURE_2D, texID);
						}

						//if we don't have any current material, we apply default one
						(newMatlIndex>=0 ? (*materials)[newMatlIndex] : context.defaultMat).applyGL(glParams.showNorms,false);
						glBegin(triangleDisplayType);
						lasMtlIndex=newMatlIndex;
					}

					if (showTextures)
					{
						getTriangleTexCoordinates(n,Tx1,Tx2,Tx3);
					}
				}

				if (pushTriangleNames)
				{
					glEnd();
					glLoadName(n);
					glBegin(triangleDisplayType);
				}
				else if (showWired)
				{
					glEnd();
					glBegin(triangleDisplayType);
				}

				//vertex 1
				if (N1)
					ccGL::Normal3v(N1);
				if (col1)
					glColor3ubv(col1);
				if (Tx1)
					glTexCoord2fv(Tx1);
				ccGL::Vertex3v(vertices->getPoint(tsi->i1)->u);

				//vertex 2
				if (N2)
					ccGL::Normal3v(N2);
				if (col2)
					glColor3ubv(col2);
				if (Tx2)
					glTexCoord2fv(Tx2);
				ccGL::Vertex3v(vertices->getPoint(tsi->i2)->u);

				//vertex 3
				if (N3)
					ccGL::Normal3v(N3);
				if (col3)
					glColor3ubv(col3);
				if (Tx3)
					glTexCoord2fv(Tx3);
				ccGL::Vertex3v(vertices->getPoint(tsi->i3)->u);
			}

			glEnd();

			if (pushTriangleNames)
				glPopName();

			if (showTextures)
			{
#ifdef TEST_TEXTURED_BUNDLER_IMPORT
				glPopAttrib(); //GL_COLOR_BUFFER_BIT 
#endif
				glBindTexture(GL_TEXTURE_2D, 0);
				glDisable(GL_TEXTURE_2D);
			}
		}

		if (stipplingEnabled())
			EnableGLStippleMask(false);

		if (colorMaterial)
			glDisable(GL_COLOR_MATERIAL);

		if (glParams.showNorms)
		{
			glDisable(GL_LIGHTING);
			glDisable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE));
		}

		if (pushName)
			glPopName();
	}
}
Example #27
0
void RenderSceneA::RenderScene()
{
	//big sphere
	//glPolygonMode(GL_FRONT,GL_LINE);
	//glPolygonMode(GL_BACK,GL_LINE);
	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glColor3f( 1.0f, 1.0f, 1.0f );
    glVertexPointer( 3, GL_FLOAT, 0, afVertices ); // set pointer to vertex data
    glNormalPointer( GL_FLOAT, 0, afVertices ); // set pointer to normal data
    glEnableClientState( GL_VERTEX_ARRAY ); // enable vertex and normal pointer
    glEnableClientState( GL_NORMAL_ARRAY );
	float *auiTextureCoord = new float[2*m_iNoVertices];
	UpdateTextureCoord(auiTextureCoord);
	glTexCoordPointer(2, GL_FLOAT, 0, auiTextureCoord);
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    glDrawElements( GL_TRIANGLES, m_iNoFaces*3, GL_UNSIGNED_INT, auiIndices );
	
	//small sphere
	glPolygonMode(GL_FRONT,GL_FILL);
	glPolygonMode(GL_BACK,GL_FILL);
	glVertexPointer( 3, GL_FLOAT, 0, afVerticesSphere );
	glMatrixMode(GL_MODELVIEW);
	float RadiusSphere = 2.0f;
	float vx = RadiusSphere * sin(SphereMove);
	float vz = RadiusSphere * cos(SphereMove);
	glTranslatef(vx,0.0f,vz);
	float radiusSphere = 0.3f;
	float multMatrix[16] =
	{
		radiusSphere,0.0f,0.0f,0.0f,
		0.0f,radiusSphere,0.0f,0.0f,
		0.0f,0.0f,radiusSphere,0.0f,
		0.0f,0.0f,0.0f,1.0f
	};
	glMultMatrixf(multMatrix);
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    glDrawElements( GL_TRIANGLES, NO_FACES_SPHERE*3, GL_UNSIGNED_INT, auiIndicesSphere);

	 //Simple Plane by 4 Quads
	glPolygonMode(GL_FRONT,GL_LINE); // wireframe for the front side of the polygone
	glPolygonMode(GL_BACK,GL_LINE); //and for the back side
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();                                  
    glColor3f(0.5f,0.5f,1.0f);  
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );

	/* quads generieren [4x4] */
	int qx,qy;
	for (qx = -2; qx < 2; qx++) {
		for (qy = -2; qy < 2; qy++) {
			glBegin(GL_QUADS);                         
				glVertex3f(1.0f * qx, -1.0f, 1.0f * qy);
				glVertex3f(1.0f * (qx + 1), -1.0f, 1.0f * qy);
				glVertex3f(1.0f * (qx + 1), -1.0f, 1.0f * (qy + 1));
				glVertex3f(1.0f * qx, -1.0f, 1.0f * (qy + 1));
			glEnd();
		}
	}

	//go back to the previous Texture Mode stored in TextureMode
	if (TextureMode == 1)
	{
		glDisable(GL_TEXTURE_2D);
		glPolygonMode(GL_FRONT,GL_FILL); // fill the front side of the polygone
		glPolygonMode(GL_BACK,GL_FILL); // and use wireframe for back side
	}
	else if (TextureMode == 2)
	{
		glEnable(GL_TEXTURE_2D);
		glPolygonMode(GL_FRONT,GL_FILL); // fill the front side of the polygone
		glPolygonMode(GL_BACK,GL_FILL); // and use wireframe for back side
	}
	else 
	{
		glDisable(GL_TEXTURE_2D);
		glPolygonMode(GL_FRONT,GL_LINE); // fill the front side of the polygone
		glPolygonMode(GL_BACK,GL_LINE); // and use wireframe for back side
	}
}
Example #28
0
static void drawCube(void)
{
	/* 3 vertices for every triangle in a cube. We need this amount as each vertex
	   needs a unique normal associated with it for lighting to work correctly. */
	const GLfloat vertices[] = {
		/* Front */
		M, M, P,
		P, M, P,
		P, P, P,

		M, M, P,
		P, P, P,
		M, P, P,

		/* Back */
		P, M, M,
		M, M, M,
		M, P, M,

		P, M, M,
		M, P, M,
		P, P, M,

		/* Right */
		P, M, P,
		P, M, M,
		P, P, M,

		P, M, P,
		P, P, M,
		P, P, P,

		/* Left */
		M, M, M,
		M, M, P,
		M, P, P,

		M, M, M,
		M, P, P,
		M, P, M,

		/* Top */
		M, P, P,
		P, P, P,
		P, P, M,

		M, P, P,
		P, P, M,
		M, P, M,

		/* Bottom */
		P, M, P,
		M, M, P,
		M, M, M,

		P, M, P,
		M, M, M,
		P, M, M
	};

	const GLfloat normals[] = {
		/* Front - All normals facing forwards */
		0.0f, 0.0f, 1.0f,
		0.0f, 0.0f, 1.0f,
		0.0f, 0.0f, 1.0f,

		0.0f, 0.0f, 1.0f,
		0.0f, 0.0f, 1.0f,
		0.0f, 0.0f, 1.0f,

		/* Back - All normals facing backwards */
		0.0f, 0.0f, -1.0f,
		0.0f, 0.0f, -1.0f,
		0.0f, 0.0f, -1.0f,

		0.0f, 0.0f, -1.0f,
		0.0f, 0.0f, -1.0f,
		0.0f, 0.0f, -1.0f,

		/* Right - All normals facing right */
		1.0f, 0.0f, 0.0f,
		1.0f, 0.0f, 0.0f,
		1.0f, 0.0f, 0.0f,

		1.0f, 0.0f, 0.0f,
		1.0f, 0.0f, 0.0f,
		1.0f, 0.0f, 0.0f,

		/* Left - All normals facing left */
		-1.0f, 0.0f, 0.0f,
		-1.0f, 0.0f, 0.0f,
		-1.0f, 0.0f, 0.0f,

		-1.0f, 0.0f, 0.0f,
		-1.0f, 0.0f, 0.0f,
		-1.0f, 0.0f, 0.0f,

		/* Top - All normals facing up */
		0.0f, 1.0f, 0.0f,
		0.0f, 1.0f, 0.0f,
		0.0f, 1.0f, 0.0f,

		0.0f, 1.0f, 0.0f,
		0.0f, 1.0f, 0.0f,
		0.0f, 1.0f, 0.0f,

		/* Bottom - All normals facing down */
		0.0f, -1.0f, 0.0f,
		0.0f, -1.0f, 0.0f,
		0.0f, -1.0f, 0.0f,

		0.0f, -1.0f, 0.0f,
		0.0f, -1.0f, 0.0f,
		0.0f, -1.0f, 0.0f
	};

	const GLubyte indices[] = {
		0, 1, 2, 3, 4, 5,       /* FRONT */
		6, 7, 8, 9, 10, 11,     /* BACK */
		12, 13, 14, 15, 16, 17, /* RIGHT */
		18, 19, 20, 21, 22, 23, /* LEFT */
		24, 25, 26, 27, 28, 29, /* TOP */
		30, 31, 32, 33, 34, 35  /* BOTTOM */
	};

	glNormalPointer(GL_FLOAT, 0, normals);
	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glDrawElements(GL_TRIANGLES, NELEMS(indices), GL_UNSIGNED_BYTE, indices);
}
Example #29
-1
void RenderSceneA::CreateScene()
{
	// Data read from the header of the BMP file
	unsigned char header[54]; // Each BMP file begins by a 54-bytes header
	unsigned int dataPos;     // Position in the file where the actual data begins
	unsigned int width, height;
	unsigned int imageSize;   // = width*height*3
	// Actual RGB data
	unsigned char * data;
	// Open the file
	FILE * file = fopen("Mercator.bmp","rb");
	if (!file)
	{
		printf("Image could not be opened\n"); 
		exit(0);
	}
	if ( fread(header, 1, 54, file)!=54 ){ // If not 54 bytes read : problem
		printf("Not a correct BMP file\n");
		exit(0);
	}
	// Read ints from the byte array
	dataPos    = *(int*)&(header[0x0A]);
	imageSize  = *(int*)&(header[0x22]);
	imageSize = 0; //header broken? guess below with width and height
	width      = *(int*)&(header[0x12]);
	height     = *(int*)&(header[0x16]);
	width = 256; //TODO header might be corrupt.. adjusted for bricks.bmp
	height = 256;
	// Some BMP files are misformatted, guess missing information
	if (imageSize==0)    imageSize=width*height*3; // 3 : one byte for each Red, Green and Blue component
	if (dataPos==0)      dataPos=54; // The BMP header is done that way

	data = new unsigned char [imageSize]; // Create a buffer
	fread(data,1,imageSize,file); // Read the actual data from the file into the buffer
	fclose(file); //Everything is in memory now, the file can be closed



    GLuint textureNumber; // Eine Textur in Karte erzeugen
    glGenTextures(1, &textureNumber);
    glBindTexture(GL_TEXTURE_2D, textureNumber); // Mit unserer erzeugten Textur arbeiten
    // Lineare Interpolation der Texturpixel zum Vergrößern und
    // Verkleinern verwenden (andere Parameter auf Standard belasen)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Textur in die Grafikkarte hochladen
    glTexImage2D(GL_TEXTURE_2D,     // 2D Textur
                 0,                 // Detailsstufe (für Mipmaps)
                 GL_RGB,                 // Farbkomponenten (1 für Grauwerte)
                 width,     // Breite
                 height,    // Höhe
                 0,                 // Rand
                 GL_BGR,      // Pixel-Format (Grauwerte)
                 GL_UNSIGNED_BYTE,  // Datentyp der Komponenten (0 bis 255)
                 data);           // Pixel-Puffer


	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glColor3f( 1.0f, 1.0f, 1.0f );

    glVertexPointer( 3, GL_FLOAT, 0, afVertices ); // set pointer to vertex data
    glNormalPointer( GL_FLOAT, 0, afVertices ); // set pointer to normal data
    glEnableClientState( GL_VERTEX_ARRAY ); // enable vertex and normal pointer
    glEnableClientState( GL_NORMAL_ARRAY );
	float *auiTextureCoord = new float[2*m_iNoVertices];
	UpdateTextureCoord(auiTextureCoord);

	glTexCoordPointer(2, GL_FLOAT, 0, auiTextureCoord);
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    glDrawElements( GL_TRIANGLES, m_iNoFaces*3, GL_UNSIGNED_INT, auiIndices ); // draw polygons


	//rotating Sphere
	memcpy(afVerticesSphere,afVerticesSphereStart, sizeof(float) * NO_VERTICES_SPHERE*3);
	memcpy(auiIndicesSphere,auiIndicesSphereStart,sizeof(int) * NO_FACES_SPHERE*3);
	
    //glDrawElements( GL_TRIANGLES, NO_FACES_SPHERE*3, GL_UNSIGNED_INT, auiIndicesSphere);     

	
}
void R_RemapDeluxeImages( world_t *world )
{
	int i;

	if( !tr.deluxemaps[0] )
		return;

	R_InitConverter();

	R_StateSetActiveTmuUntracked( GL_TEXTURE0 );
	R_StateSetActiveClientTmuUntracked( GL_TEXTURE0 );

	glPushAttrib( GL_ALL_ATTRIB_BITS );
	glPushClientAttrib( GL_CLIENT_ALL_ATTRIB_BITS );

	glEnableClientState( GL_VERTEX_ARRAY );
	glEnableClientState( GL_NORMAL_ARRAY );
	glEnableVertexAttribArrayARB( 6 );
	glEnableVertexAttribArrayARB( 7 );

	glClearColor( 0, 0, 0, 0 );
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_STENCIL_TEST );
	glDisable( GL_ALPHA_TEST );
	glDisable( GL_BLEND );
	glDisable( GL_CULL_FACE );
	glDisable( GL_MULTISAMPLE );
	glEnable( GL_POLYGON_SMOOTH );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glEnable( GL_VERTEX_PROGRAM_ARB );
	glBindProgramARB( GL_VERTEX_PROGRAM_ARB, conv.vp );
	glEnable( GL_FRAGMENT_PROGRAM_ARB );
	glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, conv.fp );

	glEnable( GL_TEXTURE_2D );

	for( i = 0; i < tr.numLightmaps; i++ )
	{
		int j, y;
		unsigned *buf0, *buf1;

		image_t *img = tr.deluxemaps[i];
		glBindTexture( GL_TEXTURE_2D, img->texnum );

		glClear( GL_COLOR_BUFFER_BIT );

		glViewport( 0, img->uploadHeight, img->uploadWidth, img->uploadHeight );

		glDisable( GL_VERTEX_PROGRAM_ARB );
		glDisable( GL_FRAGMENT_PROGRAM_ARB );

		glBegin( GL_QUADS );
		{
			glTexCoord2f( 0, 0 );
			glVertex2f( -1, -1 );

			glTexCoord2f( 0, 1 );
			glVertex2f( -1, 1 );

			glTexCoord2f( 1, 1 );
			glVertex2f( 1, 1 );

			glTexCoord2f( 1, 0 );
			glVertex2f( 1, -1 );
		}
		glEnd();

		glEnable( GL_VERTEX_PROGRAM_ARB );
		glEnable( GL_FRAGMENT_PROGRAM_ARB );

		glViewport( 0, 0, img->uploadWidth, img->uploadHeight );

		glProgramLocalParameter4fARB( GL_VERTEX_PROGRAM_ARB, 0,
			img->uploadWidth, img->uploadHeight,
			1.0F / img->uploadWidth, 1.0F / img->uploadHeight );

		for( j = 0; j < world->numsurfaces; j++ )
		{
			const msurface_t *srf = world->surfaces + j;
			const shader_t *shader = srf->shader;
			const msurface_ex_t *exsrf = srf->redirect;
			
			if( !shader->stages[0] || !shader->stages[0]->active )
				continue;
			if( shader->stages[0]->deluxeMap != img )
				continue;

			if( !exsrf )
				continue;

			glVertexPointer( 2, GL_FLOAT, sizeof( drawVert_ex_t ),
				&exsrf->verts[0].uvL );
			glNormalPointer( GL_FLOAT, sizeof( drawVert_ex_t ),
				&exsrf->verts[0].norm );
			glVertexAttribPointerARB( 6, 3, GL_FLOAT, GL_FALSE,
				sizeof( drawVert_ex_t ), &exsrf->verts[0].tan );
			glVertexAttribPointerARB( 7, 3, GL_FLOAT, GL_FALSE,
				sizeof( drawVert_ex_t ), &exsrf->verts[0].bin );

			glDrawElements( exsrf->primType, exsrf->numIndices,
				GL_UNSIGNED_SHORT, exsrf->indices );
		}

		glFinish();
		
		buf0 = (unsigned*)ri.Hunk_AllocateTempMemory( img->uploadWidth * img->uploadHeight * 4 );
		buf1 = (unsigned*)ri.Hunk_AllocateTempMemory( img->uploadWidth * img->uploadHeight * 4 );

		//can't just copy to the texture since we
		//need the custom mipmap generator
		glReadPixels( 0, 0, img->uploadWidth, img->uploadHeight,
			GL_RGBA, GL_UNSIGNED_BYTE, buf0 );

#define DELUXEL( buf, x, y ) ((byte*)(buf) + (((y) * img->uploadWidth + (x)) * 4))

		Com_Memcpy( buf1, buf0, img->uploadWidth * img->uploadHeight * 4 );

		for( j = 0; j < 4; j++ )
		{
			for( y = 0; y < img->uploadHeight; y++ )
			{
				int x;

				for( x = 0; x < img->uploadWidth; x++ )
				{
					static int neighbors[8][2] =
					{
						{ 0, 1 },
						{ 1, 1 },
						{ 1, 0 },
						{ 1, -1 },
						{ 0, -1 },
						{ -1, -1 },
						{ -1, 0 },
						{ -1, 1 }
					};

					int i;
					int sum[3], c;

					byte *cIn = DELUXEL( buf0, x, y );
					byte *cOut = DELUXEL( buf1, x, y );

					cOut[3] = cIn[3];

					if( cIn[2] )
					{
						//if it has some Z value
						//then it's already good

						cOut[0] = cIn[0];
						cOut[1] = cIn[1];
						cOut[2] = cIn[2];

						continue;
					}

					c = 0;
					sum[0] = sum[1] = sum[2] = 0;

					for( i = 0; i < lengthof( neighbors ); i++ )
					{
						int nx = x + neighbors[i][0];
						int ny = y + neighbors[i][1];

						if( nx >= 0 && nx < img->uploadWidth &&
							ny >= 0 && ny < img->uploadHeight )
						{
							byte *n = DELUXEL( buf0, nx, ny );

							if( !n[2] )
								continue;

							sum[0] += n[0];
							sum[1] += n[1];
							sum[2] += n[2];

							c++;
						}
					}

					if( c )
					{
						cOut[0] = sum[0] / c;
						cOut[1] = sum[1] / c;
						cOut[2] = sum[2] / c;
					}
				}
			}

			Com_Memcpy( buf0, buf1, img->uploadWidth * img->uploadHeight * 4 );
		}

		for( y = 0; y < img->uploadHeight; y++ )
		{
			int x;

			for( x = 0; x < img->uploadWidth; x++ )
			{
				byte *d = DELUXEL( buf1, x, y );

				if( !d[2] )
				{
					d[0] = 0;
					d[1] = 0;
					d[2] = 0xFF;
				}
			}
		}

		//write it out to file
		{
			int size;
			char path[MAX_QPATH];
			byte *out_buf;
			
			Com_sprintf( path, sizeof( path ), "deluxe/%s/dm_%04d.tga",
				world->baseName, i );

			size = 18 + img->uploadWidth * img->uploadHeight * 3;
			out_buf = (byte*)ri.Hunk_AllocateTempMemory( size );

		   	Com_Memset( out_buf, 0, 18 );
			out_buf[2] = 2;		// uncompressed type
			out_buf[12] = img->uploadWidth & 255;
			out_buf[13] = img->uploadWidth >> 8;
			out_buf[14] = img->uploadHeight & 255;
			out_buf[15] = img->uploadHeight >> 8;
			out_buf[16] = 24;	// pixel size
			out_buf[17] = 0x20; // reverse row order

			for( y = 0; y < img->uploadHeight; y++ )
			{
				int x;
				for( x = 0; x < img->uploadWidth; x++ )
				{
					byte *d = DELUXEL( buf1, x, y );
					out_buf[18 + (y * img->uploadWidth + x) * 3 + 0] = d[2];
					out_buf[18 + (y * img->uploadWidth + x) * 3 + 1] = d[1];
					out_buf[18 + (y * img->uploadWidth + x) * 3 + 2] = d[0];
				}
			}
			
			ri.FS_WriteFile( path, out_buf, size );
			
			ri.Hunk_FreeTempMemory( out_buf );
		}

#undef DELUXEL

		Upload32( buf1, qfalse, img, ILF_VECTOR_SB3 );

#ifdef _DEBUG
		glEnable( GL_TEXTURE_2D );
		glBindTexture( GL_TEXTURE_2D, img->texnum );

		glViewport( img->uploadWidth, 0, img->uploadWidth, img->uploadHeight );

		glDisable( GL_VERTEX_PROGRAM_ARB );
		glDisable( GL_FRAGMENT_PROGRAM_ARB );

		glBegin( GL_QUADS );
		{
			glTexCoord2f( 0, 0 );
			glVertex2f( -1, -1 );

			glTexCoord2f( 0, 1 );
			glVertex2f( -1, 1 );

			glTexCoord2f( 1, 1 );
			glVertex2f( 1, 1 );

			glTexCoord2f( 1, 0 );
			glVertex2f( 1, -1 );
		}
		glEnd();

		glEnable( GL_VERTEX_PROGRAM_ARB );
		glEnable( GL_FRAGMENT_PROGRAM_ARB );

		GLimp_EndFrame();
#endif

		ri.Hunk_FreeTempMemory( buf1 );
		ri.Hunk_FreeTempMemory( buf0 );
	}

	glPopClientAttrib();
	glPopAttrib();

	glDeleteProgramsARB( 1, &conv.vp );
	glDeleteProgramsARB( 1, &conv.fp );
}