Esempio n. 1
0
File: load.c Progetto: XAMEUS/CPROJ6
GLuint Tess_Obj_Area(int c, GLdouble ** points, way w)
{
	GLuint id = glGenLists(1);
	if (!id) {
		fprintf(stderr, "failed to create a list, return 0\n");
		return id;
	}

	GLUtesselator *tess = gluNewTess();
	if (!tess) {
		fprintf(stderr,
			"failed to create tessellation object, return 0\n");
		return 0;
	};

	tessCallback(tess);

	GLdouble pos;
	int border = 0;
	glNewList(id, GL_COMPILE);

	if (w.highway == HIGHWAY_PEDESTRIAN) {
		HIGHWAY_PEDESTRIAN_COLOR;
		pos = -4.9f;
		border = 2;
	} else if (w.building != 0) {
		BUILDING_COLOR;
		pos = BUILDING_DEPTH;
		border = 1;
	} else if (w.natural != 0) {
		color_natural(w.natural);
		pos = NATURAL_DEPTH;
	} else if (w.waterway != 0) {
		WATERWAY_COLOR;
		pos = WATERWAY_DEPTH;
	} else if (w.leisure != 0) {
		color_leisure(w.leisure);
		pos = LEISURE_DEPTH;
	} else if (w.landuse != 0) {
		color_landuse(w.landuse);
		pos = LEISURE_DEPTH;
	} else if (w.inner != 0) {
		border = 1;
		glColor3f(0.80f, 0.85f, 0.81f);
		if (w.inner > 1) {
			pos = BUILDING_DEPTH + 0.1f;
		} else {
			pos = BACKGROUND_DEPTH;
		}
	} else if (w.bridge) {
		BRIDGE_COLOR;
		pos = BRIDGE_DEPTH;
	}

	int i;
	gluTessBeginPolygon(tess, 0);
	gluTessBeginContour(tess);
	for (i = 0; i < c - 1; i++) {
		points[i][2] = pos;
		gluTessVertex(tess, points[i], points[i]);
	}
	gluTessEndContour(tess);
	gluTessEndPolygon(tess);

	gluDeleteTess(tess);

	if (border) {
		glColor3f(0.3f, 0.2f, 0.2f);
		if (border == 2) {
			glColor3f(0.0f, 0.0f, 0.0f);
		}
		Draw_Lines(c, points, 1.0f, pos);
	}

	glEndList();

	return id;
}
	~opengl_object()
	{
		glEndList();
	}
	
}

static void
updateElementTextures (CompScreen *s, Bool changeTextures)
{
	int       i, count = 0;
	float     autumnSize = elementsGetLeafSize(s->display);
	float     ffSize = elementsGetFireflySize(s->display);
	float     snowSize = elementsGetSnowSize(s->display);
	float     starsSize = elementsGetStarsSize(s->display);
	float     bubblesSize = elementsGetBubblesSize(s->display);
	element *ele;

	E_SCREEN (s);
	E_DISPLAY (s->display);
	int numAutumn, numFf, numSnow, numStars, numBubbles;

	if (eScreen->isActive[0])
		numAutumn = elementsGetNumLeaves (s->display);	
	else
		numAutumn = 0;
	if (eScreen->isActive[1])
		numFf = elementsGetNumFireflies (s->display);
	else
		numFf = 0;
	if (eScreen->isActive[2])
		numSnow = elementsGetNumSnowflakes (s->display);
	else
		numSnow = 0;
	if (eScreen->isActive[3])
		numStars = elementsGetNumStars (s->display);
	else
		numStars = 0;
	if (eScreen->isActive[4])
		numBubbles = elementsGetNumBubbles (s->display);
	else
		numBubbles = 0;
	ele = eScreen->allElements;
	if (changeTextures)
	{
	for (i = 0; i < eScreen->numElements; i++)
	{
		finiTexture (s, &eScreen->textu[i].tex);
		glDeleteLists (eScreen->textu[i].dList, 1);
	}

	if (eScreen->textu)
		free (eScreen->textu);
	eScreen->numElements = 0;
	eScreen->numTexLoaded[0] = 0;
	eScreen->numTexLoaded[1] = 0;
	eScreen->numTexLoaded[2] = 0;
	eScreen->numTexLoaded[3] = 0;
	eScreen->numTexLoaded[4] = 0;
	eScreen->textu = calloc (1, sizeof (texture) * (ed->numTex[0] + ed->numTex[1] + ed->numTex[2] + ed->numTex[3] + ed->numTex[4]));
	}
	for (i = 0; i < ed->numTex[0]; i++)
	{		
		CompMatrix  *mat;
		texture *aTex;
	if (changeTextures)
	{
		eScreen->textu[count].loaded =
		    readImageToTexture (s, &eScreen->textu[count].tex,
					ed->texFiles[0][i].s,
					&eScreen->textu[count].width,
					&eScreen->textu[count].height);
		if (!eScreen->textu[count].loaded)
		{
		    compLogMessage ("Elements", CompLogLevelWarn,
			    "Texture (Autumn) not found : %s", ed->texFiles[0][i].s);
		    continue;
		}
		compLogMessage ("Elements", CompLogLevelInfo,
			"Loaded Texture (Autumn)%s", ed->texFiles[0][i].s);
		}
		mat = &eScreen->textu[count].tex.matrix;
		aTex = &eScreen->textu[count];
		aTex->dList = glGenLists (1);
		glNewList (aTex->dList, GL_COMPILE);

		glBegin (GL_QUADS);

		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (0, 0);
		glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
			      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (0, autumnSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
			      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (autumnSize, autumnSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
			      COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (autumnSize, 0);

		glEnd ();
		glEndList ();

		count++;
	}
	if (changeTextures)
		eScreen->numTexLoaded[0] = count;
	for (i = 0; i < ed->numTex[1]; i++)
	{ 
		CompMatrix  *mat;
		texture *aTex;
		if (changeTextures)
		{
		eScreen->textu[count].loaded =
		readImageToTexture (s, &eScreen->textu[count].tex,
				ed->texFiles[1][i].s,
				&eScreen->textu[count].width,
				&eScreen->textu[count].height);
		if (!eScreen->textu[count].loaded)
		{
		    compLogMessage ("Elements", CompLogLevelWarn,
			    "Texture (Firefly) not found : %s", ed->texFiles[1][i].s);
		    continue;
		}
		compLogMessage ("Elements", CompLogLevelInfo,
			"Loaded Texture (Firefly) %s", ed->texFiles[1][i].s);
		}
		mat = &eScreen->textu[count].tex.matrix;
		aTex = &eScreen->textu[count];

		aTex->dList = glGenLists (1);
		glNewList (aTex->dList, GL_COMPILE);

		glBegin (GL_QUADS);

		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (0, 0);
		glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (0, ffSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
			      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (ffSize, ffSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
			      COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (ffSize, 0);

		glEnd ();
		glEndList ();

		count++;
	}
	if (changeTextures)
	eScreen->numTexLoaded[1] = count - eScreen->numTexLoaded[0];
	for (i = 0; i < ed->numTex[2]; i++)
	{ 
		CompMatrix  *mat;
		texture *aTex;
	if (changeTextures)
	{
		eScreen->textu[count].loaded =
		readImageToTexture (s, &eScreen->textu[count].tex,
				ed->texFiles[2][i].s,
				&eScreen->textu[count].width,
				&eScreen->textu[count].height);
		if (!eScreen->textu[count].loaded)
		{
			compLogMessage ("Elements", CompLogLevelWarn,
			    "Texture (snow) not found : %s", ed->texFiles[2][i].s);
			continue;
		}
		compLogMessage ("Elements", CompLogLevelInfo,
			"Loaded Texture (snow) %s", ed->texFiles[2][i].s);
	}
		mat = &eScreen->textu[count].tex.matrix;
		aTex = &eScreen->textu[count];

		aTex->dList = glGenLists (1);
		glNewList (aTex->dList, GL_COMPILE);

		glBegin (GL_QUADS);

		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (0, 0);
		glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (0, snowSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (snowSize, snowSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
		      COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (snowSize, 0);

		glEnd ();
		glEndList ();

		count++;
	}
	if (changeTextures)
	eScreen->numTexLoaded[2] = count - eScreen->numTexLoaded[0] -eScreen->numTexLoaded[1];
	for (i = 0; i < ed->numTex[3]; i++)
	{ 
		CompMatrix  *mat;
		texture *aTex;
	if (changeTextures)
	{
		eScreen->textu[count].loaded =
		readImageToTexture (s, &eScreen->textu[count].tex,
				ed->texFiles[3][i].s,
				&eScreen->textu[count].width,
				&eScreen->textu[count].height);
		if (!eScreen->textu[count].loaded)
		{
			compLogMessage ("Elements", CompLogLevelWarn,
			    "Texture (stars) not found : %s", ed->texFiles[3][i].s);
			continue;
		}
		compLogMessage ("Elements", CompLogLevelInfo,
			"Loaded Texture (stars)%s", ed->texFiles[3][i].s);
	}
		mat = &eScreen->textu[count].tex.matrix;
		aTex = &eScreen->textu[count];

		aTex->dList = glGenLists (1);
		glNewList (aTex->dList, GL_COMPILE);

		glBegin (GL_QUADS);

		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (0, 0);
		glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (0, starsSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (starsSize, starsSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
		      COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (starsSize, 0);

		glEnd ();
		glEndList ();

		count++;
	}
	if (changeTextures)
	eScreen->numTexLoaded[3] = count - eScreen->numTexLoaded[0] - eScreen->numTexLoaded[1] - eScreen->numTexLoaded[2];
	for (i = 0; i < ed->numTex[4]; i++)
	{ 
		CompMatrix  *mat;
		texture *aTex;
	if (changeTextures)
	{
		eScreen->textu[count].loaded =
		readImageToTexture (s, &eScreen->textu[count].tex,
				ed->texFiles[4][i].s,
				&eScreen->textu[count].width,
				&eScreen->textu[count].height);
		if (!eScreen->textu[count].loaded)
		{
			compLogMessage ("Elements", CompLogLevelWarn,
			    "Texture (bubbles) not found : %s", ed->texFiles[4][i].s);
			continue;
		}
		compLogMessage ("Elements", CompLogLevelInfo,
			"Loaded Texture (bubbles)%s", ed->texFiles[4][i].s);
	}
		mat = &eScreen->textu[count].tex.matrix;
		aTex = &eScreen->textu[count];

		aTex->dList = glGenLists (1);
		glNewList (aTex->dList, GL_COMPILE);

		glBegin (GL_QUADS);

		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (0, 0);
		glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (0, bubblesSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
		      COMP_TEX_COORD_Y (mat, aTex->height));
		glVertex2f (bubblesSize, bubblesSize * aTex->height / aTex->width);
		glTexCoord2f (COMP_TEX_COORD_X (mat, aTex->width),
		      COMP_TEX_COORD_Y (mat, 0));
		glVertex2f (bubblesSize, 0);

		glEnd ();
		glEndList ();

		count++;
	}
	if (changeTextures)
	{
	eScreen->numTexLoaded[4] = count - eScreen->numTexLoaded[0] - eScreen->numTexLoaded[1] - eScreen->numTexLoaded[2] - eScreen->numTexLoaded[3];

//	if (count < (ed->numTex[0] + ed->numTex[1] + ed->numTex[2] + ed->numTex[3] + ed->numTex[4]))
		eScreen->textu = realloc (eScreen->textu, sizeof (texture) * count);

	eScreen->numElements = count;
Esempio n. 4
0
/*! \internal
    This is basically a substitute for glxUseXFont() which can only
    handle XLFD fonts. This version relies on XFT v2 to render the
    glyphs, but it works with all fonts that XFT2 provides - both
    antialiased and aliased bitmap and outline fonts.
*/
void qgl_use_font(QFontEngineXft *engine, int first, int count, int listBase)
{
    GLfloat color[4];
    glGetFloatv(GL_CURRENT_COLOR, color);

    // save the pixel unpack state
    GLint gl_swapbytes, gl_lsbfirst, gl_rowlength, gl_skiprows, gl_skippixels, gl_alignment;
    glGetIntegerv (GL_UNPACK_SWAP_BYTES, &gl_swapbytes);
    glGetIntegerv (GL_UNPACK_LSB_FIRST, &gl_lsbfirst);
    glGetIntegerv (GL_UNPACK_ROW_LENGTH, &gl_rowlength);
    glGetIntegerv (GL_UNPACK_SKIP_ROWS, &gl_skiprows);
    glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &gl_skippixels);
    glGetIntegerv (GL_UNPACK_ALIGNMENT, &gl_alignment);

    glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    Bool antialiased = False;
#if 0 // disable antialias support for now
    XftPatternGetBool(engine->pattern(), XFT_ANTIALIAS, 0, &antialiased);
#endif
#ifdef QT_XFT2
    FT_Face face = XftLockFace(engine->font());
#else
    FT_Face face = engine->face();
#endif
    // start generating font glyphs
    for (int i = first; i < count; ++i) {
	int list = listBase + i;
	GLfloat x0, y0, dx, dy;

	FT_Error err;

	err = FT_Load_Glyph(face, FT_Get_Char_Index(face, i), FT_LOAD_DEFAULT);
	if (err) {
	    qDebug("failed loading glyph %d from font", i);
	    Q_ASSERT(!err);
	}
	err = FT_Render_Glyph(face->glyph, (antialiased ? ft_render_mode_normal
					    : ft_render_mode_mono));
	if (err) {
	    qDebug("failed rendering glyph %d from font", i);
	    Q_ASSERT(!err);
	}

	FT_Bitmap bm = face->glyph->bitmap;
	x0 = face->glyph->metrics.horiBearingX >> 6;
	y0 = (face->glyph->metrics.height - face->glyph->metrics.horiBearingY) >> 6;
	dx = face->glyph->metrics.horiAdvance >> 6;
	dy = 0;
 	int sz = bm.pitch * bm.rows;
	uint *aa_glyph = 0;
	uchar *ua_glyph = 0;

	if (antialiased)
	    aa_glyph = new uint[sz];
	else
	    ua_glyph = new uchar[sz];

	// convert to GL format
	for (int y = 0; y < bm.rows; ++y) {
	    for (int x = 0; x < bm.pitch; ++x) {
		int c1 = y*bm.pitch + x;
		int c2 = (bm.rows - y - 1) > 0 ? (bm.rows-y-1)*bm.pitch + x : x;
		if (antialiased) {
		    aa_glyph[c1] = (int(color[0]*255) << 24)
					 | (int(color[1]*255) << 16)
					 | (int(color[2]*255) << 8) | bm.buffer[c2];
		} else {
		    ua_glyph[c1] = bm.buffer[c2];
		}
	    }
	}

	glNewList(list, GL_COMPILE);
	if (antialiased) {
	    // calling glBitmap() is just a trick to move the current
	    // raster pos, since glGet*() won't work in display lists
	    glBitmap(0, 0, 0, 0, x0, -y0, 0);
	    glDrawPixels(bm.pitch, bm.rows, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, aa_glyph);
	    glBitmap(0, 0, 0, 0, dx-x0, y0, 0);
	} else {
	    glBitmap(bm.pitch*8, bm.rows, -x0, y0, dx, dy, ua_glyph);
	}
	glEndList();
	antialiased ? delete[] aa_glyph : delete[] ua_glyph;
    }

#ifdef QT_XFT2
    XftUnlockFace(engine->font());
#endif

    // restore pixel unpack settings
    glPixelStorei(GL_UNPACK_SWAP_BYTES, gl_swapbytes);
    glPixelStorei(GL_UNPACK_LSB_FIRST, gl_lsbfirst);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, gl_rowlength);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, gl_skiprows);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, gl_skippixels);
    glPixelStorei(GL_UNPACK_ALIGNMENT, gl_alignment);
}
Esempio n. 5
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	float array[] = {
		10, 10,	   1, 0, 0,
		27, 10,	   1, 0, 0,
		10, 30,	   1, 0, 0,

		30, 10,	   0, 1, 0,
		47, 10,	   0, 1, 0,
		30, 30,	   0, 1, 0,

		50, 10,	   0, 0, 1,
		67, 10,	   0, 0, 1,
		50, 30,	   0, 0, 1,

		70, 10,	   1, 0, 1,
		87, 10,	   1, 0, 1,
		70, 30,	   1, 0, 1
	};
	float seccol[] = {
		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,

		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,

		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,

		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,
		0.2, 0.2, 0.2,
	     };
	float c0[] = {1, 0.2, 0.2};
	float c1[] = {0.2, 1, 0.2};
	float c2[] = {0.2, 0.2, 1};
	float c3[] = {1, 0.2, 1};
	short indices[] = {
		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
	};
	int i, j;

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	printf("From bottom to top:\n");

	glEnable(GL_COLOR_SUM);
	glLoadIdentity();

	/* State change: Vertex arrays. */
	glVertexPointer(2, GL_FLOAT, 20, array);
	glColorPointer(3, GL_FLOAT, 20, array + 2);
	glSecondaryColorPointer(3, GL_FLOAT, 0, seccol);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_SECONDARY_COLOR_ARRAY);

	/* The vertex array state should be preserved after glClear. */
	glClear(GL_COLOR_BUFFER_BIT);

	/* Draw. */
	printf("DrawElements\n");
	for (i = 0; i < 4; i++)
		glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, indices + i*3);

	/* State change: Constant buffer. */
	glTranslatef(0, 30, 0);

	rotate_colors(array);

	/* Draw. */
	printf("DrawArrays\n");
	for (i = 0; i < 4; i++)
		glDrawArrays(GL_TRIANGLES, i*3, 3);

	/* State change: Vertex arrays. */
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_SECONDARY_COLOR_ARRAY);

	/* State change: Constant buffer. */
	glTranslatef(0, 30, 0);

	rotate_colors(array);

	/* Draw. */
	printf("Begin/End\n");
	for (i = 0; i < 4; i++) {
		glBegin(GL_TRIANGLES);
		for (j = 0; j < 3; j++) {
			glColor3fv(array + i*15 + j*5 + 2);
			glSecondaryColor3fv(seccol);
			glVertex2fv(array + i*15 + j*5);
		}
		glEnd();
	}

	/* State change: Constant buffer. */
	glTranslatef(0, 30, 0);

	rotate_colors(array);

	/* Create display lists. */
	for (i = 0; i < 4; i++) {
		glNewList(i+1, GL_COMPILE);
		glBegin(GL_TRIANGLES);
		for (j = 0; j < 3; j++) {
			glColor3fv(array + i*15 + j*5 + 2);
			glSecondaryColor3fv(seccol);
			glVertex2fv(array + i*15 + j*5);
		}
		glEnd();
		glEndList();
	}

	/* Draw. */
	printf("CallList\n");
	for (i = 0; i < 4; i++) {
		glCallList(i+1);
	}

	pass = pass && piglit_probe_pixel_rgb(15, 15, c0);
	pass = pass && piglit_probe_pixel_rgb(35, 15, c1);
	pass = pass && piglit_probe_pixel_rgb(55, 15, c2);
	pass = pass && piglit_probe_pixel_rgb(75, 15, c3);

	pass = pass && piglit_probe_pixel_rgb(15, 45, c1);
	pass = pass && piglit_probe_pixel_rgb(35, 45, c2);
	pass = pass && piglit_probe_pixel_rgb(55, 45, c3);
	pass = pass && piglit_probe_pixel_rgb(75, 45, c0);

	pass = pass && piglit_probe_pixel_rgb(15, 75, c2);
	pass = pass && piglit_probe_pixel_rgb(35, 75, c3);
	pass = pass && piglit_probe_pixel_rgb(55, 75, c0);
	pass = pass && piglit_probe_pixel_rgb(75, 75, c1);

	pass = pass && piglit_probe_pixel_rgb(15, 105, c3);
	pass = pass && piglit_probe_pixel_rgb(35, 105, c0);
	pass = pass && piglit_probe_pixel_rgb(55, 105, c1);
	pass = pass && piglit_probe_pixel_rgb(75, 105, c2);

	piglit_present_results();
	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Esempio n. 6
0
void EDA_3D_CANVAS::CreateDrawGL_List( REPORTER* aErrorMessages, REPORTER* aActivity )
{
    BOARD* pcb = GetBoard();

    wxBusyCursor    dummy;

    // Build 3D board parameters:
    GetPrm3DVisu().InitSettings( pcb );

    glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );

    // Create axis gl list (if it is not shown, the list will be not called
    draw3DAxis();

    // Create Board full gl lists:

    if( ! m_glLists[GL_ID_BOARD] )
    {
        DBG( unsigned strtime = GetRunningMicroSecs() );

        m_glLists[GL_ID_BOARD] = glGenLists( 1 );
        m_glLists[GL_ID_BODY] = glGenLists( 1 );
        buildBoard3DView(m_glLists[GL_ID_BOARD], m_glLists[GL_ID_BODY], aErrorMessages, aActivity );
        CheckGLError( __FILE__, __LINE__ );

        DBG( printf( "  buildBoard3DView total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
    }

    if( ! m_glLists[GL_ID_TECH_LAYERS] )
    {
        DBG( unsigned strtime = GetRunningMicroSecs() );

        m_glLists[GL_ID_TECH_LAYERS] = glGenLists( 1 );
        glNewList( m_glLists[GL_ID_TECH_LAYERS], GL_COMPILE );
        // when calling BuildTechLayers3DView,
        // do not show warnings, which are the same as buildBoard3DView
        buildTechLayers3DView( aErrorMessages, aActivity );
        glEndList();
        CheckGLError( __FILE__, __LINE__ );

        DBG( printf( "  buildTechLayers3DView total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
    }

    if( ! m_glLists[GL_ID_AUX_LAYERS] )
    {
        DBG( unsigned strtime = GetRunningMicroSecs() );

        m_glLists[GL_ID_AUX_LAYERS] = glGenLists( 1 );
        glNewList( m_glLists[GL_ID_AUX_LAYERS], GL_COMPILE );
        buildBoard3DAuxLayers( aErrorMessages, aActivity );
        glEndList();
        CheckGLError( __FILE__, __LINE__ );

        DBG( printf( "  buildBoard3DAuxLayers total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
    }

    // draw modules 3D shapes
    if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] && isEnabled( FL_MODULE ) )
    {
        m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] = glGenLists( 1 );

        // GL_ID_3DSHAPES_TRANSP_FRONT is an auxiliary list for 3D shapes;
        // Ensure it is cleared before rebuilding it
        if( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] )
            glDeleteLists( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT], 1 );

        bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );

        if( useMaterial )
            m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = glGenLists( 1 );
        else
            m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] = 0;

        buildFootprintShape3DList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT],
                                   m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT],
                                   aErrorMessages, aActivity );

        CheckGLError( __FILE__, __LINE__ );
    }

    calcBBox();

    // Create grid gl list
    if( ! m_glLists[GL_ID_GRID] )
    {
        m_glLists[GL_ID_GRID] = glGenLists( 1 );
        glNewList( m_glLists[GL_ID_GRID], GL_COMPILE );

        draw3DGrid( GetPrm3DVisu().m_3D_Grid );

        glEndList();
    }

    if( !m_glLists[GL_ID_SHADOW_FRONT] )
        m_glLists[GL_ID_SHADOW_FRONT] = glGenLists( 1 );

    if( !m_glLists[GL_ID_SHADOW_BACK] )
        m_glLists[GL_ID_SHADOW_BACK]  = glGenLists( 1 );

    if( !m_glLists[GL_ID_SHADOW_BOARD] )
        m_glLists[GL_ID_SHADOW_BOARD] = glGenLists( 1 );

    buildShadowList( m_glLists[GL_ID_SHADOW_FRONT],
                     m_glLists[GL_ID_SHADOW_BACK],
                     m_glLists[GL_ID_SHADOW_BOARD] );

    CheckGLError( __FILE__, __LINE__ );
}
Esempio n. 7
0
void TerrainQuadtree::generateTextures() {
	// prepare viewport and projection
	//glDisable(GL_DEPTH_TEST);

	// do not setup the proj more than once
	if (this->parent == NULL) {
		glViewport(0, 0, this->textureSize, this->textureSize);
		glMatrixMode(GL_PROJECTION);
		glPolygonMode(GL_FRONT, GL_FILL);
		glLoadIdentity();
		glOrtho(0.0, (double)this->textureSize, 0.0, (double)this->textureSize, 0.0, 1.0);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslated(0.0, 0.0, -1.0);

		generationScreenList = glGenLists(1);
		glNewList(generationScreenList, GL_COMPILE);
		glBegin(GL_QUADS);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(0.0, 0.0, 0.0);
		glTexCoord2f(1.0, 0.0);
		glVertex3f(this->textureSize, 0.0, 0.0);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(this->textureSize, this->textureSize, 0.0);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(0.0, this->textureSize, 0.0);
		glEnd();
		glEndList();
	}

	// generate topography
	glBindFramebuffer(GL_FRAMEBUFFER, this->framebuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->topoTexture->id, 0);
	this->positionTexture->bind(GL_TEXTURE0);

	this->generatorShader->bind();
	glUniform1i(glGetUniformLocation(this->generatorShader->program, "positionTexture"), 0);
	glCallList(generationScreenList);
	this->generatorShader->unbind();
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// generate normals
	//glBindFramebuffer(GL_FRAMEBUFFER, this->framebuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->normalTexture->id, 0);
	this->topoTexture->bind(GL_TEXTURE1);

	this->generatorShaderN->bind();
	glUniform1f(glGetUniformLocation(this->generatorShaderN->program, "size"), (float)this->textureSize);
	glUniform1f(glGetUniformLocation(this->generatorShaderN->program, "radius"), this->planet->radius);
	glUniform1i(glGetUniformLocation(this->generatorShaderN->program, "topoTexture"), 1);
	glUniform1i(glGetUniformLocation(this->generatorShaderN->program, "positionTexture"), 0);
	glCallList(generationScreenList);
	this->generatorShaderN->unbind();
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// generate colors
	//glBindFramebuffer(GL_FRAMEBUFFER, this->framebuffer);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->colorTexture->id, 0);
	this->generatorShaderC->bind();
	glUniform1i(glGetUniformLocation(this->generatorShaderC->program, "topoTexture"), 1);
	glCallList(generationScreenList);
	this->generatorShaderC->unbind();
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);

	//glEnable(GL_DEPTH_TEST);
	this->ready = true;
}
Esempio n. 8
0
ENTRYPOINT void 
init_gears (ModeInfo *mi)
{
  gears_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);
  int i;

  if (!bps) {
    bps = (gears_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (gears_configuration));
    if (!bps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_gears (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  if (!wire)
    {
      GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0};
      GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);

      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  {
    double spin_speed   = 0.5;
    double wander_speed = 0.01;
    double spin_accel   = 0.25;

    bp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            spin_accel,
                            do_wander ? wander_speed : 0,
                            True
                            );
    bp->trackball = gltrackball_init ();
  }

  if (!(random() % 8))
    {
      planetary_gears (mi);
    }
  else
    {
      gear *g = 0;
      int total_gears = MI_COUNT (mi);
      int i;
      if (total_gears <= 0)
        total_gears = 3 + abs (BELLRAND (8) - 4);  /* 3 - 7, mostly 3. */

      bp->gears = (gear **) calloc (total_gears+2, sizeof(**bp->gears));
      bp->ngears = 0;

      for (i = 0; i < total_gears; i++)
        g = place_new_gear (mi, g);
    }


  /* Center gears in scene. */
  {
    GLfloat minx=99999, miny=99999, maxx=-99999, maxy=-99999;
    int i;
    for (i = 0; i < bp->ngears; i++)
      {
        gear *g = bp->gears[i];
        if (g->x - g->r < minx) minx = g->x - g->r;
        if (g->x + g->r > maxx) maxx = g->x + g->r;
        if (g->y - g->r < miny) miny = g->y - g->r;
        if (g->y + g->r > maxy) maxy = g->y + g->r;
      }
    bp->bbox.x1 = minx;
    bp->bbox.y1 = miny;
    bp->bbox.x2 = maxx;
    bp->bbox.y2 = maxy;
  }

  /* Now render each gear into its display list.
   */
  for (i = 0; i < bp->ngears; i++)
    {
      gear *g = bp->gears[i];
      g->dlist = glGenLists (1);
      if (! g->dlist)
        {
          check_gl_error ("glGenLists");
          abort();
        }

      glNewList (g->dlist, GL_COMPILE);
      g->polygons += draw_involute_gear (g, wire);
      glEndList ();
    }
  if (bp->planetary_p)
    armature (mi);
}
Esempio n. 9
0
static void
realize (GtkWidget *widget,
	 gpointer   data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

  static GLfloat light0_position[] = { 0.0, 0.0, 30.0, 0.0 };
  static GLfloat light0_diffuse[]  = { 1.0, 1.0, 1.0, 1.0 };
  static GLfloat light0_specular[] = { 1.0, 1.0, 1.0, 1.0 };

  static GLfloat mat_specular[]  = { 0.5, 0.5, 0.5, 1.0 };
  static GLfloat mat_shininess[] = { 10.0 };
  static GLfloat mat_black[]     = { 0.0, 0.0, 0.0, 1.0 };
  static GLfloat mat_red[]       = { 1.0, 0.0, 0.0, 1.0 };
  static GLfloat mat_green[]     = { 0.0, 1.0, 0.0, 1.0 };
  static GLfloat mat_blue[]      = { 0.0, 0.0, 1.0, 1.0 };

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
    return;

  glClearColor (0.5, 0.5, 0.8, 1.0);
  glClearDepth (1.0);

  glLightfv (GL_LIGHT0, GL_POSITION, light0_position);
  glLightfv (GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  glLightfv (GL_LIGHT0, GL_SPECULAR, light0_specular);

  glEnable (GL_LIGHTING);
  glEnable (GL_LIGHT0);
  glEnable (GL_DEPTH_TEST);

  glEnable (GL_CULL_FACE);

  glShadeModel (GL_SMOOTH);

  glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular);
  glMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess);

  /* Center black cube. */
  glNewList (LOGO_CUBE, GL_COMPILE);
    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
    logo_draw_cube ();
  glEndList ();

  /* Forward "G". */
  glNewList (LOGO_G_FORWARD, GL_COMPILE);
    glDisable (GL_CULL_FACE);
    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_blue);
    logo_draw_g_plane ();
    glEnable (GL_CULL_FACE);

    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
    logo_draw_g ();
  glEndList ();

  /* Backward "G". */
  glNewList (LOGO_G_BACKWARD, GL_COMPILE);
    glPushMatrix ();
      glRotatef (180.0, 1.0, 0.0, 0.0);

      glDisable (GL_CULL_FACE);
      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_blue);
      logo_draw_g_plane ();
      glEnable (GL_CULL_FACE);

      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
      logo_draw_g ();

    glPopMatrix ();
  glEndList ();

  /* Forward "T". */
  glNewList (LOGO_T_FORWARD, GL_COMPILE);
    glDisable (GL_CULL_FACE);
    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_red);
    logo_draw_t_plane ();
    glEnable (GL_CULL_FACE);

    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
    logo_draw_t ();
  glEndList ();

  /* Backward "T". */
  glNewList (LOGO_T_BACKWARD, GL_COMPILE);
    glPushMatrix ();
      glRotatef (180.0, 1.0, 0.0, 0.0);

      glDisable (GL_CULL_FACE);
      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_red);
      logo_draw_t_plane ();
      glEnable (GL_CULL_FACE);

      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
      logo_draw_t ();

    glPopMatrix ();
  glEndList ();

  /* Forward "K". */
  glNewList (LOGO_K_FORWARD, GL_COMPILE);
    glDisable (GL_CULL_FACE);
    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_green);
    logo_draw_k_plane ();
    glEnable (GL_CULL_FACE);

    glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
    logo_draw_k ();
  glEndList ();

  /* Backward "K". */
  glNewList (LOGO_K_BACKWARD, GL_COMPILE);
    glPushMatrix ();
      glRotatef (180.0, 0.0, 0.0, 1.0);

      glDisable (GL_CULL_FACE);
      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_green);
      logo_draw_k_plane ();
      glEnable (GL_CULL_FACE);

      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_black);
      logo_draw_k ();
    glPopMatrix ();
  glEndList ();

  glEnable (GL_NORMALIZE);

  /* Init logo orientation. */
  init_logo_quat ();

  /* Init view. */
  init_view ();

  gdk_gl_drawable_gl_end (gldrawable);
  /*** OpenGL END ***/
}
Esempio n. 10
0
//
//  Load OBJ file
//
int LoadOBJ(const char* file)
{
   int k;
   int  Nv,Nn,Nt;  //  Number of vertex, normal and textures
   int  Mv,Mn,Mt;  //  Maximum vertex, normal and textures
   float* V;       //  Array of vertexes
   float* N;       //  Array of normals
   float* T;       //  Array if textures coordinates
   char*  line;    //  Line pointer
   char*  str;     //  String pointer

   //  Open file
   FILE* f = fopen(file,"r");
   if (!f) Fatal("Cannot open file %s\n",file);

   // Reset materials
   mtl = NULL;
   Nmtl = 0;

   //  Start new displaylist
   int list = glGenLists(1);
   glNewList(list,GL_COMPILE);
   //  Push attributes for textures
   glPushAttrib(GL_TEXTURE_BIT);

   //  Read vertexes and facets
   V  = N  = T  = NULL;
   Nv = Nn = Nt = 0;
   Mv = Mn = Mt = 0;
   while ((line = readline(f)))
   {
      //  Vertex coordinates (always 3)
      if (line[0]=='v' && line[1]==' ')
         readcoord(line+2,3,&V,&Nv,&Mv);
      //  Normal coordinates (always 3)
      else if (line[0]=='v' && line[1] == 'n')
         readcoord(line+2,3,&N,&Nn,&Mn);
      //  Texture coordinates (always 2)
      else if (line[0]=='v' && line[1] == 't')
         readcoord(line+2,2,&T,&Nt,&Mt);
      //  Read and draw facets
      else if (line[0]=='f')
      {
         line++;
         //  Read Vertex/Texture/Normal triplets
         glBegin(GL_POLYGON);
         while ((str = getword(&line)))
         {
            int Kv,Kt,Kn;
            //  Try Vertex/Texture/Normal triplet
            if (sscanf(str,"%d/%d/%d",&Kv,&Kt,&Kn)==3)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3);
               if (Kt<0 || Kt>Nt/2) Fatal("Texture %d out of range 1-%d\n",Kt,Nt/2);
            }
            //  Try Vertex//Normal pairs
            else if (sscanf(str,"%d//%d",&Kv,&Kn)==2)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3);
               Kt = 0;
            }
            //  Try Vertex index
            else if (sscanf(str,"%d",&Kv)==1)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               Kn = 0;
               Kt = 0;
            }
            //  This is an error
            else
               Fatal("Invalid facet %s\n",str);
            //  Draw vectors
            if (Kt) glTexCoord2fv(T+2*(Kt-1));
            if (Kn) glNormal3fv(N+3*(Kn-1));
            if (Kv) glVertex3fv(V+3*(Kv-1));
         }
         glEnd();
      }
      //  Use material
      else if ((str = readstr(line,"usemtl")))
         SetMaterial(str);
      //  Load materials
      else if ((str = readstr(line,"mtllib")))
         LoadMaterial(str);
      //  Skip this line
   }
   fclose(f);
   //  Pop attributes (textures)
   glPopAttrib();
   glEndList();

   //  Free materials
   for (k=0;k<Nmtl;k++)
      free(mtl[k].name);
   free(mtl);

   //  Free arrays
   free(V);
   free(T);
   free(N);

   return list;
}
Esempio n. 11
0
static void
armature (ModeInfo *mi)
{
  gears_configuration *bp = &bps[MI_SCREEN(mi)];
  int wire = MI_IS_WIREFRAME(mi);

  static const GLfloat spec[4] = {1.0, 1.0, 1.0, 1.0};
  GLfloat shiny = 128.0;
  GLfloat color[4];

  color[0] = 0.5 + frand(0.5);
  color[1] = 0.5 + frand(0.5);
  color[2] = 0.5 + frand(0.5);
  color[3] = 1.0;

  bp->armature_polygons = 0;

  bp->armature_dlist = glGenLists (1);
  if (! bp->armature_dlist)
    {
      check_gl_error ("glGenLists");
      abort();
    }

  glNewList (bp->armature_dlist, GL_COMPILE);

  glMaterialfv (GL_FRONT, GL_SPECULAR,  spec);
  glMateriali  (GL_FRONT, GL_SHININESS, shiny);
  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
  glColor3f (color[0], color[1], color[2]);

  glPushMatrix();

  {
    GLfloat s = bp->gears[0]->r * 2.7;
    s = s/5.6;
    glScalef (s, s, s);
  }

  glTranslatef (0, 0, 1.4 + bp->gears[0]->thickness);
  glRotatef (30, 0, 0, 1);

  bp->armature_polygons += ctube (0.5, 10, wire);       /* center axle */

  glPushMatrix();
  glTranslatef(0.0, 4.2, -1);
  bp->armature_polygons += ctube (0.5, 3, wire);       /* axle 1 */
  glTranslatef(0, 0, 1.8);
  bp->armature_polygons += ctube (0.7, 0.7, wire);
  glPopMatrix();

  glPushMatrix();
  glRotatef(120, 0.0, 0.0, 1.0);
  glTranslatef(0.0, 4.2, -1);
  bp->armature_polygons += ctube (0.5, 3, wire);       /* axle 2 */
  glTranslatef(0, 0, 1.8);
  bp->armature_polygons += ctube (0.7, 0.7, wire);
  glPopMatrix();

  glPushMatrix();
  glRotatef(240, 0.0, 0.0, 1.0);
  glTranslatef(0.0, 4.2, -1);
  bp->armature_polygons += ctube (0.5, 3, wire);       /* axle 3 */
  glTranslatef(0, 0, 1.8);
  bp->armature_polygons += ctube (0.7, 0.7, wire);
  glPopMatrix();

  glTranslatef(0, 0, 1.5);			      /* center disk */
  bp->armature_polygons += ctube (1.5, 2, wire);

  glPushMatrix();
  glRotatef(270, 0, 0, 1);
  glRotatef(-10, 0, 1, 0);
  glTranslatef(-2.2, 0, 0);
  bp->armature_polygons += arm (4.0, 1.0, 0.5,
                                2.0, 1.0, wire);	/* arm 1 */
  glPopMatrix();

  glPushMatrix();
  glRotatef(30, 0, 0, 1);
  glRotatef(-10, 0, 1, 0);
  glTranslatef(-2.2, 0, 0);
  bp->armature_polygons += arm (4.0, 1.0, 0.5,
                                2.0, 1.0, wire);	/* arm 2 */
  glPopMatrix();

  glPushMatrix();
  glRotatef(150, 0, 0, 1);
  glRotatef(-10, 0, 1, 0);
  glTranslatef(-2.2, 0, 0);
  bp->armature_polygons += arm (4.0, 1.0, 0.5,
                                2.0, 1.0, wire);	/* arm 3 */
  glPopMatrix();

  glPopMatrix();

  glEndList ();
}
Esempio n. 12
0
void MakeCallLists() 
{

GLUquadricObj	*gluLinkObj;
GLUquadricObj	*gluJointObj;
GLUquadricObj	*gluAxesObj;

gluLinkObj	= gluNewQuadric();
gluJointObj	= gluNewQuadric();
gluAxesObj	= gluNewQuadric();

/* **************************************************************************************************************************** */
	// Axes
	glNewList(AxesList, GL_COMPILE);
		glMatrixMode(GL_MODELVIEW);

		glPushMatrix();
		glColor3f(1, 0, 0);
		glTranslatef(-50.0, 0, 0);
		glScalef(100, 0.5, 0.5);
		glRotatef(90, 0, 1, 0);
		gluCylinder(gluAxesObj, 0.5, 0.5, 1.0, 15, 15);
		glPopMatrix();
		glPushMatrix();
		glTranslatef(50.0+3, 0, 0);
		glRotatef(-90, 0, 1, 0);
		gluCylinder(gluAxesObj, 0.0, 1.5, 3.0, 15, 15);
		glPopMatrix();

		glPushMatrix();
		glColor3f(0, 1, 0);
		glTranslatef(0.0, 50.0, 0);
		glScalef(0.5, 100.0, 0.5);
		glRotatef(90, 0, 1, 0);
		glRotatef(90, 1, 0, 0);
		gluCylinder(gluAxesObj, 0.5, 0.5, 1.0, 15, 15);
		glPopMatrix();
		glPushMatrix();
		glTranslatef(0.0, 50.0+3, 0);
		glRotatef(90, 0, 1, 0);
		glRotatef(90, 1, 0, 0);
		gluCylinder(gluAxesObj, 0.0, 1.5, 3.0, 15, 15);
		glPopMatrix();

		glPushMatrix();
		glColor3f(0, 0, 1);
		glTranslatef(0.0, 0.0, -50.0);
		glScalef(0.5, 0.5, 100.0);
		gluCylinder(gluAxesObj, 0.5, 0.5, 1.0, 15, 15);
		glPopMatrix();
		glPushMatrix();
		glTranslatef(0.0, 0.0, 50.0+3);
		glRotatef(180, 1, 0, 0);
		gluCylinder(gluAxesObj, 0.0, 1.5, 3.0, 15, 15);
		glPopMatrix();
 
	glEndList();
/* **************************************************************************************************************************** */
	// Segment
	glNewList(LinkList, GL_COMPILE);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glRotatef(90, 0, 1, 0);
		gluCylinder(gluLinkObj, 1.0, 1.0, 1.0, 30, 30);
		glPopMatrix();
	glEndList();
/* **************************************************************************************************************************** */
	// Articulation
	glNewList(JointList, GL_COMPILE);
		glMatrixMode(GL_MODELVIEW);
		gluSphere(gluJointObj, 1.0, 30, 30);
	glEndList();
/* **************************************************************************************************************************** */
	// Effecteur final
	glNewList(EEList, GL_COMPILE);
		glPushMatrix();
		glTranslatef(1*thickness, 0, 0);

		glPushMatrix();
		glScalef(2*thickness, thickness/3, thickness/2);
		glutSolidCube(1);
		glPopMatrix();

		glTranslatef(1*thickness+thickness/8, 0, 0);

		glPushMatrix();
		glScalef(thickness/4, 2*thickness, 2*thickness);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslatef(thickness/2 + thickness/8, 0, 0);
		glTranslatef(0, thickness - thickness/8, 0);
		glScalef(thickness, thickness/4, 2*thickness);
		glutSolidCube(1);
		glPopMatrix();
		
		glPushMatrix();
		glTranslatef(thickness/2 + thickness/8, 0, 0);
		glTranslatef(0, -thickness + thickness/8, 0);
		glScalef(thickness, thickness/4, 2*thickness);
		glutSolidCube(1);
		glPopMatrix();
		
		glPopMatrix();
	glEndList();
/* **************************************************************************************************************************** */
}
Esempio n. 13
0
/*
 =======================================================================================================================
    draws a checkered rectangle
 =======================================================================================================================
 */
static void drawCheck(int w, int h, int evenColor, int oddColor)
{
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	static int		initialized = 0;
	static int		usedLighting = 0;
	static GLuint	checklist = 0;
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	if(!initialized || (usedLighting != useLighting))
	{
		{
			/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
			static float	square_normal[4] = { 0.0, 0.0, 1.0, 0.0 };
			static float	square[4][4];
			int				i, j;
			/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

			if(!checklist)
			{
				checklist = glGenLists(1);
			}

			glNewList(checklist, GL_COMPILE_AND_EXECUTE);
			if(useQuads)
			{
				glNormal3fv(square_normal);
				glBegin(GL_QUADS);
			}

			for(j = 0; j < h; ++j)
			{
				{
					for(i = 0; i < w; ++i)
					{
						{
							square[0][0] = -1.0 + 2.0 / w * i;
							square[0][1] = -1.0 + 2.0 / h * (j + 1);
							square[0][2] = 0.0;
							square[0][3] = 1.0;
							square[1][0] = -1.0 + 2.0 / w * i;
							square[1][1] = -1.0 + 2.0 / h * j;
							square[1][2] = 0.0;
							square[1][3] = 1.0;
							square[2][0] = -1.0 + 2.0 / w * (i + 1);
							square[2][1] = -1.0 + 2.0 / h * j;
							square[2][2] = 0.0;
							square[2][3] = 1.0;
							square[3][0] = -1.0 + 2.0 / w * (i + 1);
							square[3][1] = -1.0 + 2.0 / h * (j + 1);
							square[3][2] = 0.0;
							square[3][3] = 1.0;
							if((i & 1) ^ (j & 1))
							{
								setColor(oddColor);
							}
							else
							{
								setColor(evenColor);
							}

							if(!useQuads)
							{
								glBegin(GL_POLYGON);
							}

							glVertex4fv(&square[0][0]);
							glVertex4fv(&square[1][0]);
							glVertex4fv(&square[2][0]);
							glVertex4fv(&square[3][0]);
							if(!useQuads)
							{
								glEnd();
							}
						}
					}
				}
			}

			if(useQuads)
			{
				glEnd();
			}

			glEndList();
			initialized = 1;
			usedLighting = useLighting;
		}
	}
	else
	{
		glCallList(checklist);
	}
}
Esempio n. 14
0
DWORD FFGLVolumeRendering::ProcessOpenGL(ProcessOpenGLStruct *pGL)
{
	if (pGL->numInputTextures<1)
		return FF_FAIL;

	if (pGL->inputTextures[0]==NULL)
		return FF_FAIL;

	


	FFGLTextureStruct &Texture = *(pGL->inputTextures[0]);

	//enable texturemapping
	glEnable(GL_TEXTURE_2D);

	//bind the texture handle
	glBindTexture(GL_TEXTURE_2D, Texture.Handle);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);


	

	//get the max s,t that correspond to the 
	//width,height of the used portion of the allocated texture space
	FFGLTexCoords maxCoords = GetMaxGLTexCoords(Texture);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);


	glMatrixMode(GL_PROJECTION);		
	
	// Saving the projection matrix
	glPushMatrix();
	
	glLoadIdentity();

	// Setting parallel projection 
	if (this->fIsPerspective == 0) 
		glOrtho(-1,1,-1,1,-2,2);
	else
	{
		gluPerspective( 90.0*(this->fAngle + 0.5) , 1, 0.1, 100.0);
		gluLookAt( 0, 0, 1.5, 0, 0, 0, 0, 1, 0 );
	}

	

	float xRotationAngle = (this->fXAngle - 0.5) * 180;
	float yRotationAngle = (this->fYAngle - 0.5) * 180;


	glRotatef(xRotationAngle, 1, 0, 0);
	glRotatef(yRotationAngle, 0, 1, 0); 

	glScalef(this->fScaleValue, this->fScaleValue, this->fScaleValue);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	


#ifndef  USE_VBO

	if (this->isGeometryRebuildNeeded)
	{	
		this->isGeometryRebuildNeeded = false;
		this->iList = glGenLists(1);
		glNewList( this->iList, GL_COMPILE);
		if (this->iPlanesCount > 1)
		{			
			double dZStep = (double)this->fDistance/(double)(this->iPlanesCount - 1);
			glBegin(GL_QUADS);
			for (int i=0 ; i < this->iPlanesCount ; i++)
			{
				double ZCoord = -(this->fDistance/2) + dZStep * (double)i;        

				//lower left
				glTexCoord2d(0.0, 0.0);
				glVertex3f(-1, -1, ZCoord);

				//upper left
				glTexCoord2d(0.0, maxCoords.t);
				glVertex3f(-1, 1, ZCoord);

				//upper right
				glTexCoord2d(maxCoords.s, maxCoords.t);
				glVertex3f(1, 1, ZCoord);

				//lower right
				glTexCoord2d(maxCoords.s, 0.0);
				glVertex3f(1, -1, ZCoord);
			};
			glEnd();
		}
		else	
		{// simple quad:

			glBegin(GL_QUADS);

			//lower left
			glTexCoord2d(0.0, 0.0);
			glVertex3f(-1, -1, 0);

			//upper left
			glTexCoord2d(0.0, maxCoords.t);
			glVertex3f(-1, 1, 0);

			//upper right
			glTexCoord2d(maxCoords.s, maxCoords.t);
			glVertex3f(1, 1, 0);

			//lower right
			glTexCoord2d(maxCoords.s, 0.0);
			glVertex3f(1, -1, 0);

			glEnd();
		};
		glEndList();
	}

	glCallList(this->iList);
#else
	int vertextDataSize = 0;
	int texcoordDataSize = 0;

	if (this->isGeometryRebuildNeeded)
	{
		this->isGeometryRebuildNeeded = false;

		this->CreateArrayData(maxCoords);

		vertextDataSize = 4 * this->iPlanesCount * sizeof(GLVertexTriplet);
		texcoordDataSize = 4 * this->iPlanesCount * sizeof(GLTexcoords);

		m_extensions.glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
		m_extensions.glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertextDataSize + texcoordDataSize, 0, GL_STATIC_DRAW_ARB);
		m_extensions.glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, vertextDataSize, this->VertexData); // copy vertices starting from 0 offest
		m_extensions.glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, vertextDataSize, texcoordDataSize, this->TexcoordData); // copy texcoords after vertices;

		m_extensions.glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);


	}
	
	m_extensions.glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	vertextDataSize = 4 * this->iPlanesCount * sizeof(GLVertexTriplet);
	texcoordDataSize = 4 * this->iPlanesCount * sizeof(GLTexcoords);

	glVertexPointer(3, GL_FLOAT, 0, 0);
	glTexCoordPointer(2, GL_FLOAT, 0, (void*)(vertextDataSize));

	glDrawArrays(GL_QUADS, 0, this->iPlanesCount*4);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	m_extensions.glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
	
#endif

	
	glMatrixMode(GL_PROJECTION);
	//Restoring projection matrix
	glPopMatrix();

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

	//disable texturemapping
	glDisable(GL_TEXTURE_2D);

	//disable blending
	glDisable(GL_BLEND);

	//restore default color
	glColor4f(1.f,1.f,1.f,1.f);

	return FF_SUCCESS;
}
Esempio n. 15
0
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Update
//
void CVisWindow::update(void)								// Here's Where We Do All The Drawing
{
//	if(WindowFlag && NeedsUpdate)  // Only draw when VisServer requests
	if(WindowFlag)                 // Draw when VisServer or OS requests
	{
		NeedsUpdate=0;

		/////////////////////////////////////////////////////////
		// Need to erase the old frame:
		// either XOR out the stuff or just clear the buffer

#if VISWIN_XOR_DRAWING
		// Enable XOR
		glEnable(GL_COLOR_LOGIC_OP);
		glLogicOp(GL_XOR);

		// Erase Last Image -- all drawing is assumed to be xor
		if( dispList[bufferId] ) glCallList(dispList[bufferId]);	// Have a previous list
		else{
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// else Initialize
			dispList[bufferId] = glGenLists(1);
		}

		// Now make a new Display List to save the new image
		glNewList(dispList[bufferId],GL_COMPILE);					// Start List

#else 
		// Clearing and redraw de novo each time
		// This may be too slow, in which case we'll need to 
		// use XOR drawing
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
#endif

		//////////////////////////////////////////////////////////
		// Draw Each Object, running through the linked list
		if(ObjList!=NULL){
			int done=0;
			VisObjectListStruct *objptr=ObjList;
			CVisObject *obj;

			while(!done){
				obj=(CVisObject*)(objptr->ptr);
				obj->draw();
				if(objptr->next!=NULL) objptr=objptr->next;
				else done=1;
			}
		}

		// Action Counter
		if(logmode) DrawCounter();

#if VISWIN_XOR_DRAWING
		// End List
		glEndList();
		// ... and then call it
		glCallList(dispList[bufferId]);
#endif

		// Double Buffering
		SwapBuffers(hDC);									// Swap Buffers (Double Buffering)
		bufferId = bufferId?0:1;							// Swap bufferId
	}
}
Esempio n. 16
0
static void draw_dodeca( void )
{
  GLuint list;

#define TAU ((SQRT5+1)/2)

  list = glGenLists( 1 );
  glNewList( list, GL_COMPILE );
  PENTAGON(1,seno,edgedivisions,sqr(TAU) * sqrt((TAU+2)/5) / 2);
  glEndList();

  glPushMatrix();
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  glCallList(list);
  glRotatef(180,0,0,1);
  glPushMatrix();
  glRotatef(-dodecaangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(-dodecaangle,cos72,sin72,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(-dodecaangle,cos72,-sin72,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(dodecaangle,cos36,-sin36,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
  glCallList(list);
  glPopMatrix();
  glRotatef(dodecaangle,cos36,sin36,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
  glCallList(list);
  glRotatef(180,0,0,1);
  glPushMatrix();
  glRotatef(-dodecaangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(-dodecaangle,cos72,sin72,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(-dodecaangle,cos72,-sin72,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(dodecaangle,cos36,-sin36,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]);
  glCallList(list);
  glPopMatrix();
  glRotatef(dodecaangle,cos36,sin36,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]);
  glCallList(list);

  glDeleteLists(list,1);
}
Esempio n. 17
0
void EDA_3D_CANVAS::buildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList )
{
    // Board shadows are based on board dimension.

    float xmin    = m_boardAABBox.Min().x;
    float xmax    = m_boardAABBox.Max().x;
    float ymin    = m_boardAABBox.Min().y;
    float ymax    = m_boardAABBox.Max().y;

    float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;

    // Shadow FRONT
    glNewList( aFrontList, GL_COMPILE );

    glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( F_Paste ) );

    glBegin (GL_QUADS);
    glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmin, ymin, zpos );
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmax, ymin, zpos );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmax, ymax, zpos );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmin, ymax, zpos );
    glEnd();

    glEndList();


    // Shadow BACK
    zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;

    glNewList( aBacklist, GL_COMPILE );

    glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( B_Paste ) );

    glBegin (GL_QUADS);
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmin, ymin, zpos );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmin, ymax, zpos );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmax, ymax, zpos );
    glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmax, ymin, zpos );
    glEnd();

    glEndList();

    // Shadow BOARD

    // Floor shadow is based on axis alighned bounding box dimension
    xmin = m_fastAABBox_Shadow.Min().x;
    xmax = m_fastAABBox_Shadow.Max().x;
    ymin = m_fastAABBox_Shadow.Min().y;
    ymax = m_fastAABBox_Shadow.Max().y;

    glNewList( aBoardList, GL_COMPILE );
    glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( F_Paste ) );

    glBegin (GL_QUADS);
    glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmin, ymin, m_fastAABBox_Shadow.Min().z );
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmax, ymin, m_fastAABBox_Shadow.Min().z );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmax, ymax, m_fastAABBox_Shadow.Min().z );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmin, ymax, m_fastAABBox_Shadow.Min().z );
    glEnd();

    glEndList();
}
Esempio n. 18
0
static void draw_ico( void )
{
  GLuint list;

  list = glGenLists( 1 );
  glNewList( list, GL_COMPILE );
  TRIANGLE(1.5,seno,edgedivisions,(3*SQRT3+SQRT15)/12);
  glEndList();

  glPushMatrix();

  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,0,1);
  glRotatef(-icoangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,0,1);
  glRotatef(-icoangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,0,1);
  glRotatef(-icoangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,0,1);
  glRotatef(-icoangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[12]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[13]);
  glCallList(list);
  glPopMatrix();
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[14]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[15]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,0,1);
  glRotatef(-icoangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[16]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[17]);
  glCallList(list);
  glPushMatrix();
  glRotatef(180,0,1,0);
  glRotatef(-180+icoangle,0.5,-SQRT3/2,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[18]);
  glCallList(list);
  glPopMatrix();
  glRotatef(180,0,0,1);
  glRotatef(-icoangle,1,0,0);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[19]);
  glCallList(list);

  glDeleteLists(list,1);
}
Esempio n. 19
0
void EDA_3D_CANVAS::buildFootprintShape3DList( GLuint aOpaqueList,
                                               GLuint aTransparentList,
                                               REPORTER* aErrorMessages,
                                               REPORTER* aActivity )
{
    DBG( unsigned strtime = GetRunningMicroSecs() );

    if( aActivity )
        aActivity->Report( _( "Load 3D Shapes" ) );

    // clean the parser list if it have any already loaded files
    m_model_parsers_list.clear();
    m_model_filename_list.clear();

    BOARD* pcb = GetBoard();

    for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
        read3DComponentShape( module );

    DBG( printf( "  read3DComponentShape total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );

    DBG( strtime = GetRunningMicroSecs() );

    bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );

    if( useMaterial )
    {
        // aOpaqueList is the gl list for non transparent items
        // aTransparentList is the gl list for non transparent items,
        // which need to be drawn after all other items

        glNewList( aOpaqueList, GL_COMPILE );
        bool loadOpaqueObjects = true;

        for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
            render3DComponentShape( module,  loadOpaqueObjects,
                                             !loadOpaqueObjects );

        glEndList();


        glNewList( aTransparentList, GL_COMPILE );
        bool loadTransparentObjects = true;

        for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
            render3DComponentShape( module, !loadTransparentObjects,
                                            loadTransparentObjects );

        glEndList();
    }
    else
    {
        // Just create one list
        glNewList( aOpaqueList, GL_COMPILE );

        for( MODULE* module = pcb->m_Modules; module; module = module->Next() )
            render3DComponentShape( module, false, false );
        glEndList();
    }

    DBG( printf( "  render3DComponentShape total time %f ms\n", (double) (GetRunningMicroSecs() - strtime) / 1000.0 ) );
}
Esempio n. 20
0
/**
 * body()
 *
 * Creates a display list for the body of a person.
 */
void body()
{
   GLfloat fan_angle;   //angle for a triangle fan
   int sections = 40;   //number of triangles in a triangle fan

   //generate a display list for a body
   body_list_id = glGenLists(1);
   //compile the new display list
   glNewList(body_list_id, GL_COMPILE);

   glPushMatrix();
      glTranslatef(0.0f, 5.05f, 0.0f);
      glRotatef(90, 1.0, 0.0, 0.0);

      //create a torso with a cylinder
      glPushMatrix();
         GLUquadricObj * torso;
         torso = gluNewQuadric();
         gluQuadricDrawStyle(torso, GLU_FILL);
         gluCylinder(torso, 1.0f, 1.0f, 2.25f, 25, 25);
      glPopMatrix();

      //triangle fan for top of body
      glPushMatrix();
         glRotatef(180.0, 0.0, 1.0, 0.0);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(cosf(fan_angle), sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //triangle fan for bottom of torso
      glPushMatrix();
         glTranslatef(0.0, 0.0, 2.25);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(cosf(fan_angle), sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //arm 1
      glPushMatrix();
         glTranslatef(1.25f, 0.0f, 0.0f);
         GLUquadricObj * arm1;
         arm1 = gluNewQuadric();
         gluQuadricDrawStyle(arm1, GLU_FILL);
         gluCylinder(arm1, 0.25f, 0.25f, 2.5f, 12, 12);
      glPopMatrix();

      //triangle fan for top of arm 1
      glPushMatrix();
         glTranslatef(1.25, 0.0, 0.0);
         glRotatef(180.0, 0.0, 1.0, 0.0);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //triangle fan for bottom of arm 1
      glPushMatrix();
         glTranslatef(1.25, 0.0, 2.5);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //arm 2
      glPushMatrix();
         glTranslatef(-1.25f, 0.0f, 0.0f);
         GLUquadricObj * arm2;
         arm2 = gluNewQuadric();
         gluQuadricDrawStyle(arm2, GLU_FILL);
         gluCylinder(arm2, 0.25f, 0.25f, 2.5f, 12, 12);
      glPopMatrix();

      //triangle fan for top of arm 2
      glPushMatrix();
         glTranslatef(-1.25, 0.0, 0.0);
         glRotatef(180.0, 0.0, 1.0, 0.0);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //triangle fan for bottom of arm 2
      glPushMatrix();
         glTranslatef(-1.25, 0.0, 2.5);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //leg 1
      glPushMatrix();
         glTranslatef(0.5f, 0.0f, 2.25f);
         GLUquadricObj * leg1;
         leg1 = gluNewQuadric();
         gluQuadricDrawStyle(leg1, GLU_FILL);
         gluCylinder(leg1, 0.5f, 0.2f, 2.8f, 12, 12);
      glPopMatrix();

      //triangle fan for bottom of leg 1
      glPushMatrix();
         glTranslatef(0.5, 0.0, 5.05);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.2*cosf(fan_angle), 0.2*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //leg 2
      glPushMatrix();
         glTranslatef(-0.5f, 0.0f, 2.25f);
         GLUquadricObj * leg2;
         leg2 = gluNewQuadric();
         gluQuadricDrawStyle(leg2, GLU_FILL);
         gluCylinder(leg2, 0.5f, 0.2f, 2.8f, 12, 12);
      glPopMatrix();

      //triangle fan for bottom of leg 2
      glPushMatrix();
         glTranslatef(-0.5, 0.0, 5.05);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.2*cosf(fan_angle), 0.2*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

   glPopMatrix();

   glEndList();
}
Esempio n. 21
0
PsychError SCREENFillOval(void)  
{	
	PsychRectType			rect;
	double					numSlices, radius, xScale, yScale, xTranslate, yTranslate, rectY, rectX;
	PsychWindowRecordType	*windowRecord;
	psych_bool				isArgThere, isclassic;
    double					*xy, *colors;
	unsigned char			*bytecolors;
	int						numRects, i, nc, mc, nrsize;
	GLUquadricObj			*diskQuadric;
	double					perfectUpToMaxDiameter;
	static double			perfectUpToMaxDiameterOld = 0;

	//all sub functions should have these two lines
	PsychPushHelp(useString, synopsisString,seeAlsoString);
	if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}
	
	//check for superfluous arguments
	PsychErrorExit(PsychCapNumInputArgs(4));   //The maximum number of inputs
	PsychErrorExit(PsychCapNumOutputArgs(0));  //The maximum number of outputs

	//get the window record from the window record argument and get info from the window record
	PsychAllocInWindowRecordArg(kPsychUseDefaultArgPosition, TRUE, &windowRecord);
    isclassic = PsychIsGLClassic(windowRecord);

	perfectUpToMaxDiameter = PsychGetWidthFromRect(windowRecord->clientrect);
	if (PsychGetHeightFromRect(windowRecord->clientrect) < perfectUpToMaxDiameter) perfectUpToMaxDiameter = PsychGetHeightFromRect(windowRecord->clientrect);
	PsychCopyInDoubleArg(4, kPsychArgOptional, &perfectUpToMaxDiameter);

    // Compute number of subdivisions (slices) to provide a perfect oval, i.e., one subdivision for each
    // distance unit on the circumference of the oval.
    numSlices = 3.14159265358979323846 * perfectUpToMaxDiameter;

    if ((perfectUpToMaxDiameter != perfectUpToMaxDiameterOld) || (windowRecord->fillOvalDisplayList == 0)) {
        perfectUpToMaxDiameterOld = perfectUpToMaxDiameter;

        // Destroy old display list so it gets rebuilt with the new numSlices setting:
        if (isclassic && (windowRecord->fillOvalDisplayList != 0)) {
            glDeleteLists(windowRecord->fillOvalDisplayList, 1);
            windowRecord->fillOvalDisplayList = 0;
        }
    }

    // Already cached display list for filled ovals for this windowRecord available?
    if (isclassic && (windowRecord->fillOvalDisplayList == 0)) {
        // Nope. Create our prototypical filled oval:
        // Generate a filled disk of that radius and subdivision and store it in a display list:
        diskQuadric=gluNewQuadric();
        windowRecord->fillOvalDisplayList = glGenLists(1);
        glNewList(windowRecord->fillOvalDisplayList, GL_COMPILE);
        gluDisk(diskQuadric, 0, 1, (int) numSlices, 1);
        glEndList();
        gluDeleteQuadric(diskQuadric);
        // Display list ready for use in this and all future drawing calls for this windowRecord.
    }

	// Query, allocate and copy in all vectors...
	numRects = 4;
	nrsize = 0;
	colors = NULL;
	bytecolors = NULL;
	mc = nc = 0;
	
	// The negative position -3 means: xy coords are expected at position 3, but they are optional.
	// NULL means - don't want a size's vector.
	PsychPrepareRenderBatch(windowRecord, -3, &numRects, &xy, 2, &nc, &mc, &colors, &bytecolors, 0, &nrsize, NULL, FALSE);

	// Only up to one rect provided?
	if (numRects <= 1) {
		// Get the oval and draw it:
		PsychCopyRect(rect, windowRecord->clientrect);
		isArgThere=PsychCopyInRectArg(kPsychUseDefaultArgPosition, FALSE, rect);
		if (isArgThere && IsPsychRectEmpty(rect)) return(PsychError_none);
		numRects = 1;
	}
	else {
		// Multiple ovals provided. Set up the first one:
		PsychCopyRect(rect, &xy[0]);
	}

	// Draw all ovals (one or multiple):
	for (i = 0; i < numRects;) {
		// Per oval color provided? If so then set it up. If only one common color
		// was provided then PsychPrepareRenderBatch() has already set it up.
		if (nc>1) {
			// Yes. Set color for this specific item:
			PsychSetArrayColor(windowRecord, i, mc, colors, bytecolors);
		}

		// Compute drawing parameters for ellipse:
		if (!IsPsychRectEmpty(rect)) {
			//The glu disk object location and size with a  center point and a radius,   
			//whereas FillOval accepts a bounding rect.   Converting from one set of parameters
			//to the other we should careful what we do for rects size of even number of pixels in length.
			PsychGetCenterFromRectAbsolute(rect, &xTranslate, &yTranslate);
			rectY=PsychGetHeightFromRect(rect);
			rectX=PsychGetWidthFromRect(rect);
			if(rectX == rectY){
				xScale=1; 
				yScale=1;
				radius=rectX/2;
			} else if(rectX > rectY){
				xScale=1;
				yScale=rectY/rectX;
				radius=rectX/2;
			} else {
				yScale=1;
				xScale=rectX/rectY;
				radius=rectY/2;
			}

            if (isclassic) {
                // Draw: Set up position, scale and size via matrix transform:
                glPushMatrix();
                glTranslatef((float) xTranslate, (float) yTranslate, (float) 0);
                glScalef((float) (xScale * radius), (float) (yScale * radius), (float) 1);
                // Draw cached disk object (stored in display list):
                glCallList(windowRecord->fillOvalDisplayList);
                glPopMatrix();
            }
            else {
                PsychDrawDisc(windowRecord, (float) xTranslate, (float) yTranslate, (float) 0, (float) radius, (int) numSlices, (float) xScale, (float) yScale, 0, 360);
            }
		}
		
		// Done with this one. Set up the next one, if any...
		i++;
		if (i < numRects) PsychCopyRect(rect, &xy[i*4]);

		// Next oval.
	}
	
	// Mark end of drawing op. This is needed for single buffered drawing:
	PsychFlushGL(windowRecord);

 	//All psychfunctions require this.
	return(PsychError_none);
}
Esempio n. 22
0
void SCENE::SetupDummies()
{
	bool Lighting=true;
	//na ez lovi be a scene display listjeit

	ObjDummyCount=CountObjects();
	ObjDummies=new OBJDUMMY[ObjDummyCount];
	memset(ObjDummies,0,sizeof(OBJDUMMY)*ObjDummyCount); //dummy tomb

	int FilledDummy=0;

	int x;
	for (x=0; x<ObjectNum; x++) //dummy tomb feltoltese
	{
		if (ObjectList[x].Primitive<100 && ObjectList[x].Primitive!=11 /*clone*/) CalculateDummy(&ObjectList[x],FilledDummy,&ObjectList[x].ModelView);
		if (ObjectList[x].Primitive==11 /*clone*/) SetupClones(this,x,FilledDummy,&ObjectList[x].ModelView);
	}

	qsort(ObjDummies,ObjDummyCount,sizeof(OBJDUMMY),DummyCompare); //attributumsort

	glNewList(ZmaskList,GL_COMPILE); //ket lista keszul, egy a zmaskos objecteknek, egy a nem zmaskosoknak
									 //ez a zmaskos, a nem zmaskos a valtaskor kap erteket
	glBegin(GL_TRIANGLES);
	unsigned char c[4],o[4];
	for (x=0; x<4; x++) c[x]=o[x]=2;

	for (int z=0; z<ObjDummyCount; z++) //a fo loop
	{
		//glErrorCheck();
		OBJECT *LastObject=NULL;
		if (z) LastObject=ObjDummies[z-1].OriginalObj;  //ez az elozo object, referencianak h melyik
														//attributum valtozott


		OBJECT *Object=ObjDummies[z].OriginalObj;		//az aktualis object

		//MATRIX Position;
		//memcpy(&Position,ObjDummies[z].ModelView,sizeof(MATRIX)); //az object pozicioja
		/*MATRIX InvTransp;
		memcpy(&InvTransp,&Position,sizeof(MATRIX));
		M_Invert(InvTransp);
		M_Transpose(InvTransp);*/
		
		//eltranszformaljuk az osszes vertexet a vegleges pozicioba, es kiszamoljuk a normalokat,
		//erre azert van szukseg mert igy jok lesznek a normalok es a nonuniform scalezettek nem bugzanak be
		for (x=0; x<Object->VertexNum; x++)
		{
				Object->VertexList[x].MapTransformedPosition=Object->VertexList[x].Position;
				M_Xformd(ObjDummies[z].ModelView,Object->VertexList[x].MapTransformedPosition,Object->VertexList[x].MapTransformedPosition);
		}
		Object->CalculateNormals();

		//ha szinvaltozas van
		bool NewCol=!LastObject;
		if (!ColorDiscard && LastObject) for (int a=0; a<4; a++) if (Object->Color.c[a]!=LastObject->Color.c[a]) NewCol=true;

		bool Cut;

		//ha elertunk a zmask valtashoz
		bool ZmaskChange=!Object->ZMask && (!LastObject || LastObject->ZMask);
		NewCol=ZmaskChange || NewCol;
		//ha envmap objecthez ertunk
		bool EnvmapTurnOn=((LastObject && !ObjDummies[z-1].Envmap) || !LastObject) && ObjDummies[z].Envmap;
		//ha wireframe valtas van
		//bool WireframeChange=!LastObject || ZmaskChange || EnvmapTurnOn || (Object->Wireframe != LastObject->Wireframe);
		//ha kikapcsolodott a textura
		bool TextureDisable=(!Object->Textured && ((LastObject && LastObject->Textured) || !LastObject));// || (WireframeChange && Object->Wireframe && !ObjDummies[z].Envmap);
		//ha valtozott a textura
		bool TextureChange=Object->Textured && (ZmaskChange || (!LastObject || !LastObject->Textured) || (LastObject && LastObject->Material->TextureID*8+LastObject->Material->SlotNumber!=Object->Material->TextureID*8+Object->Material->SlotNumber));// || (WireframeChange && !Object->Wireframe && Object->Textured));
		//ha valtozott a blendmode
		bool BlendChange=!LastObject || LastObject->SRCBlend!=Object->SRCBlend || LastObject->DSTBlend!=Object->DSTBlend;
		//ha valtozott az envmap
		bool EnvmapChange=Object->EnvMap && LastObject && ObjDummies[z-1].Envmap && (LastObject->EnvMap->TextureID*8+LastObject->EnvMap->SlotNumber!=Object->EnvMap->TextureID*8+Object->EnvMap->SlotNumber);
		//ha valtozott a backface culling ki be kapcsoltsaga
		bool BackChange=!LastObject || ZmaskChange || (Object->Backface != LastObject->Backface);
		//ha valtozott a backface culling iranya
		bool BackFrontChange=!LastObject || ZmaskChange || (Object->Backface && Object->Backfront!=LastObject->Backfront);
		//ha valtozott az alpha epsilon
		bool AepsilonChange=!LastObject || ZmaskChange || (Object->AEpsilon != LastObject->AEpsilon);

		//ha meg kell szakitani modvaltas miatt a glbegin() glend()-et
		Cut=ZmaskChange || 
			(!ObjDummies[z].Envmap && (TextureDisable || TextureChange || BlendChange) ) ||
			(ObjDummies[z].Envmap && (EnvmapTurnOn || EnvmapChange)) ||
			(NewCol && !ColorDiscard) ||
			BackChange ||
			BackFrontChange ||
			AepsilonChange;
			//||WireframeChange;

		//ha meg kell szakitani, akkor megszakitjuk :)
		if (Cut) glEnd();

		//zmask valtas, innen a nem zmaskos objectek jonnek (kulon listaba mert egy world tobb scenebol
		//allhat, es eloszor a zmaskos scene listakat kell renderelni, utana a nem zmaskosakat)
		if (ZmaskChange)
		{
			glEndList();
			glNewList(NoZmaskList,GL_COMPILE);
		}

		//alpha epsilon valtas
		if (AepsilonChange)
		{
			glAlphaFunc(GL_GEQUAL,Object->AEpsilon/255.0f);
		}

		//szinvaltas
		if (!ColorDiscard && NewCol) glColor4ub(Object->Color.c[0],Object->Color.c[1],Object->Color.c[2],Object->Color.c[3]);

		//backface cull ki/bekapcs
		if (BackChange)
			if (Object->Backface) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
		//backface cull reverse
		if (BackFrontChange)
			if (Object->Backfront) glCullFace(GL_FRONT); else glCullFace(GL_BACK);


		//ha nem envmap az object
		if (!ObjDummies[z].Envmap)
		{
			//textura kikapcs
			if (TextureDisable) glDisable(GL_TEXTURE_2D);

			//texturavaltas
			if (TextureChange)
			{
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D,Object->Material->ImageData.TextureHandle);
			}
			//blendmodevaltas
			if (BlendChange) glBlendFunc(Object->DSTBlend,Object->SRCBlend);
		}
		else
		//ha envmap az object
		{
			//envmap bekapcs
			if (EnvmapTurnOn)
			{
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D,Object->EnvMap->ImageData.TextureHandle);
				glEnable(GL_TEXTURE_GEN_S);
				glEnable(GL_TEXTURE_GEN_T);
				glBlendFunc(GL_ONE,GL_ONE);
			}
			//envmap textura valtas
			if (EnvmapChange) glBindTexture(GL_TEXTURE_2D,Object->EnvMap->ImageData.TextureHandle);				
		}

		/*if (WireframeChange)
		{
			if (!Object->Wireframe || ObjDummies[z].Envmap) 
			{
				if (Lighting)
				glEnable(GL_LIGHTING);
			}
			else 
			{
				Lighting=glIsEnabled(GL_LIGHTING)!=0;
				glDisable(GL_LIGHTING);
			}
		}*/

		//ha vagas volt, ujra kell glbegin
		if (Cut) 
			if (!Object->Wireframe || ObjDummies[z].Envmap)
			glBegin(GL_TRIANGLES);
			else
			glBegin(GL_LINES);

		if (!Object->Wireframe || ObjDummies[z].Envmap)
		{
			for (x=0; x<Object->PolygonNum; x++)
			{
				if (Object->PolygonList[x].CurrentShading!=aDDict_GOURAUDSHADE) 
					glNormal3f(Object->PolygonList[x].CurrentNormal.x,Object->PolygonList[x].CurrentNormal.y,Object->PolygonList[x].CurrentNormal.z);
				
				//vertex1

				if (Object->PolygonList[x].CurrentShading==aDDict_GOURAUDSHADE) 
					glNormal3f(Object->VertexList[Object->PolygonList[x].v[0]].CurrentNormal.x,Object->VertexList[Object->PolygonList[x].v[0]].CurrentNormal.y,Object->VertexList[Object->PolygonList[x].v[0]].CurrentNormal.z);
				if (Object->Textured) glTexCoord2f(Object->PolygonList[x].ct[0].x,Object->PolygonList[x].ct[0].y);
				glVertex3f(Object->VertexList[Object->PolygonList[x].v[0]].MapTransformedPosition.x,Object->VertexList[Object->PolygonList[x].v[0]].MapTransformedPosition.y,Object->VertexList[Object->PolygonList[x].v[0]].MapTransformedPosition.z);

				//vertex2
				
				if (Object->PolygonList[x].CurrentShading==aDDict_GOURAUDSHADE) 
					glNormal3f(Object->VertexList[Object->PolygonList[x].v[1]].CurrentNormal.x,Object->VertexList[Object->PolygonList[x].v[1]].CurrentNormal.y,Object->VertexList[Object->PolygonList[x].v[1]].CurrentNormal.z);
				if (Object->Textured) glTexCoord2f(Object->PolygonList[x].ct[1].x,Object->PolygonList[x].ct[1].y);			
				glVertex3f(Object->VertexList[Object->PolygonList[x].v[1]].MapTransformedPosition.x,Object->VertexList[Object->PolygonList[x].v[1]].MapTransformedPosition.y,Object->VertexList[Object->PolygonList[x].v[1]].MapTransformedPosition.z);

				//vertex3
				
				if (Object->PolygonList[x].CurrentShading==aDDict_GOURAUDSHADE) 
					glNormal3f(Object->VertexList[Object->PolygonList[x].v[2]].CurrentNormal.x,Object->VertexList[Object->PolygonList[x].v[2]].CurrentNormal.y,Object->VertexList[Object->PolygonList[x].v[2]].CurrentNormal.z);
				if (Object->Textured) glTexCoord2f(Object->PolygonList[x].ct[2].x,Object->PolygonList[x].ct[2].y);
				glVertex3f(Object->VertexList[Object->PolygonList[x].v[2]].MapTransformedPosition.x,Object->VertexList[Object->PolygonList[x].v[2]].MapTransformedPosition.y,Object->VertexList[Object->PolygonList[x].v[2]].MapTransformedPosition.z);
			}

			/*if (ObjDummies[z].Envmap)
			{
				glEnd();
				
				glColor4f(0,1,0,1);
				glDisable(GL_BLEND);
				glDisable(GL_LINE_SMOOTH);
				glDisable(GL_TEXTURE_2D);
				glBlendFunc(GL_ONE,GL_ZERO);
				glDisable(GL_LIGHTING);
				glBegin(GL_LINES);
				for (x=0; x<Object->VertexNum; x++)
				{
					glVertex3f(Object->VertexList[x].MapTransformedPosition.x,Object->VertexList[x].MapTransformedPosition.y,Object->VertexList[x].MapTransformedPosition.z);
					glVertex3f(Object->VertexList[x].MapTransformedPosition.x+Object->VertexList[x].CurrentNormal.x/5.0f,
							   Object->VertexList[x].MapTransformedPosition.y+Object->VertexList[x].CurrentNormal.y/5.0f,
							   Object->VertexList[x].MapTransformedPosition.z+Object->VertexList[x].CurrentNormal.z/5.0f);
				}
				glEnd();
			}


			glBegin(GL_TRIANGLES);*/

		}
		else
		{
			glEnd();
			glPushAttrib(GL_LIGHTING_BIT);
			glPushAttrib(GL_TEXTURE_BIT);
			glDisable(GL_LIGHTING);
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_LINES);
			for (x=0; x<Object->EdgeNum; x++)
				if (Object->EdgeList[x].InWireframe)
				{
					glVertex3f(Object->VertexList[Object->EdgeList[x].v1].MapTransformedPosition.x,Object->VertexList[Object->EdgeList[x].v1].MapTransformedPosition.y,Object->VertexList[Object->EdgeList[x].v1].MapTransformedPosition.z);
					glVertex3f(Object->VertexList[Object->EdgeList[x].v2].MapTransformedPosition.x,Object->VertexList[Object->EdgeList[x].v2].MapTransformedPosition.y,Object->VertexList[Object->EdgeList[x].v2].MapTransformedPosition.z);
				}
			glEnd();

			glPopAttrib();
			glPopAttrib();
			glBegin(GL_LINES);
		}

	}

	//ha elertunk minden vegere, lezarjuk a stuffot
	glEnd();
	glEndList();
}
Esempio n. 23
0
ENTRYPOINT void
init_cow (ModeInfo *mi)
{
  cow_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);
  int i;
  Bool tex_p = False;

  MI_INIT (mi, bps);

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_cow (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  glShadeModel(GL_SMOOTH);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_CULL_FACE);

  if (!wire)
    {
      GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0};
/*      GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/
      GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0};

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);

      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  bp->trackball = gltrackball_init (False);

  bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint));
  for (i = 0; i < countof(all_objs); i++)
    bp->dlists[i] = glGenLists (1);

  tex_p = load_texture (mi, do_texture);
  if (tex_p)
    glBindTexture (GL_TEXTURE_2D, bp->texture);

  for (i = 0; i < countof(all_objs); i++)
    {
      GLfloat black[4] = {0, 0, 0, 1};
      const struct gllist *gll = *all_objs[i];

      glNewList (bp->dlists[i], GL_COMPILE);

      glDisable (GL_TEXTURE_2D);

      if (i == HIDE)
        {
          GLfloat color[4] = {0.63, 0.43, 0.36, 1.00};
          if (tex_p)
            {
              /* if we have a texture, make the base color be white. */
              color[0] = color[1] = color[2] = 1.0;

              glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
              glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
              glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
              glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
              glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
              glEnable(GL_TEXTURE_GEN_S);
              glEnable(GL_TEXTURE_GEN_T);
              glEnable(GL_TEXTURE_2D);

              /* approximately line it up with ../images/earth.png */
              glMatrixMode (GL_TEXTURE);
              glLoadIdentity();
              glTranslatef (0.45, 0.58, 0);
              glScalef (0.08, 0.16, 1);
              glRotatef (-5, 0, 0, 1);
              glMatrixMode (GL_MODELVIEW);
            }
          glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
          glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,            black);
          glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS,           128); 
       }
      else if (i == TAIL)
        {
          GLfloat color[4] = {0.63, 0.43, 0.36, 1.00};
          glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
          glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,            black);
          glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS,           128);
        }
      else if (i == UDDER)
        {
          GLfloat color[4] = {1.00, 0.53, 0.53, 1.00};
          glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
          glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,            black);
          glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS,           128);
        }
      else if (i == HOOFS || i == HORNS)
        {
          GLfloat color[4] = {0.20, 0.20, 0.20, 1.00};
          GLfloat spec[4]  = {0.30, 0.30, 0.30, 1.00};
          GLfloat shiny    = 8.0;
          glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
          glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,            spec);
          glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS,           shiny);
        }
      else if (i == FACE)
        {
          GLfloat color[4] = {0.10, 0.10, 0.10, 1.00};
          GLfloat spec[4]  = {0.10, 0.10, 0.10, 1.00};
          GLfloat shiny    = 8.0;
          glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
          glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,            spec);
          glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS,           shiny);
        }
      else
        {
          GLfloat color[4] = {1.00, 1.00, 1.00, 1.00};
          GLfloat spec[4]  = {1.00, 1.00, 1.00, 1.00};
          GLfloat shiny    = 128.0;
          glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
          glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,            spec);
          glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS,           shiny);
        }

      renderList (gll, wire);

      glEndList ();
    }

  bp->nfloaters = MI_COUNT (mi);
  bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater));

  for (i = 0; i < bp->nfloaters; i++)
    {
      floater *f = &bp->floaters[i];
      f->rot = make_rotator (10.0, 0, 0,
                             4, 0.05 * speed,
                             True);
      if (bp->nfloaters == 2)
        {
          f->x = (i ? 6 : -6);
        }
      else if (i != 0)
        {
          double th = (i - 1) * M_PI*2 / (bp->nfloaters-1);
          double r = 10;
          f->x = r * cos(th);
          f->z = r * sin(th);
        }

      f->ix = f->x;
      f->iy = f->y;
      f->iz = f->z;
      reset_floater (mi, f);
    }
}
Esempio n. 24
0
void  DemoMesh::OptimizeForRender()
{
	// first make sure the previous optimization is removed
	ResetOptimization();

	dListNode* nextNode;
	for (dListNode* node = GetFirst(); node; node = nextNode) {
		DemoSubMesh& segment = node->GetInfo();
		nextNode = node->GetNext();
		if (segment.m_indexCount > 128 * 128 * 6) {
			SpliteSegment(node, 128 * 128 * 6);
		}
	}

#ifdef USING_DISPLAY_LIST
	bool isOpaque = false;
	bool hasTranparency = false;

	for (dListNode* node = GetFirst(); node; node = node->GetNext()) {
		DemoSubMesh& segment = node->GetInfo();
		isOpaque |= segment.m_opacity > 0.999f;
		hasTranparency |= segment.m_opacity <= 0.999f;
	}

	if (isOpaque) {
		m_optimizedOpaqueDiplayList = glGenLists(1);

		glNewList(m_optimizedOpaqueDiplayList, GL_COMPILE);

		//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

		for (dListNode* node = GetFirst(); node; node = node->GetNext()) {
			DemoSubMesh& segment = node->GetInfo();
			if (segment.m_opacity > 0.999f) {
				segment.OptimizeForRender(this);
			}
		}
		glEndList();
	}

	if (hasTranparency) {
        m_optimizedTransparentDiplayList = glGenLists(1);

        glNewList(m_optimizedTransparentDiplayList, GL_COMPILE);
        //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		glEnable (GL_BLEND);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        for (dListNode* node = GetFirst(); node; node = node->GetNext()) {
            DemoSubMesh& segment = node->GetInfo();
            if (segment.m_opacity <= 0.999f) {
                segment.OptimizeForRender(this);
            }
        }
		glDisable(GL_BLEND);
		glLoadIdentity();
        glEndList();
	}
#endif
}
Esempio n. 25
0
// Main
int main(int argc, char *argv[])
{
    TwBar *bar; // Pointer to the tweak bar
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutCreateWindow("AntTweakBar simple example using GLUT");
    glutCreateMenu(NULL);

    // Set GLUT callbacks
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    atexit(Terminate);  // Called after glutMainLoop ends

    // Initialize AntTweakBar
    TwInit(TW_OPENGL, NULL);

    // Set GLUT event callbacks
    // - Directly redirect GLUT mouse button events to AntTweakBar
    glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
    // - Directly redirect GLUT mouse motion events to AntTweakBar
    glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
    glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT key events to AntTweakBar
    glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
    // - Directly redirect GLUT special key events to AntTweakBar
    glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, 
               " label='Object rotation' opened=true help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, 
               " label='Light direction' opened=true help='Change the light direction.' ");

    // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");

    // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");

    // Add the enum variable 'g_CurrentShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }

    // Store time
    g_RotateTime = GetTimeMs();
    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

    // Call the GLUT main loop
    glutMainLoop();

    return 0;
}
void LevelRenderer::buildMap()
{
    GrassModel::teamNumber = false;
    TextureManager::getInstance()->toggleTextures(true);
    TextureManager::getInstance()->toggleSkins(0);
    //SKIN1 W/OUT TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(2, GL_COMPILE);
    /*for(int i = 0; i < rows; i++) {
    	for(int j = 0; j < columns; j++) {
    		glPushMatrix();

                glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
    			models[ level[i][j] ]->draw();
    		glPopMatrix();
    	}
    }*/
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=11) {
                models[0]->draw();
            }

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0f, 0.0f, 0.0f, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0f, 0.0f, 0.0f, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //SKIN2 W/OUT TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(6, GL_COMPILE);
    TextureManager::getInstance()->toggleSkins(1);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=11) {
                models[0]->draw();
            }

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //LIST FOR NO TEXTURES W/OUT TEAM NUMBER ----------------------------------------------------------------------------------------
    BoundingBox* tempBox;
    glNewList(5, GL_COMPILE);
    TextureManager::getInstance()->toggleTextures(false);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {

            if (level[i][j]==0)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }
            glPushMatrix();
            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=12) {
                models[0]->draw();
            }
            glPopMatrix();
            glDisable(GL_STENCIL_TEST);
            switch(level[i][j]) {
            case 1:
            case 6:
            case 7: //hills, plain and holloy block
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1), 1.0f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 4:
            case 5: //half blocks
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.5f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 2: //mountains
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+2),3.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 3: //fence
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),2.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 8:
            case 9:
            case 10:
            case 11: //pits and light rubble
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.01f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 13://base
                //5.0f,1.25f,4.0f
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+5.0f),1.25f, (GLfloat)(i+2.5f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                tempBox = new BoundingBox((GLfloat)(j+1.0f), 0.0f, (GLfloat)(i+2.5f), (GLfloat)(j+4.0f),0.75f, (GLfloat)(i+4.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 12://factory
                //3.0f,1.25f,2.0f
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)j, (GLfloat)(i+3.0f),1.25f, (GLfloat)(j+1.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+3.0f),1.25f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)(i+1.0f), (GLfloat)(j+3.0f),0.75f, (GLfloat)(i+2.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 14:
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1.0f),8.0f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                break;
            default:
                break;
            }
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();
    delete tempBox;

    GrassModel::teamNumber = true;
    TextureManager::getInstance()->toggleTextures(true);
    TextureManager::getInstance()->toggleSkins(0);

    //SKIN1 W/ TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(8, GL_COMPILE);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=11) {
                models[0]->draw();
            }

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, (GLfloat)rows, (GLfloat)rows,(GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //SKIN2 W TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(9, GL_COMPILE);
    TextureManager::getInstance()->toggleSkins(1);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            /*if(level[i][j] >=11){
            	models[0]->draw();
            }*/

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0,(GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //LIST FOR NO TEXTURES W/ TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(10, GL_COMPILE);
    toggleTeamNumber();
    TextureManager::getInstance()->toggleTextures(false);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {

            if (level[i][j]==0)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }
            glPushMatrix();
            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            /*if(level[i][j] >=12){
            	models[0]->draw();
            }*/
            glPopMatrix();
            glDisable(GL_STENCIL_TEST);
            switch(level[i][j]) {
            case 1:
            case 6:
            case 7: //hills, plain and holloy block
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1), 1.0f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 4:
            case 5: //half blocks
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.5f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 2: //mountains
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+2),3.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 3: //fence
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),2.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 8:
            case 9:
            case 10:
            case 11: //pits and light rubble
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.01f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 13://base
                //5.0f,1.25f,4.0f
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+5.0f),1.25f, (GLfloat)(i+2.5f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                tempBox = new BoundingBox((GLfloat)(j+1.0f), 0.0f, (GLfloat)(i+2.5f), (GLfloat)(j+4.0f),0.75f, (GLfloat)(i+4.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 12://factory
                //3.0f,1.25f,2.0f
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)j, (GLfloat)(i+3.0f),1.25f, (GLfloat)(j+1.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+3.0f),1.25f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)(i+1.0f), (GLfloat)(j+3.0f),0.75f, (GLfloat)(i+2.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 14:
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1.0f),8.0f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                //tempBox->hasNukePowerUp = true;
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                break;
            default:
                break;
            }
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i,0, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    delete tempBox;

}
Esempio n. 27
0
void init (void)
{
    GLUtesselator *tobj;
    GLdouble rect[4][3] = {50.0, 50.0, 0.0,
                           200.0, 50.0, 0.0,
                           200.0, 200.0, 0.0,
                           50.0, 200.0, 0.0
                          };
    GLdouble tri[3][3] = {75.0, 75.0, 0.0,
                          125.0, 175.0, 0.0,
                          175.0, 75.0, 0.0
                         };
    GLdouble star[5][6] = {250.0, 50.0, 0.0, 1.0, 0.0, 1.0,
                           325.0, 200.0, 0.0, 1.0, 1.0, 0.0,
                           400.0, 50.0, 0.0, 0.0, 1.0, 1.0,
                           250.0, 150.0, 0.0, 1.0, 0.0, 0.0,
                           400.0, 150.0, 0.0, 0.0, 1.0, 0.0
                          };

    glClearColor(0.0, 0.0, 0.0, 0.0);

    startList = glGenLists(2);

    tobj = gluNewTess();
    gluTessCallback(tobj, GLU_TESS_VERTEX,
                    glVertex3dv);
    gluTessCallback(tobj, GLU_TESS_BEGIN,
                    beginCallback);
    gluTessCallback(tobj, GLU_TESS_END,
                    endCallback);
    gluTessCallback(tobj, GLU_TESS_ERROR,
                    errorCallback);

    /*  rectangle with triangular hole inside  */
    glNewList(startList, GL_COMPILE);
    glShadeModel(GL_FLAT);
    gluTessBeginPolygon(tobj, NULL);
    gluTessBeginContour(tobj);
    gluTessVertex(tobj, rect[0], rect[0]);
    gluTessVertex(tobj, rect[1], rect[1]);
    gluTessVertex(tobj, rect[2], rect[2]);
    gluTessVertex(tobj, rect[3], rect[3]);
    gluTessEndContour(tobj);
    gluTessBeginContour(tobj);
    gluTessVertex(tobj, tri[0], tri[0]);
    gluTessVertex(tobj, tri[1], tri[1]);
    gluTessVertex(tobj, tri[2], tri[2]);
    gluTessEndContour(tobj);
    gluTessEndPolygon(tobj);
    glEndList();

    gluTessCallback(tobj, GLU_TESS_VERTEX,
                    vertexCallback);
    gluTessCallback(tobj, GLU_TESS_BEGIN,
                    beginCallback);
    gluTessCallback(tobj, GLU_TESS_END,
                    endCallback);
    gluTessCallback(tobj, GLU_TESS_ERROR,
                    errorCallback);
    gluTessCallback(tobj, GLU_TESS_COMBINE,
                    combineCallback);

    /*  smooth shaded, self-intersecting star  */
    glNewList(startList + 1, GL_COMPILE);
    glShadeModel(GL_SMOOTH);
    gluTessProperty(tobj, GLU_TESS_WINDING_RULE,
                    GLU_TESS_WINDING_POSITIVE);
    gluTessBeginPolygon(tobj, NULL);
    gluTessBeginContour(tobj);
    gluTessVertex(tobj, star[0], star[0]);
    gluTessVertex(tobj, star[1], star[1]);
    gluTessVertex(tobj, star[2], star[2]);
    gluTessVertex(tobj, star[3], star[3]);
    gluTessVertex(tobj, star[4], star[4]);
    gluTessEndContour(tobj);
    gluTessEndPolygon(tobj);
    glEndList();
    gluDeleteTess(tobj);
}
GLWidget::GLWidget(QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    setWindowTitle(tr("OpenGL pbuffers 2"));

    pbuffer = new QGLPixelBuffer(1024, 1024, format(), this);

    rot_x = rot_y = rot_z = 0.0f;
    scale = 0.1f;
    anim = new QTimeLine(750, this);
    anim->setUpdateInterval(20);
    connect(anim, SIGNAL(valueChanged(qreal)), SLOT(animate(qreal)));
    connect(anim, SIGNAL(finished()), SLOT(animFinished()));

    svg_renderer = new QSvgRenderer(QLatin1String(":/res/bubbles.svg"), this);
    connect(svg_renderer, SIGNAL(repaintNeeded()), this, SLOT(draw()));

    logo = QImage(":/res/designer.png");
    logo = logo.convertToFormat(QImage::Format_ARGB32);

    makeCurrent(); // need a current context to create the display list
    tile_list = glGenLists(1);
    glNewList(tile_list, GL_COMPILE);
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);

        glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);

        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);

        glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);

        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);

        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
}
    glEnd();
    glEndList();

    wave = new GLfloat[logo.width()*logo.height()];
    memset(wave, 0, logo.width()*logo.height());
    startTimer(30); // wave timer

    pbuffer->makeCurrent();
    dynamicTexture = pbuffer->generateDynamicTexture();

    // bind the dynamic texture to the pbuffer - this is a no-op under X11
    hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
}
Esempio n. 29
0
void
Fake_glXUseXFont(Font font, int first, int count, int listbase)
{
   Display *dpy;
   Window win;
   Pixmap pixmap;
   GC gc;
   XGCValues values;
   unsigned long valuemask;
   XFontStruct *fs;
   GLint swapbytes, lsbfirst, rowlength;
   GLint skiprows, skippixels, alignment;
   unsigned int max_width, max_height, max_bm_width, max_bm_height;
   GLubyte *bm;
   int i;

   dpy = glXGetCurrentDisplay();
   if (!dpy)
      return;			/* I guess glXMakeCurrent wasn't called */
   win = RootWindow(dpy, DefaultScreen(dpy));

   fs = XQueryFont(dpy, font);
   if (!fs) {
      _mesa_error(NULL, GL_INVALID_VALUE,
		  "Couldn't get font structure information");
      return;
   }

   /* Allocate a bitmap that can fit all characters.  */
   max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing;
   max_height = fs->max_bounds.ascent + fs->max_bounds.descent;
   max_bm_width = (max_width + 7) / 8;
   max_bm_height = max_height;

   bm = (GLubyte *) MALLOC((max_bm_width * max_bm_height) * sizeof(GLubyte));
   if (!bm) {
      XFreeFontInfo(NULL, fs, 1);
      _mesa_error(NULL, GL_OUT_OF_MEMORY,
		  "Couldn't allocate bitmap in glXUseXFont()");
      return;
   }

#if 0
   /* get the page info */
   pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
   firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2;
   lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2;
   rows = fs->max_byte1 - fs->min_byte1 + 1;
   unsigned int first_char, last_char, pages, rows;
#endif

   /* Save the current packing mode for bitmaps.  */
   glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
   glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
   glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
   glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
   glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
   glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);

   /* Enforce a standard packing mode which is compatible with
      fill_bitmap() from above.  This is actually the default mode,
      except for the (non)alignment.  */
   glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
   glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
   glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
   glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
   glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   pixmap = XCreatePixmap(dpy, win, 10, 10, 1);
   values.foreground = BlackPixel(dpy, DefaultScreen(dpy));
   values.background = WhitePixel(dpy, DefaultScreen(dpy));
   values.font = fs->fid;
   valuemask = GCForeground | GCBackground | GCFont;
   gc = XCreateGC(dpy, pixmap, valuemask, &values);
   XFreePixmap(dpy, pixmap);

#ifdef DEBUG
   if (debug_xfonts)
      dump_font_struct(fs);
#endif

   for (i = 0; i < count; i++) {
      unsigned int width, height, bm_width, bm_height;
      GLfloat x0, y0, dx, dy;
      XCharStruct *ch;
      int x, y;
      unsigned int c = first + i;
      int list = listbase + i;
      int valid;

      /* check on index validity and get the bounds */
      ch = isvalid(fs, c);
      if (!ch) {
	 ch = &fs->max_bounds;
	 valid = 0;
      }
      else {
	 valid = 1;
      }

#ifdef DEBUG
      if (debug_xfonts) {
	 char s[7];
	 sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
	 dump_char_struct(ch, s);
      }
#endif

      /* glBitmap()' parameters:
         straight from the glXUseXFont(3) manpage.  */
      width = ch->rbearing - ch->lbearing;
      height = ch->ascent + ch->descent;
      x0 = -ch->lbearing;
      y0 = ch->descent - 0;	/* XXX used to subtract 1 here */
      /* but that caused a conformace failure */
      dx = ch->width;
      dy = 0;

      /* X11's starting point.  */
      x = -ch->lbearing;
      y = ch->ascent;

      /* Round the width to a multiple of eight.  We will use this also
         for the pixmap for capturing the X11 font.  This is slightly
         inefficient, but it makes the OpenGL part real easy.  */
      bm_width = (width + 7) / 8;
      bm_height = height;

      glNewList(list, GL_COMPILE);
      if (valid && (bm_width > 0) && (bm_height > 0)) {

	 memset(bm, '\0', bm_width * bm_height);
	 fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);

	 glBitmap(width, height, x0, y0, dx, dy, bm);
#ifdef DEBUG
	 if (debug_xfonts) {
	    printf("width/height = %u/%u\n", width, height);
	    printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height);
	    dump_bitmap(bm_width, bm_height, bm);
	 }
#endif
      }
      else {
	 glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
      }
      glEndList();
   }

   FREE(bm);
   XFreeFontInfo(NULL, fs, 1);
   XFreeGC(dpy, gc);

   /* Restore saved packing modes.  */
   glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
   glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
   glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
   glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
   glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
   glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
}
Esempio n. 30
0
File: load.c Progetto: XAMEUS/CPROJ6
GLuint Tess_Obj_Way(int c, GLdouble ** points, way w)
{
	GLuint id = glGenLists(1);
	if (!id) {
		fprintf(stderr, "failed to create a list, return 0\n");
		return id;
	}
	GLdouble size = 1.0f;
	GLdouble pos = 1.0f;
	glNewList(id, GL_COMPILE);

	int border = 1;
	if (w.highway != 0) {
		switch (w.highway) {
		case HIGHWAY_MOTORWAY:
			HIGHWAY_MOTORWAY_COLOR;
			size = HIGHWAY_MOTORWAY_SIZE;
			pos = HIGHWAY_MOTORWAY_DEPTH;
			break;
		case HIGHWAY_TRUNK:
			HIGHWAY_TRUNK_COLOR;
			size = HIGHWAY_TRUNK_SIZE;
			pos = HIGHWAY_TRUNK_DEPTH;
			break;
		case HIGHWAY_PRIMARY:
			HIGHWAY_PRIMARY_COLOR;
			size = HIGHWAY_PRIMARY_SIZE;
			pos = HIGHWAY_PRIMARY_DEPTH;
			break;
		case HIGHWAY_SECONDARY:
			HIGHWAY_SECONDARY_COLOR;
			size = HIGHWAY_SECONDARY_SIZE;
			pos = HIGHWAY_SECONDARY_DEPTH;
			break;
		case HIGHWAY_TERTIARY:
			HIGHWAY_TERTIARY_COLOR;
			size = HIGHWAY_TERTIARY_SIZE;
			pos = HIGHWAY_TERTIARY_DEPTH;
			break;
		case HIGHWAY_UNCLASSIFIED:
			HIGHWAY_UNCLASSIFIED_COLOR;
			size = HIGHWAY_UNCLASSIFIED_SIZE;
			pos = HIGHWAY_UNCLASSIFIED_DEPTH;
			break;
		case HIGHWAY_RESIDENTIAL:
			HIGHWAY_RESIDENTIAL_COLOR;
			size = HIGHWAY_RESIDENTIAL_SIZE;
			pos = HIGHWAY_RESIDENTIAL_DEPTH;
			break;
		case HIGHWAY_SERVICE:
			HIGHWAY_SERVICE_COLOR;
			size = HIGHWAY_SERVICE_SIZE;
			pos = HIGHWAY_SERVICE_DEPTH;
			break;
		case HIGHWAY_MOTORWAY_LINK:
			HIGHWAY_MOTORWAY_LINK_COLOR;
			size = HIGHWAY_MOTORWAY_LINK_SIZE;
			pos = HIGHWAY_MOTORWAY_LINK_DEPTH;
			break;
		case HIGHWAY_TRUNK_LINK:
			HIGHWAY_TRUNK_LINK_COLOR;
			size = HIGHWAY_TRUNK_LINK_SIZE;
			pos = HIGHWAY_DEPTH;
			break;
		case HIGHWAY_PRIMARY_LINK:
			HIGHWAY_PRIMARY_LINK_COLOR;
			size = HIGHWAY_PRIMARY_LINK_SIZE;
			pos = HIGHWAY_PRIMARY_LINK_DEPTH;
			break;
		case HIGHWAY_SECONDARY_LINK:
			HIGHWAY_SECONDARY_LINK_COLOR;
			size = HIGHWAY_SECONDARY_LINK_SIZE;
			pos = HIGHWAY_SECONDARY_LINK_DEPTH;
			break;
		case HIGHWAY_TERTIARY_LINK:
			HIGHWAY_TERTIARY_LINK_COLOR;
			size = HIGHWAY_TERTIARY_LINK_SIZE;
			pos = HIGHWAY_TERTIARY_LINK_DEPTH;
			break;
		case HIGHWAY_LIVING_STREET:
			HIGHWAY_LIVING_STREET_COLOR;
			size = HIGHWAY_LIVING_STREET_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		case HIGHWAY_PEDESTRIAN:
			HIGHWAY_PEDESTRIAN_COLOR;
			size = HIGHWAY_PEDESTRIAN_SIZE;
			pos = HIGHWAY_PEDESTRIAN_DEPTH;
			break;
		case HIGHWAY_TRACK:
			HIGHWAY_TRACK_COLOR;
			size = HIGHWAY_TRACK_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		case HIGHWAY_ROAD:
			HIGHWAY_ROAD_COLOR;
			size = HIGHWAY_ROAD_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		case HIGHWAY_FOOTWAY:
			HIGHWAY_FOOTWAY_COLOR;
			size = HIGHWAY_FOOTWAY_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		case HIGHWAY_BRIDLEWAY:
			HIGHWAY_BRIDLEWAY_COLOR;
			size = HIGHWAY_BRIDLEWAY_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		case HIGHWAY_STEPS:
			HIGHWAY_STEPS_COLOR;
			size = HIGHWAY_STEPS_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		case HIGHWAY_PATH:
			HIGHWAY_PATH_COLOR;
			size = HIGHWAY_PATH_SIZE;
			pos = HIGHWAY_LIVING_STREET_DEPTH;
			break;
		}
	} else if (w.natural != 0) {
		color_natural(w.natural);
		size = 1.0f;
		if (w.natural == NATURAL_COASTLINE) {
			size = 10.0f;
		}
		border = 0;
		pos = NATURAL_DEPTH;
	} else if (w.leisure != 0) {
		color_leisure(w.leisure);
		size = 1.0f;
		border = 0;
		pos = LEISURE_DEPTH;
	} else if (w.waterway != 0) {
		WATERWAY_COLOR;
		pos = WATERWAY_DEPTH;
		border = 0;
		switch (w.highway) {
		case WATERWAY_RIVER:
			size = WATERWAY_RIVER_SIZE;
			break;
		case WATERWAY_STREAM:
			size = WATERWAY_STREAM_SIZE;
			break;
		case WATERWAY_CANAL:
			size = WATERWAY_CANAL_SIZE;
			break;
		case WATERWAY_DRAIN:
			size = WATERWAY_DRAIN_SIZE;
			break;
		case WATERWAY_DITCH:
			size = WATERWAY_DITCH_SIZE;
			break;
		}
	} else if (w.railway != 0) {
		RAILWAY_COLOR;
		size = RAILWAY_SIZE;
		pos = RAILWAY_DEPTH;
	} else if (w.bridge != 0) {
		BRIDGE_COLOR;
		pos = BRIDGE_DEPTH;
	}

	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0, 1.0);
	Draw_Lines(c, points, size, pos);
	if (border) {
		glColor3f(0.0f, 0.0f, 0.0f);
		Draw_Lines(c, points, size + 0.75f, pos - 1.0f);
	}
	glDisable(GL_POLYGON_OFFSET_FILL);
	if (DEBUG) {
		glColor4f(0.5f, 0.9f, 0.5f, 0.8f);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		Draw_Lines(c, points, size, pos);
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}
	glEndList();

	return id;
}