Exemple #1
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 = &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);
}
// render
void PlayerOverlayAmmo::Render(unsigned int aId, float aTime, const Transform2 &aTransform)
{
	// get the player
	Player *player = Database::player.Get(aId);

	// get the attached entity identifier
	unsigned int id = player->mAttach;

	// draw player ammo (HACK)
	Resource *ammoresource = Database::resource.Get(id).Get(0x5b9b0daf /* "ammo" */);
	if (!ammoresource)
		return;

	// get ammo ratio
	float new_ammo = 0.0f;
	const ResourceTemplate &ammoresourcetemplate = Database::resourcetemplate.Get(id).Get(0x5b9b0daf /* "ammo" */);
	if (ammoresourcetemplate.mMaximum > 0)
	{
		new_ammo = ammoresource->GetValue() / ammoresourcetemplate.mMaximum;
	}
	
	// get level
	int new_level = 1;
	Resource *levelresource = Database::resource.Get(id).Get(0x9b99e7dd /* "level" */);
	if (levelresource)
	{
		new_level = xs_FloorToInt(levelresource->GetValue());
	}

	// if the lives count has not changed...
	if (new_ammo == cur_ammo && new_level == cur_level && glIsList(ammo_handle))
	{
		// call the existing draw list
		glCallList(ammo_handle);
		return;
	}

	// update ammo
	cur_ammo = new_ammo;
	cur_level = new_level;

	// start a new draw list list
	glNewList(ammo_handle, GL_COMPILE_AND_EXECUTE);

	glBegin(GL_QUADS);

	// background
	glColor4fv(ammocolor[cur_level]);
	glVertex2f(ammorect.x, ammorect.y);
	glVertex2f(ammorect.x + ammorect.w, ammorect.y);
	glVertex2f(ammorect.x + ammorect.w, ammorect.y + ammorect.h);
	glVertex2f(ammorect.x, ammorect.y + ammorect.h);

	// fill gauge
	glColor4fv(ammocolor[cur_level+1]);
	glVertex2f(ammorect.x, ammorect.y);
	glVertex2f(ammorect.x + ammorect.w * cur_ammo, ammorect.y);
	glVertex2f(ammorect.x + ammorect.w * cur_ammo, ammorect.y + ammorect.h);
	glVertex2f(ammorect.x, ammorect.y + ammorect.h);

	glEnd();

	glEndList();
}
Exemple #3
0
/***********************************************************************
 *		wglUseFontOutlines_common
 */
static BOOL wglUseFontOutlines_common(HDC hdc,
                                      DWORD first,
                                      DWORD count,
                                      DWORD listBase,
                                      FLOAT deviation,
                                      FLOAT extrusion,
                                      int format,
                                      LPGLYPHMETRICSFLOAT lpgmf,
                                      BOOL unicode)
{
    UINT glyph;
    const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}};
    GLUtesselator *tess;
    LOGFONTW lf;
    HFONT old_font, unscaled_font;
    UINT em_size = 1024;
    RECT rc;

    TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count,
          listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A");

    if (!load_libglu())
    {
        ERR("libGLU is required for this function but isn't loaded\n");
        return FALSE;
    }

    ENTER_GL();
    tess = pgluNewTess();
    if(tess)
    {
        pgluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex);
        pgluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin);
        pgluTessCallback(tess, GLU_TESS_END, tess_callback_end);
    }
    LEAVE_GL();

    if(!tess) return FALSE;

    GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
    rc.left = rc.right = rc.bottom = 0;
    rc.top = em_size;
    DPtoLP(hdc, (POINT*)&rc, 2);
    lf.lfHeight = -abs(rc.top - rc.bottom);
    lf.lfOrientation = lf.lfEscapement = 0;
    unscaled_font = CreateFontIndirectW(&lf);
    old_font = SelectObject(hdc, unscaled_font);

    for (glyph = first; glyph < first + count; glyph++)
    {
        DWORD needed;
        GLYPHMETRICS gm;
        BYTE *buf;
        TTPOLYGONHEADER *pph;
        TTPOLYCURVE *ppc;
        GLdouble *vertices;

        if(unicode)
            needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);
        else
            needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity);

        if(needed == GDI_ERROR)
            goto error;

        buf = HeapAlloc(GetProcessHeap(), 0, needed);
        vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble));

        if(unicode)
            GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);
        else
            GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity);

        TRACE("glyph %d\n", glyph);

        if(lpgmf)
        {
            lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size;
            lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size;
            lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size;
            lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size;
            lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size;
            lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size;

            TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY,
                  lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY); 
            lpgmf++;
        }

	ENTER_GL();
	glNewList(listBase++, GL_COMPILE);
        pgluTessBeginPolygon(tess, NULL);

        pph = (TTPOLYGONHEADER*)buf;
        while((BYTE*)pph < buf + needed)
        {
            TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value);

            pgluTessBeginContour(tess);

            fixed_to_double(pph->pfxStart, em_size, vertices);
            pgluTessVertex(tess, vertices, vertices);
            vertices += 3;

            ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph));
            while((char*)ppc < (char*)pph + pph->cb)
            {
                int i;

                switch(ppc->wType) {
                case TT_PRIM_LINE:
                    for(i = 0; i < ppc->cpfx; i++)
                    {
                        TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value);
                        fixed_to_double(ppc->apfx[i], em_size, vertices); 
                        pgluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                    }
                    break;

                case TT_PRIM_QSPLINE:
                    for(i = 0; i < ppc->cpfx/2; i++)
                    {
                        /* FIXME just connecting the control points for now */
                        TRACE("\t\tcurve  %d,%d %d,%d\n",
                              ppc->apfx[i * 2].x.value,     ppc->apfx[i * 3].y.value,
                              ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value);
                        fixed_to_double(ppc->apfx[i * 2], em_size, vertices); 
                        pgluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                        fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices); 
                        pgluTessVertex(tess, vertices, vertices);
                        vertices += 3;
                    }
                    break;
                default:
                    ERR("\t\tcurve type = %d\n", ppc->wType);
                    pgluTessEndContour(tess);
                    goto error_in_list;
                }

                ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) +
                                     (ppc->cpfx - 1) * sizeof(POINTFX));
            }
            pgluTessEndContour(tess);
            pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb);
        }

error_in_list:
        pgluTessEndPolygon(tess);
        glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0);
        glEndList();
        LEAVE_GL();
        HeapFree(GetProcessHeap(), 0, buf);
        HeapFree(GetProcessHeap(), 0, vertices);
    }

 error:
    DeleteObject(SelectObject(hdc, old_font));
    pgluDeleteTess(tess);
    return TRUE;

}
Exemple #4
0
	// Create A Display List Corresponding To The Given Character.
	void make_dlist ( FT_Face face, char ch, GLuint list_base, GLuint * tex_base ) {

		// The First Thing We Do Is Get FreeType To Render Our Character
		// Into A Bitmap.  This Actually Requires A Couple Of FreeType Commands:

		// Load The Glyph For Our Character.
		if(FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ))
			throw std::runtime_error("FT_Load_Glyph failed");

		// Move The Face's Glyph Into A Glyph Object.
		FT_Glyph glyph;
		if(FT_Get_Glyph( face->glyph, &glyph ))
			throw std::runtime_error("FT_Get_Glyph failed");

		// Convert The Glyph To A Bitmap.
		FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
		FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;

		// This Reference Will Make Accessing The Bitmap Easier.
		FT_Bitmap& bitmap=bitmap_glyph->bitmap;
		// Use Our Helper Function To Get The Widths Of
			// The Bitmap Data That We Will Need In Order To Create
			// Our Texture.
		int width = next_p2( bitmap.width );
		int height = next_p2( bitmap.rows );

		// Allocate Memory For The Texture Data.
		GLubyte* expanded_data = new GLubyte[ 2 * width * height];

		// Here We Fill In The Data For The Expanded Bitmap.
		// Notice That We Are Using A Two Channel Bitmap (One For
		// Channel Luminosity And One For Alpha), But We Assign
		// Both Luminosity And Alpha To The Value That We
		// Find In The FreeType Bitmap.
		// We Use The ?: Operator To Say That Value Which We Use
		// Will Be 0 If We Are In The Padding Zone, And Whatever
		// Is The FreeType Bitmap Otherwise.
		for(int j=0; j <height;j++) {
			for(int i=0; i < width; i++){
				expanded_data[2*(i+j*width)]= expanded_data[2*(i+j*width)+1] =
					(i>=bitmap.width || j>=bitmap.rows) ?
					0 : bitmap.buffer[i + bitmap.width*j];
			}
		}

		// Now We Just Setup Some Texture Parameters.
		glBindTexture( GL_TEXTURE_2D, tex_base[ch]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

		// Here We Actually Create The Texture Itself, Notice
		// That We Are Using GL_LUMINANCE_ALPHA To Indicate That
		// We Are Using 2 Channel Data.
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
			GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data );

		// With The Texture Created, We Don't Need The Expanded Data Anymore.
		delete [] expanded_data;
		// Now We Create The Display List
		glNewList(list_base+ch,GL_COMPILE);

		glBindTexture(GL_TEXTURE_2D,tex_base[ch]);

		glPushMatrix();

		// First We Need To Move Over A Little So That
		// The Character Has The Right Amount Of Space
		// Between It And The One Before It.
		glTranslatef(bitmap_glyph->left,0,0);

		// Now We Move Down A Little In The Case That The
		// Bitmap Extends Past The Bottom Of The Line
		// This Is Only True For Characters Like 'g' Or 'y'.
		glTranslatef(0,bitmap_glyph->top-bitmap.rows,0);

		// Now We Need To Account For The Fact That Many Of
		// Our Textures Are Filled With Empty Padding Space.
		// We Figure What Portion Of The Texture Is Used By
		// The Actual Character And Store That Information In
		// The x And y Variables, Then When We Draw The
		// Quad, We Will Only Reference The Parts Of The Texture
		// That Contains The Character Itself.
		float   x=(float)bitmap.width / (float)width,
			y=(float)bitmap.rows / (float)height;

		// Here We Draw The Texturemapped Quads.
		// The Bitmap That We Got From FreeType Was Not
		// Oriented Quite Like We Would Like It To Be,
		// But We Link The Texture To The Quad
		// In Such A Way That The Result Will Be Properly Aligned.
		glBegin(GL_QUADS);
		glTexCoord2d(0,0); glVertex2f(0,bitmap.rows);
		glTexCoord2d(0,y); glVertex2f(0,0);
		glTexCoord2d(x,y); glVertex2f(bitmap.width,0);
		glTexCoord2d(x,0); glVertex2f(bitmap.width,bitmap.rows);
		glEnd();
		glPopMatrix();
		glTranslatef(face->glyph->advance.x >> 6 ,0,0);

		// Increment The Raster Position As If We Were A Bitmap Font.
		// (Only Needed If You Want To Calculate Text Length)
		// glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL);

		// Finish The Display List
		glEndList();
	}
/* called at init this creates the 'carpet' display list item */
static void buildCarpet(ModeInfo *mi)
{
	int i,c,x,y;
	GLfloat color[4];
  	int wire = MI_IS_WIREFRAME(mi);
  	topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
		color[0] = 0.0f;	
		color[1] = 1.0f;	
		color[2] = 0.0f;	
		color[3] = 1.0f;	
	tb->carpet=glGenLists(1);	/* only one */
	glNewList(tb->carpet,GL_COMPILE);
        tb->carpet_polys=0;
	glPushMatrix();	/* save state */
  	x=tb->carpetWidth;
  	y=tb->carpetLength;
	if (wire) { glColor3fv(color); }
	else { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); }
	/* draw carpet plane */
	glBegin( wire ? GL_LINE_LOOP : GL_QUADS );
		/* draw top */
		glNormal3f( 0, 0, -1 );
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(x,0.0,0.0);
		glVertex3f(x,y,0.0);
		glVertex3f(0.0,y,0.0);
                tb->carpet_polys++;
	    if (!wire) {
		/* add edge pieces */
		/* side 1 */
		glNormal3f( 0, -1, 0 );
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(x,0.0,0.0);
		glVertex3f(x,0,singleThick);
		glVertex3f(0.0,0,singleThick);
                tb->carpet_polys++;
		/* side 2 */
		glNormal3f( -1, 0, 0 );
		glVertex3f(0.0,0.0,0.0);
		glVertex3f(0,y,0.0);
		glVertex3f(0,y,singleThick);
		glVertex3f(0.0,0,singleThick);
                tb->carpet_polys++;
		/* side 3 */
		glNormal3f( 1, 0, 0 );
		glVertex3f(x,0.0,0.0);
		glVertex3f(x,y,0.0);
		glVertex3f(x,y,singleThick);
		glVertex3f(x,0,singleThick);
                tb->carpet_polys++;
		/* side 4 */
		glNormal3f( 0, 1, 0 );
		glVertex3f(0,y,0.0);
		glVertex3f(x,y,0.0);
		glVertex3f(x,y,singleThick);
		glVertex3f(0,y,singleThick);
                tb->carpet_polys++;
		}
	glEnd();
	/* nipples */
	if (drawNipples) {
		glTranslatef(0.5f,0.5f,-.25);			/* move to the cylinder center */
		for (c=0;c<x;c++) {
			glPushMatrix();	/* save state */
			for (i=0;i<y;i++) {
                          tb->carpet_polys += tube(0, 0, -0.1,
                                                   0, 0, 0.26,
                                                   cylSize, 0,
                                                   resolution, True, True,
                                                   wire);
                          glRotatef(180, 0.0f, 1.0f, 0.0f); /* they are upside down */
                          glRotatef(180, 0.0f, 1.0f, 0.0f); /* recover */
                          glTranslatef(0.0f,1.0f,0.0f);			/* move to the next cylinder center (backward) */
			}
			glPopMatrix();	/* save state */
			glTranslatef(1.0f,0.0f,0.0f);			/* reset   */
		}
	}
	glPopMatrix();	/* restore state */
	glEndList();	
}
Exemple #6
0
void init() {
	GLUquadricObj *quadric;
	int i, numInsts;
	GLfloat position[] = {0.0f, 25.0f, -ZOOM*0.9, 1.0f};
	GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
	GLfloat ambient[] = {0.4f, 0.4f, 0.4f};
	
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glClearDepth(1.0);
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glEnable(GL_BLEND);
	
	glLightfv(
			GL_LIGHT0, 
			GL_POSITION, 
			position
		);
	glLightfv(
			GL_LIGHT0, 
			GL_AMBIENT,  
			ambient
		);
	glLightfv(
			GL_LIGHT0, 
			GL_SPECULAR, 
			specular
		);
	
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glMateriali(GL_FRONT, GL_SHININESS, 255);
	
	sphere = glGenLists(1);
	glNewList(sphere, GL_COMPILE);
	
	quadric = gluNewQuadric();
	gluQuadricNormals(quadric, GLU_SMOOTH);
	gluQuadricTexture(quadric, GL_FALSE);
	gluSphere(quadric, RADIUS, 32, 32);
	gluDeleteQuadric(quadric);
	
	glEndList();
	
	for(i = 0; i < DROPCOUNT; ++i)
		drops[i].offset = -1;
	
	FSOUND_Init(44100, 64, FSOUND_INIT_USEDEFAULTMIDISYNTH);
	song = FMUSIC_LoadSong(SONG);
	if(song == NULL)
		song = FMUSIC_LoadSong("Obj\\" SONG);
	FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE);
	FMUSIC_SetMasterVolume(song, 256);
	
	srand(0xDEADBEEF);
	
	numInsts = FMUSIC_GetNumInstruments(song);
	instrumentOffsets = (int *) malloc(sizeof(int) * numInsts);
	for(i = 0; i < numInsts; ++i) {
		FMUSIC_SetInstCallback(song, instrumentCallback, i);
		instrumentOffsets[i] = rand() % (GRID_HEIGHT * GRID_WIDTH);
	}
	
	FMUSIC_PlaySong(song);
	
	setText("STRAYLIGHT");
}
Exemple #7
0
void DSSkybox::load(GLuint index) {

    // 原来可能已经存在天空盒,需要清空
    del();

    GLuint texture_height, texture_width;

    // 先载入纹理,将纹理编号存入 texture[]
    tinyxml2::XMLDocument doc;
    doc.LoadFile("skyboxes.xml");
    auto root = doc.FirstChildElement();
    auto item = root->FirstChildElement("skybox");
    for (; item != nullptr; item = item->NextSiblingElement()) {

        // 找到了该序号的天空盒信息
        if (item->UnsignedAttribute("id") == index) {

            texture[0] = dsLoadTextureBMP2D(
                             item->FirstChildElement("t0")->GetText(),
                             &texture_height,
                             &texture_width
                         );
            texture[1] = dsLoadTextureBMP2D(
                             item->FirstChildElement("t1")->GetText()
                         );
            texture[2] = dsLoadTextureBMP2D(
                             item->FirstChildElement("t2")->GetText()
                         );
            texture[3] = dsLoadTextureBMP2D(
                             item->FirstChildElement("t3")->GetText()
                         );
            texture[4] = dsLoadTextureBMP2D(
                             item->FirstChildElement("t4")->GetText()
                         );
            texture[5] = dsLoadTextureBMP2D(
                             item->FirstChildElement("t5")->GetText()
                         );
            item->FirstChildElement("depth")->QueryDoubleText(&depth);

            break;
        }
    }

    // 再创建显示列表
    width = 2000;
    height = width / (GLdouble)texture_width * (GLdouble)texture_height;

    GLdouble x = width / 2;

    display_list = glGenLists(1);

    glNewList(display_list, GL_COMPILE); // GL_COMPILE_AND_EXECUTE
    {
        glPushAttrib(GL_ENABLE_BIT);
        glDisable(GL_LIGHTING);

        // 地面
        glBindTexture(GL_TEXTURE_2D, texture[5]);
        glBegin(GL_QUADS);
        {
            glTexCoord2d(1, 0);
            glVertex3d(- x, - x, - depth);
            glTexCoord2d(1, 1);
            glVertex3d(x, - x, - depth);
            glTexCoord2d(0, 1);
            glVertex3d(x, x, - depth);
            glTexCoord2d(0, 0);
            glVertex3d(- x, x, - depth);
        }
        glEnd();

        // 东面
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glBegin(GL_QUADS);
        {
            glTexCoord2d(0, 0);
            glVertex3d(x, x + 1, - depth);
            glTexCoord2d(0, 1);
            glVertex3d(x, x + 1, height - depth);
            glTexCoord2d(1, 1);
            glVertex3d(x, - x - 1, height - depth);
            glTexCoord2d(1, 0);
            glVertex3d(x, - x - 1, - depth);
        }
        glEnd();

        // 西面
        glBindTexture(GL_TEXTURE_2D, texture[1]);
        glBegin(GL_QUADS);
        {
            glTexCoord2d(0, 0);
            glVertex3d(- x, - x - 1, - depth);
            glTexCoord2d(0, 1);
            glVertex3d(- x, - x - 1, height - depth);
            glTexCoord2d(1, 1);
            glVertex3d(- x, x + 1, height - depth);
            glTexCoord2d(1, 0);
            glVertex3d(- x, x + 1, - depth);
        }
        glEnd();

        // 南面
        glBindTexture(GL_TEXTURE_2D, texture[2]);
        glBegin(GL_QUADS);
        {
            glTexCoord2d(0, 0);
            glVertex3d(x + 1, - x, - depth);
            glTexCoord2d(0, 1);
            glVertex3d(x + 1, - x, height - depth);
            glTexCoord2d(1, 1);
            glVertex3d(- x - 1, - x, height - depth);
            glTexCoord2d(1, 0);
            glVertex3d(- x - 1, - x, - depth);
        }
        glEnd();

        // 北面
        glBindTexture(GL_TEXTURE_2D, texture[3]);
        glBegin(GL_QUADS);
        {
            glTexCoord2d(0, 0);
            glVertex3d(- x - 1, x, - depth);
            glTexCoord2d(0, 1);
            glVertex3d(- x - 1, x, height - depth);
            glTexCoord2d(1, 1);
            glVertex3d(x + 1, x, height - depth);
            glTexCoord2d(1, 0);
            glVertex3d(x + 1, x, - depth);
        }
        glEnd();

        // 顶面
        glBindTexture(GL_TEXTURE_2D, texture[4]);
        glBegin(GL_QUADS);
        {
            glTexCoord2d(1, 1);
            glVertex3d(- x, -x, height - depth);
            glTexCoord2d(1, 0);
            glVertex3d(x, -x, height - depth);
            glTexCoord2d(0, 0);
            glVertex3d(x, x, height - depth);
            glTexCoord2d(0, 1);
            glVertex3d(- x, x, height - depth);
        }
        glEnd();

        //glEnable(GL_LIGHTING);
        glPopAttrib();
    }
    glEndList();
}
Exemple #8
0
void CSMFRenderer::DrawSquare(RSquare& q, const vec3f& v, const CReadMap* rm, const float* hm) {
	const float d = v.flen2D() - 0.01f;
	const int xshift = GetXLOD(d, viewRadius, squareSizeX, lodDists);
	const int zshift = GetZLOD(d, viewRadius, squareSizeZ, lodDists);
	const int xlod = (1 << xshift);
	const int zlod = (1 << zshift);

	const int xverts = (squareSizeX / xlod) + 1;		// #vertices in the x-direction for this square
	const int zverts = (squareSizeZ / zlod) + 1;		// #vertices in the z-direction for this square
	const int numQuads = (xverts - 1) * (zverts - 1);	// #quads needed to cover square at wanted LOD
	const bool wantList = (xlod == 1 && zlod == 1);		// highest-LOD squares are rendered from dlists

	int vertex = 0;
	int offset = 0;


	const float r = 1.0f - (xshift * 0.1667f), g = 0.333f, b = (zshift * 0.1667f);
	glColor3f(r, g, b);


	if (q.hasDisLst && wantList) {
		// note: for deformable terrain, the list
		// would possibly need to be invalidated
		glCallList(q.disLstID);
	} else {
		if (!q.hasDisLst && wantList) {
			q.disLstID = glGenLists(1);
			glNewList(q.disLstID, GL_COMPILE);
		}

		va.Initialize();
		va.EnlargeArrays(numQuads * 4, 0, VA_SIZE_N);

		// note: LESS OR EQUAL, so that when {x, z}lod == squareSize{X, Z}
		// four vertices (two in each direction) are added instead of one
		for (int x = 0; x <= squareSizeX; x += xlod) {
			for (int z = 0; z <= squareSizeZ; z += zlod) {
				vec3f tl(q.tlp.x + x, 0.0f, q.tlp.z + z); tl.y = GetHeight(hm, tl.x, tl.z);
				vec3f nv = GetVertexNormal(hm, q, tl, rm->maxxpos, rm->maxzpos, x, xlod, z, zlod);

				va.AddVertexN(tl, nv);

				// the bottom- and right-most row and column
				// of vertices do not define any new quads
				// if ((x < squareSizeX && z < squareSizeZ)) {
				if (!(x & squareSizeX) && !(z & squareSizeZ)) {
					indices[offset++] = vertex + 0;          // tl
					indices[offset++] = vertex + zverts;     // tr
					indices[offset++] = vertex + zverts + 1; // br
					indices[offset++] = vertex + 1;          // bl
				}

				vertex++;
			}
		}

		/// FIXME: add indexed drawing to VA class
		/// va.Draw(numQuads, indices);
		va.DrawArrayN(GL_QUADS);

		if (!q.hasDisLst && wantList) {
			q.hasDisLst = true;
			glEndList();
		}
	}

	glColor3f(1.0f, 1.0f, 1.0f);
}
Exemple #9
0
bool CTexturedPlane::Load(QGLContext *p_pContext, double p_dAreaRefPointLat, double p_dAreaRefPointLong)
{
 QDir Dir;
 QPixmap Pixmap;
 GeographicLib::Math::real ZXY[3];
 GLenum GLError;

 if(m_bLoaded) return(true);

 //qDebug() << "CTexturedPlane::Load";

 m_pContext = p_pContext;
 
 if(!m_bGeographic) {
   //qDebug() << "CTexturedPlane::Load not geo";
   Pixmap = QPixmap(QString(m_FileName));
   m_nTextureWidth = Pixmap.width();
   m_nTextureHeight = Pixmap.height();
   m_nTextureID = m_pContext->bindTexture(Pixmap, GL_TEXTURE_2D); // will return 0 on error, but we let the area get created anyway.
   //qDebug() << "CTexturedPlane::Load: w/h/ID=" << QString::number(m_nTextureWidth) << "/" << QString::number(m_nTextureHeight) << "/" << QString::number(m_nTextureID);
   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	  //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   }
 else {
   //qDebug() << "CTexturedPlane::Load geo";
   m_nTextureWidth = 0;
   m_nTextureHeight = 0;
   m_nTextureID = 0; }

 Recalc(p_dAreaRefPointLat, p_dAreaRefPointLong); // we need this call to compute the zero point (upper left corner) of the surface in geo coords. The computed value should be used when creating opengl objects.

 ////nDisplayListNum = 1;
 ////while(glIsList(nDisplayListNum++));
 //m_nListID = glGenLists(1); //nDisplayListNum);
 ////qDebug() << "m_nListID = " << QString::number(m_nListID);
 //GLError = glGetError(); 
 ////qDebug() << "glGetError()=" << QString::number(GLError);
 //assert(m_nListID);
 //glNewList(m_nListID, GL_COMPILE);
 //GLError = glGetError();
 ////qDebug() << "glGetError()=" << QString::number(GLError);
 //if(GLError != GL_NO_ERROR) {
 //  //qDebug() << "setting m_nListID = 0";
 //  m_nListID = 0; }
 //else {
 //  if(m_nTextureID) {
 //    glEnable(GL_TEXTURE_2D);
 //    glBindTexture(GL_TEXTURE_2D, m_nTextureID); }
 //  glBegin(GL_TRIANGLES);
 //  glColor3ub(255, 255, 255);
 //  MakeAreaTriangles();
 //  glEnd();
 //  glBindTexture(GL_TEXTURE_2D, 0);
 //  glDisable(GL_TEXTURE_2D);
 //  glEndList(); }
 
 // new way of creating lists
 m_nListID2 = glGenLists(1); //nDisplayListNum);
 //qDebug() << "m_nListID2 = " << QString::number(m_nListID2);
 GLError = glGetError(); 
 //qDebug() << "glGetError()=" << QString::number(GLError);
 assert(m_nListID2);
 glNewList(m_nListID2, GL_COMPILE);
 GLError = glGetError(); 
 //qDebug() << "glGetError()=" << QString::number(GLError);
 if(GLError != GL_NO_ERROR) m_nListID2 = 0;
 else {
   if(m_nTextureID) {
     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D, m_nTextureID);
     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); //GL_LINEAR);
     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
     //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     }
   glBegin(GL_TRIANGLES);
   glColor3ub(255, 255, 255);
   MakeAreaTriangles3();
   glEnd();
   glBindTexture(GL_TEXTURE_2D, 0);
   glDisable(GL_TEXTURE_2D);
   glEndList(); }

 m_nOutlineListID = glGenLists(1); //nDisplayListNum);
 //qDebug() << "m_nOutlineListID = " << QString::number(m_nOutlineListID);
 GLError = glGetError(); 
 //qDebug() << "glGetError()=" << QString::number(GLError);
 assert(m_nOutlineListID);
 glNewList(m_nOutlineListID, GL_COMPILE);
 GLError = glGetError(); 
 //qDebug() << "glGetError()=" << QString::number(GLError);
 if(GLError != GL_NO_ERROR) m_nOutlineListID = 0;
 
 else {
   if(!m_bGeographic) {
     // selected outline
     //glBegin(GL_LINE_LOOP);
     //glColor3ub(255, 0, 0);
     //glVertex3f(-m_fSizeXM, 0, 0);
     //glVertex3f(-m_fSizeXM, 0, m_fSizeZM);
     //glVertex3f(0, 0, m_fSizeZM);
     //glVertex3f(0, 0, 0);
     //glEnd();
     //glEndList(); 
     
     //180628
     glBegin(GL_LINE_LOOP);
     glColor3ub(255, 0, 255);
     m_pLC->Forward(m_dSurface0Lat, m_dSurface0Long, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     m_pLC->Forward(m_dSurface0Lat, m_dSurface0Long + m_fSizeLong, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     m_pLC->Forward(m_dSurface0Lat - m_fSizeLat, m_dSurface0Long + m_fSizeLong, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     m_pLC->Forward(m_dSurface0Lat - m_fSizeLat, m_dSurface0Long, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     glEnd();
     glEndList();
     
     }
   else {
     glBegin(GL_LINE_LOOP);
     glColor3ub(255, 0, 255);
     m_pLC->Forward(m_dRefPointLat, m_dRefPointLong, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     m_pLC->Forward(m_dRefPointLat, m_dRefPointLong + m_fSizeLong, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     m_pLC->Forward(m_dRefPointLat - m_fSizeLat, m_dRefPointLong + m_fSizeLong, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     m_pLC->Forward(m_dRefPointLat - m_fSizeLat, m_dRefPointLong, 0, ZXY[2], ZXY[0], ZXY[1]);
     glVertex3f(ZXY[0], ZXY[1], ZXY[2]);
     glEnd();
     glEndList(); }
   }

 m_bLoaded = (/*m_nListID && */m_nListID2 && m_nOutlineListID && (m_bGeographic || m_nTextureID));
 //qDebug() << "m_nListID/m_nListID2/m_nOutlineListID/m_bGeographic/m_nTextureID" << QString::number(m_nListID) << "/" << QString::number(m_nListID2) << "/" << QString::number(m_nOutlineListID) << "/" << QString::number(m_bGeographic) << "/" << QString::number(m_nTextureID);
 //qDebug() << "m_bLoaded = " << QString::number(m_bLoaded);

 return(m_bLoaded);
}
Exemple #10
0
WINGDIAPI BOOL GLAPIENTRY wglUseFontBitmapsA(HDC hdc, DWORD first,
					     DWORD count, DWORD listBase)
{
    int i;
    GLuint font_list;
    DWORD size;
    GLYPHMETRICS gm;
    HANDLE hBits;
    LPSTR lpBits;
    MAT2 mat;
    int  success = TRUE;
    
    if (count == 0)
	return FALSE;
    
    font_list = listBase;
    
    mat.eM11 = FixedFromDouble(1);
    mat.eM12 = FixedFromDouble(0);
    mat.eM21 = FixedFromDouble(0);
    mat.eM22 = FixedFromDouble(-1);
    
    memset(&gm,0,sizeof(gm));
    
    /*
    ** If we can't get the glyph outline, it may be because this is a fixed
    ** font.  Try processing it that way.
    */
    if( GetGlyphOutline(hdc, first, GGO_BITMAP, &gm, 0, NULL, &mat)
	== GDI_ERROR ) {
	return wglUseFontBitmaps_FX( hdc, first, count, listBase );
    }
    
    /*
    ** Otherwise process all desired characters.
    */
    for (i = 0; i < (int)count; i++) {
	DWORD err;
	
	glNewList( font_list+i, GL_COMPILE );
	
	/* allocate space for the bitmap/outline */
	size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, 
			       &gm, 0, NULL, &mat);
	if (size == GDI_ERROR) {
	    glEndList( );
	    err = GetLastError();
	    success = FALSE;
	    continue;
	}
	
	hBits  = GlobalAlloc(GHND, size+1);
	lpBits = GlobalLock(hBits);
	
	err = 
	    GetGlyphOutline(hdc,         /* handle to device context */
			    first + i,   /* character to query */
			    GGO_BITMAP,  /* format of data to return */
			    &gm,         /* ptr to structure for metrics*/
			    size,        /* size of buffer for data */
			    lpBits,      /* pointer to buffer for data */
			    &mat         /* pointer to transformation */
			    /* matrix structure */
		);
	
	if (err == GDI_ERROR) {
	    GlobalUnlock(hBits);
	    GlobalFree(hBits);
	    
	    glEndList( );
	    err = GetLastError();
	    success = FALSE;
	    continue;
	}
	
	glBitmap(gm.gmBlackBoxX,gm.gmBlackBoxY,
		 (GLfloat)-gm.gmptGlyphOrigin.x,
		 (GLfloat)gm.gmptGlyphOrigin.y,
		 (GLfloat)gm.gmCellIncX,
		 (GLfloat)gm.gmCellIncY,
		 (const GLubyte * )lpBits);
	
	GlobalUnlock(hBits);
	GlobalFree(hBits);
	
	glEndList( );
    }
    
    return success;
}
int main(int argc, char **argv) {
  carve::mesh::MeshSet<3> *a = makeCube(carve::math::Matrix::ROT(1.0, 1.0, 1.0, 1.0));
  
  std::vector<carve::mesh::MeshSet<3>::vertex_t> shape;

  for (int i = 0; i < POINTS; ++i) {
    double r = 2.0 + .4 * sin(i * 3 * M_TWOPI / POINTS) + .8 * sin(i * 5 * M_TWOPI / POINTS);
    shape.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(r * cos(i * M_TWOPI / POINTS), r * sin(i * M_TWOPI / POINTS), 0.0)));
  }
  std::vector<carve::mesh::MeshSet<3>::vertex_t *> face_verts;
  for (int i = 0; i < POINTS; ++i) {
    face_verts.push_back(&shape[i]);
  }
  std::vector<carve::mesh::MeshSet<3>::face_t *> faces;
  faces.push_back(new carve::mesh::MeshSet<3>::face_t(face_verts.begin(), face_verts.end()));

  carve::mesh::MeshSet<3> *b = new carve::mesh::MeshSet<3>(faces);

  std::list<std::pair<carve::csg::FaceClass, carve::mesh::MeshSet<3> *> > b_sliced;

  carve::csg::CSG csg;

  csg.hooks.registerHook(new carve::csg::CarveTriangulator, carve::csg::CSG::Hooks::PROCESS_OUTPUT_FACE_BIT);
  csg.sliceAndClassify(a, b, b_sliced);

  TestScene *scene = new TestScene(argc, argv, 6);

  glNewList(scene->draw_list_base + 0, GL_COMPILE);

  drawMeshSet(a, .4, .6, .8, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 1, GL_COMPILE);
  drawMeshSet(b, .8, .6, .4, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 2, GL_COMPILE);
  {
    int n = 0;
    for (std::list<std::pair<carve::csg::FaceClass, carve::mesh::MeshSet<3> *> >::iterator i = b_sliced.begin(); i != b_sliced.end(); ++i) {
      float r, g, b;
      switch ((*i).first) {
      case carve::csg::FACE_IN:             r = 0.0; g = 0.0; b = 1.0; break;
      case carve::csg::FACE_OUT:            r = 1.0; g = 0.0; b = 0.0; break;
      case carve::csg::FACE_ON_ORIENT_OUT:  r = 1.0; g = 1.0; b = 0.0; break;
      case carve::csg::FACE_ON_ORIENT_IN:   r = 0.0; g = 1.0; b = 1.0; break;
      }
      drawMeshSet((*i).second, r, g, b, 1.0);
      ++n;
    }
  }
  glEndList();

  glNewList(scene->draw_list_base + 3, GL_COMPILE);
  {
    int n = 0;
    for (std::list<std::pair<carve::csg::FaceClass, carve::mesh::MeshSet<3> *> >::iterator i = b_sliced.begin(); i != b_sliced.end(); ++i) {
      float r, g, b;
      switch ((*i).first) {
      case carve::csg::FACE_IN:             r = 0.3; g = 0.3; b = 0.7; break;
      case carve::csg::FACE_OUT:            r = 0.7; g = 0.3; b = 0.3; break;
      case carve::csg::FACE_ON_ORIENT_OUT:  r = 0.7; g = 0.7; b = 0.3; break;
      case carve::csg::FACE_ON_ORIENT_IN:   r = 0.3; g = 0.7; b = 0.7; break;
      }
      drawMeshSetWireframe((*i).second, -1, false, false);
      ++n;
    }
  }
  glEndList();

  scene->run();

  delete scene;

  return 0;
}
Exemple #12
0
/*
** This is cribbed from FX/fxwgl.c, and seems to implement support
** for bitmap fonts where the wglUseFontBitmapsA() code implements
** support for outline fonts.  In combination they hopefully give
** fairly generic support for fonts.
*/
static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar,
                                 DWORD numChars, DWORD listBase)
{
#define VERIFY(a) (void)(a)
    
    TEXTMETRIC metric;
    BITMAPINFO *dibInfo;
    HDC bitDevice;
    COLORREF tempColor;
    int i;
    
    VERIFY(GetTextMetrics(fontDevice, &metric));
    
    dibInfo = (BITMAPINFO *) calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
    dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    dibInfo->bmiHeader.biPlanes = 1;
    dibInfo->bmiHeader.biBitCount = 1;
    dibInfo->bmiHeader.biCompression = BI_RGB;
    
    bitDevice = CreateCompatibleDC(fontDevice);
    
    /* Swap fore and back colors so the bitmap has the right polarity */
    tempColor = GetBkColor(bitDevice);
    SetBkColor(bitDevice, GetTextColor(bitDevice));
    SetTextColor(bitDevice, tempColor);
    
    /* Place chars based on base line */
    VERIFY(SetTextAlign(bitDevice, TA_BASELINE) != GDI_ERROR ? 1 : 0);
    
    for(i = 0; i < (int)numChars; i++) {
	SIZE size;
	char curChar;
	int charWidth,charHeight,bmapWidth,bmapHeight,numBytes,res;
	HBITMAP bitObject;
	HGDIOBJ origBmap;
	unsigned char *bmap;
	
	curChar = (char)(i + firstChar);
	
	/* Find how high/wide this character is */
	VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size));
	
	/* Create the output bitmap */
	charWidth = size.cx;
	charHeight = size.cy;
	/* Round up to the next multiple of 32 bits */
	bmapWidth = ((charWidth + 31) / 32) * 32;   
	bmapHeight = charHeight;
	bitObject = CreateCompatibleBitmap(bitDevice,
					   bmapWidth,
					   bmapHeight);
	/* VERIFY(bitObject); */
	
	/* Assign the output bitmap to the device */
	origBmap = SelectObject(bitDevice, bitObject);
	(void) VERIFY(origBmap);
	
	VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) );
	
	/* Use our source font on the device */
	VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT)));
	
	/* Draw the character */
	VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1));
	
	/* Unselect our bmap object */
	VERIFY(SelectObject(bitDevice, origBmap));
	
	/* Convert the display dependant representation to a 1 bit deep DIB */
	numBytes = (bmapWidth * bmapHeight) / 8;
	bmap = malloc(numBytes);
	dibInfo->bmiHeader.biWidth = bmapWidth;
	dibInfo->bmiHeader.biHeight = bmapHeight;
	res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
			dibInfo,
			DIB_RGB_COLORS);
	/* VERIFY(res); */
	
	/* Create the GL object */
	glNewList(i + listBase, GL_COMPILE);
	glBitmap(bmapWidth, bmapHeight, 0.0, (GLfloat)metric.tmDescent,
		 (GLfloat)charWidth, 0.0,
		 bmap);
	glEndList();
	/* CheckGL(); */
	
	/* Destroy the bmap object */
	DeleteObject(bitObject);
	
	/* Deallocate the bitmap data */
	free(bmap);
    }
    
    /* Destroy the DC */
    VERIFY(DeleteDC(bitDevice));
    
    free(dibInfo);
    
    return TRUE;
#undef VERIFY
}
Exemple #13
0
void GLViewer::keyPressEvent(QKeyEvent * event)
{
    switch(event->key())
    {
    case Qt::Key_Up:
        {
            cameraparameters.transform.col(3)=cameraparameters.transform*Eigen::Vector4d(0,0,-cameraparameters.tspeed,1);
        }
        break;
    case Qt::Key_Down:
        {
            cameraparameters.transform.col(3)=cameraparameters.transform*Eigen::Vector4d(0,0,cameraparameters.tspeed,1);
        }
        break;
    case Qt::Key_Left:
        {
            cameraparameters.transform.col(3)=cameraparameters.transform*Eigen::Vector4d(-cameraparameters.tspeed,0,0,1);
        }
        break;
    case Qt::Key_Right:
        {
            cameraparameters.transform.col(3)=cameraparameters.transform*Eigen::Vector4d(cameraparameters.tspeed,0,0,1);
        }
        break;
    case Qt::Key_PageUp:
        {
            cameraparameters.transform.col(3)=cameraparameters.transform*Eigen::Vector4d(0,cameraparameters.tspeed,0,1);
        }
        break;
    case Qt::Key_PageDown:
        {
            cameraparameters.transform.col(3)=cameraparameters.transform*Eigen::Vector4d(0,-cameraparameters.tspeed,0,1);
        }
        break;
    case Qt::Key_W://w
        {
            cameraparameters.transform.block<3,3>(0,0)=cameraparameters.transform.block<3,3>(0,0)*Eigen::AngleAxisd(cameraparameters.rspeed*GL_PI/180.0,Eigen::Vector3d::UnitX());
        }
        break;
    case Qt::Key_S://s
        {
            cameraparameters.transform.block<3,3>(0,0)=cameraparameters.transform.block<3,3>(0,0)*Eigen::AngleAxisd(-cameraparameters.rspeed*GL_PI/180.0,Eigen::Vector3d::UnitX());
        }
        break;
    case Qt::Key_A://a
        {
            cameraparameters.transform.block<3,3>(0,0)=cameraparameters.transform.block<3,3>(0,0)*Eigen::AngleAxisd(cameraparameters.rspeed*GL_PI/180.0,Eigen::Vector3d::UnitY());
        }
        break;
    case Qt::Key_D://d
        {
            cameraparameters.transform.block<3,3>(0,0)=cameraparameters.transform.block<3,3>(0,0)*Eigen::AngleAxisd(-cameraparameters.rspeed*GL_PI/180.0,Eigen::Vector3d::UnitY());
        }
        break;
    case Qt::Key_Q://q
        {
            cameraparameters.transform.block<3,3>(0,0)=cameraparameters.transform.block<3,3>(0,0)*Eigen::AngleAxisd(cameraparameters.rspeed*GL_PI/180.0,Eigen::Vector3d::UnitZ());
        }
        break;
    case Qt::Key_E://e
        {
            cameraparameters.transform.block<3,3>(0,0)=cameraparameters.transform.block<3,3>(0,0)*Eigen::AngleAxisd(-cameraparameters.rspeed*GL_PI/180.0,Eigen::Vector3d::UnitZ());
        }
        break;
    case Qt::Key_Home:
        {
            cameraparameters.transform.setIdentity();
        }
        break;
    case Qt::Key_1:
        {
            bperspective=1;
            setProjection();
        }
        break;
    case Qt::Key_2:
        {
            bperspective=0;
            setProjection();
        }
        break;
    case Qt::Key_Equal:
        {
            if(bperspective)
            {
                cameraparameters.viewAngle+=1;
            }
            else
            {
                cameraparameters.viewheight+=1;
            }
            setProjection();
        }
        break;
    case Qt::Key_Minus:
        {
            if(bperspective)
            {
                cameraparameters.viewAngle-=1;
            }
            else
            {
                cameraparameters.viewheight-=1;
            }
            setProjection();
        }
        break;
    case Qt::Key_Period:
        {
            if(bperspective)
            {
                cameraparameters.viewAngle+=10;
            }
            else
            {
                cameraparameters.viewheight+=10;
            }
            setProjection();
        }
        break;
    case Qt::Key_Comma:
        {
            if(bperspective)
            {
                cameraparameters.viewAngle-=10;
            }
            else
            {
                cameraparameters.viewheight-=10;
            }
            setProjection();
        }
        break;
    case Qt::Key_B:
        {
            QColor color(cameraparameters.background(0)*255,cameraparameters.background(1)*255,cameraparameters.background(2)*255,cameraparameters.background(3)*255);
            color=QColorDialog::getColor(color,this);
            if(color.isValid())
            {
                cameraparameters.background(0)=color.red()/255.0;
                cameraparameters.background(1)=color.green()/255.0;
                cameraparameters.background(2)=color.blue()/255.0;
                cameraparameters.background(3)=color.alpha()/255.0;
            }
         }
        break;
	case Qt::Key_N:
		{
            QColor color(cameraparameters.lightambient[0]*255,cameraparameters.lightambient[1]*255,cameraparameters.lightambient[2]*255,cameraparameters.lightambient[3]*255);
			color=QColorDialog::getColor(color,this);
			if(color.isValid())
			{
                cameraparameters.lightambient[0]=color.red()/255.0;
                cameraparameters.lightambient[1]=color.green()/255.0;
                cameraparameters.lightambient[2]=color.blue()/255.0;
                cameraparameters.lightambient[3]=color.alpha()/255.0;
			}
		}
		break;
    case Qt::Key_O:
        {
               cameraparameters.pointsize--;
               if(cameraparameters.pointsize<1)
               {
                   cameraparameters.pointsize=1;
               }
        }
        break;
    case Qt::Key_P:
        {
            cameraparameters.pointsize++;
        }
        break;
	case Qt::Key_Delete:
		{
			int i,n=displaylist.size();
			this->makeCurrent();
			for(i=0;i<n;i++)
			{
				glNewList(displaylist[i].listid,GL_COMPILE);
				glEndList();
			}
			this->update();
		}
		break;
    }
    update();
    return;
}
Exemple #14
0
bool ModelData::FormFlippedDisplayLists() //returns opengl error enunum.
{
    unsigned int l;
    unsigned int t;
    const unsigned int listSize = 10000;//each list to be 10000 triangles big.
    unsigned int tSeamCount = 0;

    //first lets free up existing display lists if there are any
    for( l = 0; l < flippedDispLists.size(); l++)
    {
        glDeleteLists(flippedDispLists[l],1);
    }

    if(bypassDispLists)
        return true;


    flippedDispLists.push_back(glGenLists(1));
    if(flippedDispLists.at(flippedDispLists.size()-1) == 0)
        return false;//failure to allocate a list index???

    glNewList(flippedDispLists.at(flippedDispLists.size()-1),GL_COMPILE);
    glBegin(GL_TRIANGLES);// Drawing Using Triangles
    for(t = 0; t < triList.size(); t = t + 1 + displaySkipping)//for each triangle
    {

        glNormal3f(-triList[t].normal.x(),triList[t].normal.y(),triList[t].normal.z());//normals

        glVertex3f( -triList[t].vertex[2].x(), triList[t].vertex[2].y(), triList[t].vertex[2].z());
        glVertex3f( -triList[t].vertex[1].x(), triList[t].vertex[1].y(), triList[t].vertex[1].z());
        glVertex3f( -triList[t].vertex[0].x(), triList[t].vertex[0].y(), triList[t].vertex[0].z());
        //make a new seam.
        if(tSeamCount >= listSize)
        {
            glEnd();
            glEndList();
            flippedDispLists.push_back(glGenLists(1));
            if(flippedDispLists.at(flippedDispLists.size()-1) == 0)
                return false;//failure to allocate a list index???

            //when creating a seam check for graphics error
            int err = GetGLError();
            if(err)
            {
                if(err == GL_OUT_OF_MEMORY)
                {
                    displaySkipping += 10;
                    return FormFlippedDisplayLists();
                }
                else
                    return false;
            }

            glNewList(flippedDispLists.at(flippedDispLists.size()-1),GL_COMPILE);
            glBegin(GL_TRIANGLES);// Drawing Using Triangles
            tSeamCount = 0;
        }

        tSeamCount++;
    }
    glEnd();
    glEndList();

    int err = GetGLError();
    if(err)
    {
        if(err == GL_OUT_OF_MEMORY)
        {
            displaySkipping += 10;
            return FormFlippedDisplayLists();
        }
        else
            return false;
    }

    qDebug() << flippedDispLists.size() << "Flipped Display Lists created for model " << filename;


    return true;

}
ENTRYPOINT void
draw_sws (ModeInfo *mi)
{
  sws_configuration *sc = &scs[MI_SCREEN(mi)];
/*  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);*/
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int i;

  if (!sc->glx_context)
    return;

#if 0
  if (XtAppPending (app) & (XtIMTimer|XtIMAlternateInput))
    XtAppProcessEvent (app, XtIMTimer|XtIMAlternateInput);
#endif

  glDrawBuffer (GL_BACK);
  glXMakeCurrent (dpy, window, *(sc->glx_context));

  glClear (GL_COLOR_BUFFER_BIT);

  draw_stars (mi);

  glMatrixMode (GL_MODELVIEW);
  glPushMatrix ();

  if (debug_p)
    {
      int i;
      glPushMatrix ();
      if (textures_p) glDisable (GL_TEXTURE_2D);
      glLineWidth (1);
      glColor3f (0.4, 0.4, 0.4);
      glTranslatef (0,-1, 0);
      for (i = 0; i < 16; i++)
        {
          box (1, 1, 1);
          grid (1, 1, sc->char_width * sc->font_scale, sc->line_height, 0);
          glTranslatef(0, 1, 0);
        }
      if (textures_p) glEnable (GL_TEXTURE_2D);
      glPopMatrix ();
    }

  /* Scroll to current position */
  glTranslatef (0.0, sc->intra_line_scroll, 0.0);

  glColor3f (1.0, 1.0, 0.4);
  glCallList (sc->text_list);
  mi->polygon_count = sc->polygon_count;

  sc->intra_line_scroll += sc->line_height / scroll_steps;

  if (sc->intra_line_scroll >= sc->line_height)
    {
      sc->intra_line_scroll = 0;

      /* Drop the oldest line off the end. */
      if (sc->lines[0])
        free (sc->lines[0]);

      /* Scroll the contents of the lines array toward 0. */
      if (sc->total_lines > 0)
        {
          for (i = 1; i < sc->total_lines; i++)
            sc->lines[i-1] = sc->lines[i];
          sc->lines[--sc->total_lines] = 0;
        }

      /* Bring in new lines at the end. */
      get_more_lines (sc);

      if (sc->total_lines < max_lines)
        /* Oops, we ran out of text... well, insert some blank lines
           here so that new text still pulls in from the bottom of
           the screen, isntead of just appearing. */
        sc->total_lines = max_lines;

      glDeleteLists (sc->text_list, 1);
      sc->text_list = glGenLists (1);
      glNewList (sc->text_list, GL_COMPILE);
      sc->polygon_count = 0;
      glPushMatrix ();
      glScalef (sc->font_scale, sc->font_scale, sc->font_scale);
      for (i = 0; i < sc->total_lines; i++)
        {
          double fade = (fade_p ? 1.0 * i / sc->total_lines : 1.0);
          int offscreen_lines = 2;

          double x = -0.5;
          double y =  ((sc->total_lines - (i + offscreen_lines) - 1)
                       * sc->line_height);
          double xoff = 0;
          char *line = sc->lines[i];

          if (debug_p)
            {
              double xx = x * 1.4;  /* a little more to the left */
              char n[20];
              sprintf(n, "%d:", i);
              draw_string (sc, xx / sc->font_scale, y / sc->font_scale, n);
            }

          if (!line || !*line)
            continue;

          if (sc->line_thickness != 1 && !textures_p)
            {
              int max_thick_lines = MAX_THICK_LINES;
              GLfloat thinnest_line = 1.0;
              GLfloat thickest_line = sc->line_thickness;
              GLfloat range = thickest_line - thinnest_line;
              GLfloat thickness;

              int j = sc->total_lines - i - 1;

              if (j > max_thick_lines)
                thickness = thinnest_line;
              else
                thickness = (thinnest_line +
                             (range * ((max_thick_lines - j) /
                                       (GLfloat) max_thick_lines)));

              glLineWidth (thickness);
            }

          if (alignment >= 0)
            {
              int n = string_width (sc, line);
              xoff = 1.0 - (n * sc->font_scale);
            }

          if (alignment == 0)
            xoff /= 2;

          glColor3f (fade, fade, 0.5 * fade);
          draw_string (sc, (x + xoff) / sc->font_scale, y / sc->font_scale,
                       line);
          if (textures_p)
            sc->polygon_count += strlen (line);
        }
      glPopMatrix ();
      glEndList ();
    }

  glPopMatrix ();

  if (mi->fps_p) do_fps (mi);
  glFinish();
  glXSwapBuffers(dpy, window);

  sc->star_theta += star_spin;
}
Exemple #16
0
main(int argc, char *argv[])
{
    int texcomps;
    static GLfloat splane[4] = {1.f/200.f, 0.f, 0.f, .5f};
    static GLfloat rplane[4] = {0, 1.f/200.f, 0, .5f};
    static GLfloat tplane[4] = {0, 0, 1.f/200.f, .5f};
    static GLfloat lightpos[4] = {150., 150., 150., 1.f};


    glutInit(&argc, argv);
    glutInitWindowSize(winWidth, winHeight);
    if(argc > 1)
    {
	char *args = argv[1];
	GLboolean done = GL_FALSE;
	while(!done)
	{
	    switch(*args)
	    {
	    case 's': /* single buffer */
		printf("Single Buffered\n");
		dblbuf = GL_FALSE;
		break;
	    case '-': /* do nothing */
		break;
	    case 0:
		done = GL_TRUE;
		break;
	    }
	    args++;
	}
    }
    if(dblbuf)
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
    else
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH);

    (void)glutCreateWindow("volume rendering demo");
    glutDisplayFunc(redraw);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(key);

    /* Initialize OpenGL State */

    /* draw a perspective scene */
#if 0
    glMatrixMode(GL_PROJECTION);
    /* cube, 300 on a side */
    glFrustum(-150., 150., -150., 150., 300., 600.);
    glMatrixMode(GL_MODELVIEW);
    /* look at scene from (0, 0, 450) */
    gluLookAt(0., 0., 450., 0., 0., 0., 0., 1., 0.);
#else
    glMatrixMode(GL_PROJECTION);
    /* cube, 300 on a side */
    glOrtho(-150., 150., -150., 150., -150., 150.);
    glMatrixMode(GL_MODELVIEW);
#endif

    glEnable(GL_DEPTH_TEST);
#ifdef GL_EXT_texture3D
    glEnable(GL_TEXTURE_3D_EXT);
#endif

    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glEnable(GL_TEXTURE_GEN_R);

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

    glTexGenfv(GL_S, GL_OBJECT_PLANE, splane);
    glTexGenfv(GL_T, GL_OBJECT_PLANE, tplane);
    glTexGenfv(GL_R, GL_OBJECT_PLANE, rplane);

#ifdef GL_EXT_texture3D
    /* to avoid boundary problems */
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R_EXT, GL_CLAMP);
#endif

    glEnable(GL_CLIP_PLANE0);
    glEnable(GL_CLIP_PLANE1);
    glEnable(GL_CLIP_PLANE2);
    glEnable(GL_CLIP_PLANE3);
    glEnable(GL_CLIP_PLANE4);
    glEnable(GL_CLIP_PLANE5);

    glDisable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);



    tex3ddata = loadtex3d(&texwid, &texht, &texdepth, &texcomps);

    slices = texht;

#ifdef GL_EXT_texture3D
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE_ALPHA,
		    texwid, texht, texdepth,
		    0,
		    GL_RGBA, GL_UNSIGNED_BYTE, tex3ddata);
#endif

    /* make a display list containing a sphere */
    glNewList(SPHERE, GL_COMPILE);
    {
	static GLfloat lightpos[] = {150.f, 150.f, 150.f, 1.f};
	static GLfloat material[] = {1.f, .5f, 1.f, 1.f};
	GLUquadricObj *qobj = gluNewQuadric();
	glPushAttrib(GL_LIGHTING_BIT);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material);
	gluSphere(qobj, 20.f, 20, 20);
	gluDeleteQuadric(qobj);
	glPopAttrib();
    }
    glEndList();

    key('?', 0, 0); /* print usage message */

    CHECK_ERROR("end of main");

    if(!glutExtensionSupported("GL_EXT_texture3d")) {
      fprintf(stderr,
        "volume: requires OpenGL texture 3D extension to operate correctly.\n");
    }
    hasBlendColor = glutExtensionSupported("GL_EXT_blend_color");
    if(!hasBlendColor) {
      fprintf(stderr,
        "volume: needs OpenGL blend color extension to attenuate.\n");
    }

    glutMainLoop();
    return 0;             /* ANSI C requires main to return int. */
}
void FOpenGLDisplayList::Begin()
{
	glNewList(Handle, GL_COMPILE);
}
/* draw a simple diamond shape with OpenGL */
void draw_keyframe_shape(float x, float y, float xscale, float hsize, short sel, short key_type, short mode, float alpha)
{
	static GLuint displist1 = 0;
	static GLuint displist2 = 0;
	
	/* initialize 2 display lists for diamond shape - one empty, one filled */
	if (displist1 == 0) {
		displist1 = glGenLists(1);
		glNewList(displist1, GL_COMPILE);
			
		glBegin(GL_LINE_LOOP);
		glVertex2fv(_unit_diamond_shape[0]);
		glVertex2fv(_unit_diamond_shape[1]);
		glVertex2fv(_unit_diamond_shape[2]);
		glVertex2fv(_unit_diamond_shape[3]);
		glEnd();

		glEndList();
	}
	if (displist2 == 0) {
		displist2 = glGenLists(1);
		glNewList(displist2, GL_COMPILE);
			
		glBegin(GL_QUADS);
		glVertex2fv(_unit_diamond_shape[0]);
		glVertex2fv(_unit_diamond_shape[1]);
		glVertex2fv(_unit_diamond_shape[2]);
		glVertex2fv(_unit_diamond_shape[3]);
		glEnd();

		glEndList();
	}
	
	/* tweak size of keyframe shape according to type of keyframe 
	 * - 'proper' keyframes have key_type = 0, so get drawn at full size
	 */
	hsize -= 0.5f * key_type;
	
	/* adjust view transform before starting */
	glTranslatef(x, y, 0.0f);
	glScalef(1.0f / xscale * hsize, hsize, 1.0f);
	
	/* anti-aliased lines for more consistent appearance */
	glEnable(GL_LINE_SMOOTH);
	
	/* draw! */
	if (ELEM(mode, KEYFRAME_SHAPE_INSIDE, KEYFRAME_SHAPE_BOTH)) {
		float inner_col[4];
		
		/* get interior colors from theme (for selected and unselected only) */
		switch (key_type) {
			case BEZT_KEYTYPE_BREAKDOWN: /* bluish frames (default theme) */
			{
				if (sel)  UI_GetThemeColor4fv(TH_KEYTYPE_BREAKDOWN_SELECT, inner_col);
				else UI_GetThemeColor4fv(TH_KEYTYPE_BREAKDOWN, inner_col);
				break;
			}
			case BEZT_KEYTYPE_EXTREME: /* reddish frames (default theme) */
			{
				if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_EXTREME_SELECT, inner_col);
				else UI_GetThemeColor4fv(TH_KEYTYPE_EXTREME, inner_col);
				break;
			}
			case BEZT_KEYTYPE_JITTER: /* greenish frames (default theme) */
			{
				if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_JITTER_SELECT, inner_col);
				else UI_GetThemeColor4fv(TH_KEYTYPE_JITTER, inner_col);
				break;
			}
			case BEZT_KEYTYPE_KEYFRAME: /* traditional yellowish frames (default theme) */
			default:
			{
				if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_KEYFRAME_SELECT, inner_col);
				else UI_GetThemeColor4fv(TH_KEYTYPE_KEYFRAME, inner_col);
				break;
			}
		}
		
		/* NOTE: we don't use the straight alpha from the theme, or else effects such as 
		 * greying out protected/muted channels doesn't work correctly! 
		 */
		inner_col[3] *= alpha;
		glColor4fv(inner_col);
		
		/* draw the "filled in" interior poly now */
		glCallList(displist2);
	}
	
	if (ELEM(mode, KEYFRAME_SHAPE_FRAME, KEYFRAME_SHAPE_BOTH)) {
		float border_col[4];
		
		/* exterior - black frame */
		if (sel)  UI_GetThemeColor4fv(TH_KEYBORDER_SELECT, border_col);
		else  UI_GetThemeColor4fv(TH_KEYBORDER, border_col);
		
		border_col[3] *= alpha;
		glColor4fv(border_col);
		
		glCallList(displist1);
	}
	
	glDisable(GL_LINE_SMOOTH);
	
	/* restore view transform */
	glScalef(xscale / hsize, 1.0f / hsize, 1.0f);
	glTranslatef(-x, -y, 0.0f);
}
Exemple #19
0
void ElPoly::DefineSkin(int NSample){
  std::list<Weighted_point> l;
  FT shrinkfactor = 0.5;
  double *Plot  = new double[pNType()*CUBE(NSample)];
  double *Count = new double[CUBE(NSample)];
  double Thre = 10.;
  double Radius = pEdge(0)/(double)NSample;
  for(int p=0;p<pNPart();p++){
    int t = pType(p);
    int vx = (int)(pPos(p,0)/pEdge(0)*NSample);
    int vy = (int)(pPos(p,1)/pEdge(1)*NSample);
    int vz = (int)(pPos(p,2)/pEdge(2)*NSample);
    int vTot = (vz*NSample+vy)*NSample+vx;
    Plot[vTot*pNType()+t] += 1.;
  }
  double *Norm = (double *)calloc(pNType(),sizeof(double));
  for(int t=0;t<pNType();t++){
    for(int v=0;v<CUBE(NSample);v++){
      if(Norm[t] < Plot[v*pNType()+t])
	Norm[t] = Plot[v*pNType()+t];
    }
    Norm[t] = Norm[t] <= 0. ? 1. : Norm[t];
  }
  for(int vx=0;vx<NSample;vx++){
    double x = vx*pEdge(0)/(double)NSample;
    for(int vy=0;vy<NSample;vy++){
      double y = vy*pEdge(1)/(double)NSample;
      for(int vz=0;vz<NSample;vz++){
	double z = vz*pEdge(2)/(double)NSample;
	int vTot = (vz*NSample+vy)*NSample+vx;
	if(Plot[vTot*pNType()] > Thre){
	  l.push_front(Weighted_point(Bare_point(x,y,z),Radius));
	}
      }
    }
  }

  Polyhedron Polyhe;

  Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor);
  CGAL::mesh_skin_surface_3(skin_surface, Polyhe);

  //  CGAL::subdivide_skin_surface_mesh_3(skin_surface, Polyhe);

  // std::ofstream out("mesh.off");
  // out << Polyhe;

  glDeleteLists(Dr->Particles,1);
  Dr->Particles = glGenLists(1);
  glNewList(Dr->Particles,GL_COMPILE);

  // Polyhedron::Facet_iterator fcUp = Polyhe.facets_begin();
  // for(;fcUp != Polyhe.facets_end(); ++fcUp){
  //   Polyhedron::Supports_facet_halfedge = fcUp.halfedge();
  //   //Halfedge_around_facet_circulator heUp = fcUp.halfedge();
  // }

  // for (Vertex_iterator vit = Polyhe.vertices_begin();vit != Polyhe.vertices_end(); vit++){
  //   // Vector n = policy.normal(vit);
  //   // n = n/sqrt(n*n);
  //   cout << vit->point() << std::endl;
  //   Halfedge_iterator heUp = Polyhe.halfedges_begin();
  //   for(;heUp != Polyhe.halfedges_end(); ++heUp){
  //     //Polyhedron::Halfedge_handle Half = *heUp;
  //     Vertex_handle veUp = heUp->vertex();
  //     K::Point_3 pf1 = vit->point();
  //   }
  // }
  CGAL::Inverse_index<Vertex_handle> index(Polyhe.vertices_begin(),
  					   Polyhe.vertices_end());

  for(Facet_iterator fi = Polyhe.facets_begin();fi != Polyhe.facets_end(); ++fi) {
    HFC hc = fi->facet_begin();
    HFC hc_end = hc;
    Polyhedron::Vertex_handle vf1 = (*hc).vertex();
    hc++;
    Polyhedron::Vertex_handle vf2 = (*hc).vertex();
    hc++;
    Polyhedron::Vertex_handle vf3 = (*hc).vertex();
    hc++;
    K::Point_3 pf1 = vf1->point();
    K::Point_3 pf2 = vf2->point();
    K::Point_3 pf3 = vf3->point();
    Vettore v1(pf1.x(),pf1.y(),pf1.z());
    Vettore v2(pf2.x(),pf2.y(),pf2.z());
    Vettore v3(pf3.x(),pf3.y(),pf3.z());
    Vettore vN(3);
    v1.Mult(InvScaleUn);
    v2.Mult(InvScaleUn);
    v3.Mult(InvScaleUn);
    vN = (v1-v2) ^ (v3-v2);
    //if(vN.Norm() > 2.*AreaMean) continue;
    double Sfumatura = .3*Mat->Casuale();
    glColor4f(0.1,.4+Sfumatura,0.2,1.);
    //glColor4f(HueUp[p].r,HueUp[p].g,HueUp[p].b,HueUp[p].a);
    DrTria(&v1,&v2,&v3,&vN);
    glColor4f(1.,.0,0.,1.);
    DrTriaContour(&v1,&v2,&v3);


    // glPushMatrix();//Particle
    // glBegin(GL_LINES);
    // do {
    //   Polyhedron::Vertex_handle vh = (*hc).vertex();
    //   K::Point_3 pf1 = vh->point();
    //   glVertex3d(pf1.x(),pf1.y(),pf1.z());
    // } while (++hc != hc_end);
    // glEnd();
    // glPopMatrix();//Particle
  }
  
  glEndList();
  
  // Tr tr;     // 3D-Delaunay triangulation
  // C2t3 c2t3 (tr);   // 2D-complex in 3D-Delaunay triangulation

  // Surface_3 surface(sphere_function,Sphere_3(CGAL::ORIGIN, 2.)); 
  // Surface_mesh_default_criteria_3<Tr> criteria(30., 0.1,0.1); 
  // // meshing surface
  // make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag());

  // std::cout << "Final number of points: " << tr.number_of_vertices() << "\n";

  // DT dt;
  // for(int c=0;c<Gen->NChain;c++){
  //   if(CHAIN_IF_TYPE(Ch[c].Type,CHAIN_UP) )continue;
  //   Point_3<K> ChPos(pPos(c,CLat1),pPos(c,CLat2),pPos(c,CNorm));
  //   dt.insert(ChPos);
  // }
  // Face_iterator fcTr = dt.finite_faces_begin();
  // glDeleteLists(Dr->Particles,1);
  // Dr->Particles = glGenLists(1);
  // glNewList(Dr->Particles,GL_COMPILE);
  // for(;fcTr != dt.faces_end(); ++fcTr){
  //   Vertex_handle vf1 = fcTr->vertex(0),
  //     vf2 = fcTr->vertex(1),vf3 = fcTr->vertex(2);
  //   Point pf1 = vf1->point();
  //   Point pf2 = vf2->point();
  //   Point pf3 = vf3->point();
  //   Vettore v1(pf1.x() - pf2.x(),pf1.y() - pf2.y(),pf1.z()-pf2.z());
  //   Vettore v2(pf3.x() - pf2.x(),pf3.y() - pf2.y(),pf1.z()-pf2.z());
  //   Vettore vN(3);
  //   vN = v1 ^ v2;
  //   DrTira(v1,v2,v3,vN);
    
  // }
  // glEndList();
   }
Exemple #20
0
PUBLIC void
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 */
   i = DefaultScreen(dpy);
   win = RootWindow(dpy, i);

   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);
}
Exemple #21
0
void CBasicTreeSquareDrawer::DrawQuad(int x,int y)
{
    int treesX = td->treesX;
    CBasicTreeDrawer::TreeSquareStruct* tss=&td->trees[y*treesX+x];

    float3 dif;
    dif.x=camera->pos.x-(x*SQUARE_SIZE*TREE_SQUARE_SIZE + SQUARE_SIZE*TREE_SQUARE_SIZE/2);
    dif.y=0;
    dif.z=camera->pos.z-(y*SQUARE_SIZE*TREE_SQUARE_SIZE + SQUARE_SIZE*TREE_SQUARE_SIZE/2);
    float dist=dif.Length();
    dif/=dist;

    float distfactor = dist / treeDistance;

    if(distfactor < MID_TREE_DIST_FACTOR) { // midle distance trees
        tss->lastSeen=gs->frameNum;
        if(!tss->displist) {
            va=GetVertexArray();
            va->Initialize();
            va->EnlargeArrays(12*tss->trees.size(),0,VA_SIZE_T); //!alloc room for all tree vertexes
            tss->displist=glGenLists(1);

            for(std::map<int,CBasicTreeDrawer::TreeStruct>::iterator ti=tss->trees.begin(); ti!=tss->trees.end(); ++ti) {
                CBasicTreeDrawer::TreeStruct* ts=&ti->second;
                if(ts->type<8)
                    DrawTreeVertexMid1(ts->pos, false);
                else
                    DrawTreeVertexMid2(ts->pos, false);
            }
            glNewList(tss->displist,GL_COMPILE);
            va->DrawArrayT(GL_QUADS);
            glEndList();
        }
        glColor4f(1,1,1,1);
        glDisable(GL_BLEND);
        glAlphaFunc(GL_GREATER,0.5f);
        glCallList(tss->displist);
    }
    else if(distfactor < FAR_TREE_DIST_FACTOR) { // far trees
        tss->lastSeenFar=gs->frameNum;
        if(!tss->farDisplist || dif.dot(tss->viewVector)<0.97f) {
            va=GetVertexArray();
            va->Initialize();
            va->EnlargeArrays(4*tss->trees.size(),0,VA_SIZE_T); //!alloc room for all tree vertexes
            tss->viewVector=dif;
            if(!tss->farDisplist)
                tss->farDisplist=glGenLists(1);
            float3 up(0,1,0);
            float3 side=up.cross(dif);

            for(std::map<int,CBasicTreeDrawer::TreeStruct>::iterator ti=tss->trees.begin(); ti!=tss->trees.end(); ++ti) {
                CBasicTreeDrawer::TreeStruct* ts=&ti->second;
                if(ts->type<8) {
                    DrawTreeVertexFar1(ts->pos, side*MAX_TREE_HEIGHT_3, false);
                } else {
                    DrawTreeVertexFar2(ts->pos, side*MAX_TREE_HEIGHT_3, false);
                }
            }
            glNewList(tss->farDisplist,GL_COMPILE);
            va->DrawArrayT(GL_QUADS);
            glEndList();
        }
        if(distfactor > FADE_TREE_DIST_FACTOR) { // faded far trees
            float trans = 1.0f - (distfactor - FADE_TREE_DIST_FACTOR) / (FAR_TREE_DIST_FACTOR - FADE_TREE_DIST_FACTOR);
            glEnable(GL_BLEND);
            glColor4f(1,1,1,trans);
            glAlphaFunc(GL_GREATER, trans / 2.0f);
        } else {
            glColor4f(1,1,1,1);
            glDisable(GL_BLEND);
            glAlphaFunc(GL_GREATER,0.5f);
        }
        glCallList(tss->farDisplist);
    }
}
Exemple #22
0
//used to generate display lists
void generateDisplayLists()
{
    treeList = glGenLists(1);
    glNewList(treeList, GL_COMPILE);
    int t;
    for(t=0; t< numTrees; t++)
    {
        int depth = rand() % 3 + 4;
        int angle = rand() % 30 + 30;
        glPushMatrix();
        glTranslated(treeLocations[t][0],-10,treeLocations[t][1]);
        tree(depth, 5,100, 0,angle);
        glPopMatrix();
    }
    glEndList();

    cathedralList = glGenLists(1);
    glNewList(cathedralList, GL_COMPILE);
    //main cathedral
    archCustom(370,-9.9,450, 6,6,1, 270, 440,75, 150, insideArchTextures);
    archCustom(-370,-9.9,450, 6,6,1, 90, 440,75, 150, insideArchTextures);
    archCustom(0,440,-300, 6,6,1, 0, 1200,0, 150, insideArchTextures);
    archCustom(0,440,825, 6,6,1, 180, 450,0, 150, insideArchTextures);

    //roof of cathedral
    archCustom(370,440,450, 6.01,6.5,1, 270, 440,0, 150, outsideArchTextures);
    archCustom(-370,440,450, 6.01,6.5,1, 90, 440,0, 150, outsideArchTextures);
    archCustom(0,440,-300, 6.01,6.5,1, 0, 1200,0, 150, outsideArchTextures);
    archCustom(0,440,825, 6.01,6.5,1, 180, 450,0, 150, outsideArchTextures);

    //TO DO: FIX OVERLAP UNDERNEATH
    //front aisles

    cube(260,204.47,-250, 1099.5,1,227.75, 15,90, outsideArchTextures[1]);
    cube(-260,204.47,-250, 1099.5,1,227.75, 15,-90, outsideArchTextures[1]);

    cube(260,204.47,820, 439.5,1,227.75, 15,90, outsideArchTextures[1]);
    cube(-260,204.47,820, 439.5,1,227.75, 15,-90, outsideArchTextures[1]);

    drawAisleCompartment(-795,150, insideArchTextures, woodTexture);
    drawAisleCompartment(-575,150, insideArchTextures, woodTexture);
    drawAisleCompartment(-355,150, insideArchTextures, woodTexture);
    drawAisleCompartment(-135,150, insideArchTextures, woodTexture);
    drawAisleCompartment(85,150, insideArchTextures, woodTexture);

    //back aisles

    drawAisleCompartment(605,150, insideArchTextures, woodTexture);
    drawAisleCompartment(825,150, insideArchTextures, woodTexture);

    //doors on crossing
    aboveArch(-260, -10, 300, 4,2,1, 180, 55,35, 2.5, insideArchTextures);
    aboveArch(-480, -10, 300, 4,2,1, 180, 55,35, 2.5, insideArchTextures);
    door(-480, -10, 300, 4,2,1, 180, 55, woodTexture);

    aboveArch(260, -10, 300, 4,2,1, 180, 55,35, 2.5, insideArchTextures);
    aboveArch(480, -10, 300, 4,2,1, 180, 55,35, 2.5, insideArchTextures);
    door(480, -10, 300, 4,2,1, 180, 55, woodTexture);

    aboveArch(-260, -10, 600, 4,2,1, 0, 55,35, 2.5, insideArchTextures);
    aboveArch(-480, -10, 600, 4,2,1, 0, 55,35, 2.5, insideArchTextures);
    door(-480, -10, 600, 4,2,1, 0, 55, woodTexture);

    aboveArch(260, -10, 600, 4,2,1, 0, 55,35, 2.5, insideArchTextures);
    aboveArch(480, -10, 600, 4,2,1, 0, 55,35, 2.5, insideArchTextures);
    door(480, -10, 600, 4,2,1, 0, 55, woodTexture);

    //altar
    cube(0,-10.1,830, 300,2.5,450, 0,0, woodTexture);
    cube(0,-7.5,700, 50,10,20, 0,0, altarTexture);
    cube(0,2.5,700, 60,2.5,30, 0,0, altarTexture);

    glEndList();

    naveAisleList= glGenLists(1);
    glNewList(naveAisleList, GL_COMPILE);

    glEndList();

    towerList = glGenLists(1);
    glNewList(towerList, GL_COMPILE);
    //front towers
    tower(0,515,-900, 300,150,400,100, 0, insideArchTextures[0],outsideArchTextures[1]);
    tower(260.1,-10.1,-875, 220,500,475,150, 0, insideArchTextures[0],outsideArchTextures[1]);
    tower(-260.1,-10.1,-875, 220,500,475,150, 0, insideArchTextures[0],outsideArchTextures[1]);
    archCustom(0,-250,-900, 5,2,1, 0, 100,200, 0, insideArchTextures);
    aboveArch(0, -10, -850, 5,2,1, 0, 80,27.5, 5, insideArchTextures);
    aboveArch(0, -10, -950, 5,2,1, 180, 80,27.5, 5, insideArchTextures);
    aboveArch(0, 275, -850, 5,2,1, 0, 80,27.5, 5, insideArchTextures);
    aboveArch(0, 275, -950, 5,2,1, 180, 80,27.5, 5, insideArchTextures);
    door(0, -10, -850, 5,2,1, 0, 80, woodTexture);
    door(0, -10, -950, 5,2,1, 180, 80, woodTexture);
    //back towers
    tower(0,-10,1180, 300,675,400,250, 0, insideArchTextures[0],outsideArchTextures[1]);
    tower(260.1,-10.1,1185, 220,675,300,300, 0, insideArchTextures[0],outsideArchTextures[1]);
    tower(-260.1,-10.1,1185, 220,675,300,300, 0, insideArchTextures[0],outsideArchTextures[1]);
    //left tower
    tower(640,-10.1,450, 350,675,300,100, 90, insideArchTextures[0],outsideArchTextures[1]);
    //right tower
    tower(-640,-10.1,450, 350,675,300,100, 90, insideArchTextures[0],outsideArchTextures[1]);
    glEndList();

    pew = LoadOBJ("pew.obj");

    pewList = glGenLists(1);
    glNewList(pewList, GL_COMPILE);
    glColor4f(0.289,0.160,0.082,1);
    int pewX;
    int pewZ;
    for(pewX=35; pewX <=110; pewX += 25)
    {
        for(pewZ=-300; pewZ <= 240; pewZ +=15)
        {
            adjustList(pewX,-10,pewZ, 2,2,2, 180,pew);
            adjustList(-1*pewX,-10,pewZ, 2,2,2, 180,pew);
        }
    }
    glEndList();

    floorList = glGenLists(1);
    glNewList(floorList, GL_COMPILE);
    glColor4f(0.868,0.805,0.699,1);
    glBindTexture(GL_TEXTURE_2D, tileTexture);
    glBegin(GL_QUADS);
    glNormal3d(0,1,0);
    glTexCoord2f(0.0,0.0);
    glVertex3d(-370.0,-9.9,-950.0);
    glTexCoord2f(0.0,193.5);
    glVertex3d(-370.0,-9.9,1035.0);
    glTexCoord2f(74.0,193.5);
    glVertex3d(370.0,-9.9,1035.0);
    glTexCoord2f(74.0,0.0);
    glVertex3d(370.0,-9.9,-950.0);

    glNormal3d(0,1,0);
    glTexCoord2f(0.0,0.0);
    glVertex3d(-600.0,-9.9,300.0);
    glTexCoord2f(0.0,30.0);
    glVertex3d(-600.0,-9.9,600.0);
    glTexCoord2f(120.0, 30.0);
    glVertex3d(600.0,-9.9,600.0);
    glTexCoord2f(120.0, 0.0);
    glVertex3d(600.0,-9.9,300.0);
    glEnd();
    glEndList();

    crossList = glGenLists(1);
    glNewList(crossList, GL_COMPILE);
    cube(0,100,1000, 5,100,5, 0,0, woodTexture);
    cube(0,175,1000, 75,5,5, 0,0, woodTexture);
    glEndList();
}
Exemple #23
0
bool CFont::load(const char* fontPath)
{
  Image  image;
  int    width  = 0,
         height = 0;

  if(!image.load(fontPath))
    return Logger::writeErrorLog("Can't load font file");

  if(image.getComponentsCount() != 4)
    return Logger::writeErrorLog("RGBA image required for font");

  if(!fontTexture.load2DImage(image, GL_CLAMP, GL_CLAMP, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true))
   return Logger::writeErrorLog("Can't create font texture");

  unsigned char *data = (unsigned char*)image.getDataBuffer();

  height = image.getHeight();
  width  = image.getWidth();

  int spacey[256];
  memset(spacey, 0, 256);

  int size   = width,
      step   = size / 16;

  int x,y,i,j,k;
  for(y = 0, i = 0; y < 16; y++)
  {
    for(x = 0; x < 16; x++, i++)
    {
      unsigned char *ptr;
      spacey[i] = 0;
      for(j = 0; j < step; j++)
      {
        ptr = data + (size * y * step + x * step + j) * 4;
        for(k = 0; k < step; k++)
        {
          if(*(ptr + 3) != 0) break;
          ptr += size * 4;
        }
        if(k != step) break;
        spacey[i]++;
      }
      spaces[i] = 0;
      if(spacey[i] == step)
        continue;
      for(j = step - 1; j >= 0; j--)
      {
        ptr = data + (size * y * step + x * step + j) * 4;
        for(k = 0; k < step; k++) {
          if(*(ptr + 3) != 0) break;
          ptr += size * 4;
        }
        if(k != step) break;
        spaces[i]++;
      }
      spaces[i] = step - spacey[i] - spaces[i];
    }
  }

  if(fontBaseRange)
    glDeleteLists(fontBaseRange, 256);

  fontTexture.activate();
  fontBaseRange = glGenLists(256);

  const unsigned char spacePos=' ';
  spaces[spacePos] = step/3;

  for(y = 0, i = 0; y < 16; y++)
  {
    for(x = 0; x < 16; x++, i++)
    {
      float s = (float)x / 16.0f + (float)spacey[i] / (float)size;
      float t = (float)y / 16.0f;
      float ds = (float)spaces[i] / (float)size;
      float dt = 1.0f/ 16.0;
  
      glNewList(fontBaseRange + i,GL_COMPILE);
      glBegin(GL_TRIANGLE_STRIP);
      glTexCoord2f(s + ds,t + dt); glVertex2i(spaces[i],step);
      glTexCoord2f(s + ds,t     ); glVertex2i(spaces[i],   0);
      glTexCoord2f(s     ,t + dt); glVertex2i(0        ,step);
      glTexCoord2f(s     ,t     ); glVertex2i(0        ,   0);
      glEnd();
      glTranslatef(float(spaces[i]),0,0);
      glEndList();
    }
  }
  fontTexture.deactivate();
  fontHeight = height/16;
  

  
  return true;
}
void Inicjuj( sf::RenderWindow &app )
{
    font.loadFromFile( "fonts/comicbd.ttf" );

    std::string str( "Ladowanie textur..." );
    CStopWatch timer;

    pisz( app, str );

    const char *chTextures[ LiczbaTextur ] = {  "textures/background.tga",
                                                "textures/cross.tga",
                                                "textures/life.tga",
                                                "textures/blood.tga",
                                                "textures/enemy.tga",
                                                "textures/comet.tga",
                                                "textures/bullet.tga",
                                                "textures/award.tga" };

    GLsizei width, height;
    GLenum format, type;
    GLvoid *pixels;

    glPixelStorei(GL_UNPACK_ALIGNMENT,1);

    for ( int i = 0; i < LiczbaTextur; ++i ){

        if ( !load_targa( chTextures[i], width, height, format, type, pixels) ){
            str = "Brak pliku ";
            str += chTextures[i];
            pisz( app, str );
            while ( timer.GetElapsedSeconds() < 1.0f ){
                continue;
            }
        }

        glGenTextures(1,&t_textures[ i ]);
        glBindTexture(GL_TEXTURE_2D, t_textures[ i ]);
        gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,width,height,format,type,pixels);

        delete [] (unsigned char *)pixels;
    }

    str = "Ladowanie modeli...";
    pisz( app, str );

    load_obj( "models/award/WoodenBox02.obj", model_award );
    load_obj( "models/comet/Rock.obj", model_rock );
    load_obj( "models/bullet/bullet.obj", model_bullet );
    load_obj( "models/SpaceShip/fighter.obj", model_space_ship );

    str = "Ladowanie dzwiekow...";
    pisz( app, str );

    const char *chMusic[ LiczbaDzwiekow ] = {   "sounds/MenuBackground#1.ogg",
                                                "sounds/MenuBackground#2.ogg",
                                                "sounds/Background.ogg",
                                                "sounds/fire.ogg",
                                                "sounds/Award.ogg",
                                                "sounds/ColShipComet.ogg",
                                                "sounds/ColShipShip.ogg",
                                                "sounds/CometExplo.ogg",
                                                "sounds/lifeLost.ogg",
                                                "sounds/ShipExplo.ogg",
                                                "sounds/hit.ogg" };

    for ( int i = 0; i < LiczbaDzwiekow; ++i ){
        if ( !sounds[i].openFromFile( chMusic[i] ) ){
            str = "Brak pliku ";
            str += chMusic[i];
            pisz( app, str );
            while ( timer.GetElapsedSeconds() < 1.0f ){
                continue;
            }
        }
    }

    sounds[0].setRelativeToListener( true );
    sounds[1].setRelativeToListener( true );
    sounds[2].setRelativeToListener( true );
    sounds[3].setRelativeToListener( true );
    sounds[4].setRelativeToListener( true );
    sounds[8].setRelativeToListener( true );
    sounds[10].setRelativeToListener( true );

    sounds[2].setLoop( true );
    sounds[2].setVolume( 20 );

    sounds[9].setMinDistance( 7.0f );
    sounds[9].setAttenuation( 15.0f );
    sounds[7].setMinDistance( 7.0f );
    sounds[7].setAttenuation( 15.0f );

    sf::Listener::setGlobalVolume( 100.f );
    sf::Listener::setDirection( 0.0f, 0.0f, -1.0f );

    str = "Inicjowaie list wyswietlania...";
    pisz( app, str );

    ///Lista tla!
    list_SkyBox = glGenLists( 1 );
    glNewList( list_SkyBox, GL_COMPILE );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[0] );

        glBegin( GL_QUADS );
            ///Tyl
            glNormal3f( 0.0f, 0.0f, 1.0f );

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

        glEnd();

        glDisable( GL_TEXTURE_2D );

    glEndList();

    ///Lista celownika
    list_cross = glGenLists( 1 );
    glNewList( list_cross, GL_COMPILE );

        glColor3fv( White );

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

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[1] );

        glBegin( GL_QUADS );

            glNormal3f( 0.0f, 0.0f, 1.0f );

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

        glEnd();

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_BLEND );

    glEndList();

    ///lista zycia
    list_life = glGenLists( 1 );
    glNewList( list_life, GL_COMPILE );

        glColor3fv( White );

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

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[2] );

        glBegin( GL_QUADS );

            glNormal3f( 0.0f, 0.0f, 1.0f );

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

        glEnd();

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_BLEND );

    glEndList();

    ///lista krwi
    list_blood = glGenLists( 1 );
    glNewList( list_blood, GL_COMPILE );

        glColor3fv( White );

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

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[3] );

        glBegin( GL_QUADS );

            glNormal3f( 0.0f, 0.0f, 1.0f );

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

        glEnd();

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_BLEND );

    glEndList();

    list_dron = glGenLists( 1 );
    glNewList( list_dron, GL_COMPILE );

        glEnable( GL_LIGHTING );
        glEnable( GL_LIGHT0 );

        glEnable( GL_COLOR_MATERIAL );
        glColorMaterial( GL_FRONT, GL_AMBIENT );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[4] );

        glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
        glScalef( 0.22f, 0.22f, 0.22f );

        glCallList( model_space_ship );

        glDisable( GL_TEXTURE_2D );


        glDisable( GL_COLOR_MATERIAL );
        glDisable( GL_LIGHTING );

    glEndList();

    list_award = glGenLists( 1 );
    glNewList( list_award, GL_COMPILE );

    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, t_textures[7] );

    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );

    glEnable( GL_COLOR_MATERIAL );
    glColorMaterial( GL_FRONT, GL_AMBIENT );

    glCallList( model_award );

    glDisable( GL_COLOR_MATERIAL );
    glDisable( GL_LIGHTING );

    glDisable( GL_TEXTURE_2D );

    glEndList();

    list_rock = glGenLists( 1 );
    glNewList( list_rock, GL_COMPILE );

        glEnable( GL_LIGHTING );
        glEnable( GL_LIGHT0 );

        glEnable( GL_COLOR_MATERIAL );
        glColorMaterial( GL_FRONT, GL_AMBIENT );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[5] );

        glCallList( model_rock );

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_COLOR_MATERIAL );
        glDisable( GL_LIGHTING );

    glEndList();

    list_bullet = glGenLists( 1 );
    glNewList( list_bullet, GL_COMPILE );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[6] );

        glScaled(0.7,0.7,0.7);
        glCallList( model_bullet );

        glDisable( GL_TEXTURE_2D );

    glEndList();

    str = "Pobieranie rankingu...";
    pisz( app, str );

    if ( DownloadFile() ) {
        str = "Pobieranie zakonczone...";
    } else {
        str = "Nie udalo sie pobrac rankingu!";
    }

    pisz( app, str );

    while ( timer.GetElapsedSeconds() < 1.0f ){
        continue;
    }

    str = "Tworzenie rankingu...";
    pisz( app, str );

    std::ifstream fin( "ranking.txt" );

        if ( fin.good() ) {
            for ( int i = 0; i < 10; ++i ) {
                fin >> Top10[i].punkty;
                fin >> Top10[i].zycia;
                fin >> Top10[i].statki;
                fin >> Top10[i].nagrody_zdobyte;
                fin >> Top10[i].rozwalone_nagrody;
                fin >> Top10[i].rozbite_asteroidy;
                char ch;
                fin.get( ch );
                ch = 'p';
                while ( ch != '\n' && ch != '\r' ) {
                    fin.get( ch );
                    Top10[i].name += ch;
                }
            }
        } else {
void GenerateShape()
  {
  object = glGenLists(1);

  glNewList( object, GL_COMPILE );


  /* Assuming you are using QUADS, if not change me */
   glBegin(GL_QUADS);
		/* first side*/
		/* first level*/
   	    glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,-0.80f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-1.0f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-1.0f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.80f,0.00f); /* number 4 top right corner */
		/* second level*/
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.60f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.80f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,-0.80f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,-0.60f,0.00f); /* number 4 top right corner */
		/* Third Level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,-0.40f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.60f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.60f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.40f,0.00f); /* number 4 top right corner */
		/* fourth level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.20f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.40f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,-0.40f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,-0.20f,0.00f); /* number 4 top right corner */
		/*  fifth level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,0.0f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.20f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.20f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.0f,0.00f); /* number 4 top right corner */
		/* sixth level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.20f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,0.0f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.0f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.20f,0.00f); /* number 4 top right corner */
		/*  seventh level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,0.40f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,0.20f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,0.20f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.40f,0.00f); /* number 4 top right corner */
		/* eight level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.60f,0.0f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,0.40f,0.0f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.40f,0.00f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.60f,0.00f); /* number 4 top right corner */
		
		
		/* back of tree */
			/* first level*/
   	    glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,-0.80f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-1.0f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-1.0f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.80f,-0.20f); /* number 4 top right corner */
		/* second level*/
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.60f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.80f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,-0.80f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,-0.60f,-0.20f); /* number 4 top right corner */
		/* Third Level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,-0.40f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.60f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.60f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.40f,-0.20f); /* number 4 top right corner */
		/* fourth level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.20f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.40f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,-0.40f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,-0.20f,-0.20f); /* number 4 top right corner */
		/*  fifth level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,0.0f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.20f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.20f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.0f,-0.20f); /* number 4 top right corner */
		/* sixth level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.20f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,0.0f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.0f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.20f,-0.20f); /* number 4 top right corner */
		/*  seventh level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,0.40f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,0.20f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,0.20f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.40f,-0.20f); /* number 4 top right corner */
		/* eight level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.60f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,0.40f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.40f,-0.20f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.60f,-0.20f); /* number 4 top right corner */
		
		/* right side */
		/* 1st level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.60f,-1.0f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.60f,-0.80f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.80f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-1.0f,0.00f); /* number 4 top right corner */
		/* 2nd level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.60f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.80f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,-0.80f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,-0.60f,0.0f); /* number 4 top right corner */
		/* 3rd level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.60f,-0.40f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.60f,-0.60f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.60f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.40f,0.00f); /* number 4 top right corner */
		/* 4th level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,-0.20f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.40f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,-0.40f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,-0.20f,0.0f); /* number 4 top right corner */
		/* fifth level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.60f,0.0f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.60f,-0.20f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.20f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.0f,0.00f); /* number 4 top right corner */
		/* sixth level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.20f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,-0.0f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.0f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.20f,0.0f); /* number 4 top right corner */
		/* seventh level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.60f,0.40f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.60f,0.20f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,0.20f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.40f,0.00f); /* number 4 top right corner */
		/* eight level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.60f,0.60f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.60f,0.40f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.40f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.60f,0.0f); /* number 4 top right corner */
		
		
		/*left side */
		/* 1st level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,-1.0f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.80f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.80f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-1.0f,0.00f); /* number 4 top right corner */
		/* 2nd level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.60f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.80f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.40f,-0.80f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.40f,-0.60f,0.0f); /* number 4 top right corner */
		/* 3rd level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,-0.40f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.60f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.60f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.40f,0.00f); /* number 4 top right corner */
		/* 4th level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,-0.20f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.40f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.40f,-0.40f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.40f,-0.20f,0.0f); /* number 4 top right corner */
		/* fifth level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,0.0f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,-0.20f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.20f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.0f,0.00f); /* number 4 top right corner */
		/* sixth level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.20f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,-0.0f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.40f,0.0f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.40f,0.20f,0.0f); /* number 4 top right corner */
		/* seventh level */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.40f,0.40f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.40f,0.20f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,0.20f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.40f,0.00f); /* number 4 top right corner */
		/* eight level */
		glTexCoord2f(0.25f, 1.0f); glVertex3f(0.40f,0.60f,-0.20f); /* number 1 top leftcorner */
		glTexCoord2f(0.25f, 0.0f); glVertex3f(0.40f,0.40f,-0.20f); /* number 2 bottom left corner */
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.40f,0.40f,0.0f); /* number 3 bottm right corner */
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.40f,0.60f,0.0f); /* number 4 top right corner */
		
		/* top of tree */
/*		
		glTexCoord2f(0.25f, 1.0f); glVertex3f(-0.60f,0.80f,0.20f);  number 1 top leftcorner 
		glTexCoord2f(0.25f, 0.0f); glVertex3f(-0.60f,-0.80f,0.0f);  number 2 bottom left corner 
		glTexCoord2f(0.49f, 0.0f); glVertex3f(0.60f,0.80f,0.0f); number 3 bottm right corner 
		glTexCoord2f(0.49f, 1.0f); glVertex3f(0.60f,0.80f,0.20f);  number 4 top right corner */
		
		/* base of leaf 
		glTexCoord2f(0.50f, 1.0f); glVertex3f(0.40f,0.80f,0.0f);  number 1 top leftcorner 
		glTexCoord2f(0.50f, 0.0f); glVertex3f(0.40f,0.60f,0.0f); number 2 bottom left corner 
		glTexCoord2f(0.74f, 0.0f); glVertex3f(0.60f,0.60f,0.00f);number 3 bottm right corner 
		glTexCoord2f(0.74f, 1.0f); glVertex3f(0.60f,0.80f,0.00f);  number 4 top right corner */
		
		
		
		
		
		
		
		
		
		
		
		
		/* base cocunut */
		/*glTexCoord2f(0.75f, 1.0f); glVertex3f(0.60f,0.60f,0.0f);  number 1 top leftcorner 
		glTexCoord2f(0.75f, 0.0f); glVertex3f(0.60f,0.40f,0.0f);  number 2 bottom left corner
		glTexCoord2f(1.0f, 0.0f); glVertex3f(0.80f,0.40f,0.00f);  number 3 bottm right corner 
		glTexCoord2f(1.0f, 1.0f); glVertex3f(0.80f,0.60f,0.00f);  number 4 top right corner */
	 /* Start your code here! */
	
  glEnd( );
  glEndList( );
  }
Exemple #26
0
void createFloorToDL(void)
{
	int x, z;

	myDL = glGenLists(1);

	glNewList(myDL,GL_COMPILE);
	// Floor
	for(x=-100; x<=100; x+=2)
	{
		for(z=-100; z<=100; z+=2)
		{
			applymaterial(4);
			glBegin(GL_QUADS);
				glNormal3f(0.0, 1.0, 0.0);
				glVertex3f(x, 0.0f, z);				// Top Left
				glVertex3f(x+1.0f, 0.0f, z);		// Top Right
				glVertex3f(x+1.0f, 0.0f, z-1.0f);	// Bottom Right
				glVertex3f(x, 0.0f, z-1.0f);		// Bottom Left
			glEnd();
		}
		for(z=-99; z<=100; z+=2)
		{
			applymaterial(4);
			glBegin(GL_QUADS);
				glNormal3f(0.0f, 1.0f, 0.0f);
				glVertex3f(x, 0.0f, z);				// Top Left
				glVertex3f(x+1.0f, 0.0f, z);		// Top Right
				glVertex3f(x+1.0f, 0.0f, z-1.0f);	// Bottom Right
				glVertex3f(x, 0.0f, z-1.0f);		// Bottom Left
			glEnd();

		}
	}
	for(x=-99; x<=100; x+=2)
	{
		for(z=-99; z<=100; z+=2)
		{
			applymaterial(4);
		
			glBegin(GL_QUADS);
				glNormal3f(0.0, 1.0, 0.0);
				glVertex3f(x, 0.0f, z);				// Top Left
				glVertex3f(x+1.0f, 0.0f, z);		// Top Right
				glVertex3f(x+1.0f, 0.0f, z-1.0f);	// Bottom Right
				glVertex3f(x, 0.0f, z-1.0f);		// Bottom Left
			glEnd();
		}
		for(z=-100; z<=100; z+=2)
		{
			applymaterial(4);
			
			glBegin(GL_QUADS);
				glNormal3f(0.0f, 1.0f, 0.0f);
				glVertex3f(x, 0.0f, z);				// Top Left
				glVertex3f(x+1.0f, 0.0f, z);		// Top Right
				glVertex3f(x+1.0f, 0.0f, z-1.0f);	// Bottom Right
				glVertex3f(x, 0.0f, z-1.0f);		// Bottom Left
			glEnd();
		}
	}
	glEndList();
}
Exemple #27
0
void TTraction::Optimize()
{
    if (Global::bUseVBO)
        return;
    uiDisplayList = glGenLists(1);
    glNewList(uiDisplayList, GL_COMPILE);

    glBindTexture(GL_TEXTURE_2D, 0);
    //    glColor3ub(0,0,0); McZapkie: to do render

    //    glPushMatrix();
    //    glTranslatef(pPosition.x,pPosition.y,pPosition.z);

    if (Wires != 0)
    {
        // Dlugosc odcinka trakcji 'Winger
        double ddp = hypot(pPoint2.x - pPoint1.x, pPoint2.z - pPoint1.z);

        if (Wires == 2)
            WireOffset = 0;
        // Przewoz jezdny 1 'Marcin
        glBegin(GL_LINE_STRIP);
        glVertex3f(pPoint1.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint1.y,
                   pPoint1.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset);
        glVertex3f(pPoint2.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint2.y,
                   pPoint2.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset);
        glEnd();
        // Nie wiem co 'Marcin
        vector3 pt1, pt2, pt3, pt4, v1, v2;
        v1 = pPoint4 - pPoint3;
        v2 = pPoint2 - pPoint1;
        float step = 0;
        if (iNumSections > 0)
            step = 1.0f / (float)iNumSections;
        float f = step;
        float mid = 0.5;
        float t;

        // Przewod nosny 'Marcin
        if (Wires != 1)
        {
            glBegin(GL_LINE_STRIP);
            glVertex3f(pPoint3.x, pPoint3.y, pPoint3.z);
            for (int i = 0; i < iNumSections - 1; i++)
            {
                pt3 = pPoint3 + v1 * f;
                t = (1 - fabs(f - mid) * 2);
                if ((Wires < 4) || ((i != 0) && (i != iNumSections - 2)))
                    glVertex3f(pt3.x, pt3.y - sqrt(t) * fHeightDifference, pt3.z);
                f += step;
            }
            glVertex3f(pPoint4.x, pPoint4.y, pPoint4.z);
            glEnd();
        }

        // Drugi przewod jezdny 'Winger
        if (Wires > 2)
        {
            glBegin(GL_LINE_STRIP);
            glVertex3f(pPoint1.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint1.y,
                       pPoint1.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset);
            glVertex3f(pPoint2.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pPoint2.y,
                       pPoint2.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset);
            glEnd();
        }

        f = step;

        if (Wires == 4)
        {
            glBegin(GL_LINE_STRIP);
            glVertex3f(pPoint3.x, pPoint3.y - 0.65f * fHeightDifference, pPoint3.z);
            for (int i = 0; i < iNumSections - 1; i++)
            {
                pt3 = pPoint3 + v1 * f;
                t = (1 - fabs(f - mid) * 2);
                glVertex3f(
                    pt3.x,
                    pt3.y - sqrt(t) * fHeightDifference -
                        ((i == 0) || (i == iNumSections - 2) ? 0.25f * fHeightDifference : +0.05),
                    pt3.z);
                f += step;
            }
            glVertex3f(pPoint4.x, pPoint4.y - 0.65f * fHeightDifference, pPoint4.z);
            glEnd();
        }

        f = step;

        // Przewody pionowe (wieszaki) 'Marcin, poprawki na 2 przewody jezdne 'Winger
        if (Wires != 1)
        {
            glBegin(GL_LINES);
            for (int i = 0; i < iNumSections - 1; i++)
            {
                float flo, flo1;
                flo = (Wires == 4 ? 0.25f * fHeightDifference : 0);
                flo1 = (Wires == 4 ? +0.05 : 0);
                pt3 = pPoint3 + v1 * f;
                pt4 = pPoint1 + v2 * f;
                t = (1 - fabs(f - mid) * 2);
                if ((i % 2) == 0)
                {
                    glVertex3f(pt3.x, pt3.y - sqrt(t) * fHeightDifference -
                                          ((i == 0) || (i == iNumSections - 2) ? flo : flo1),
                               pt3.z);
                    glVertex3f(pt4.x - (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pt4.y,
                               pt4.z - (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset);
                }
                else
                {
                    glVertex3f(pt3.x, pt3.y - sqrt(t) * fHeightDifference -
                                          ((i == 0) || (i == iNumSections - 2) ? flo : flo1),
                               pt3.z);
                    glVertex3f(pt4.x + (pPoint2.z / ddp - pPoint1.z / ddp) * WireOffset, pt4.y,
                               pt4.z + (-pPoint2.x / ddp + pPoint1.x / ddp) * WireOffset);
                }
                if ((Wires == 4) && ((i == 1) || (i == iNumSections - 3)))
                {
                    glVertex3f(pt3.x, pt3.y - sqrt(t) * fHeightDifference - 0.05, pt3.z);
                    glVertex3f(pt3.x, pt3.y - sqrt(t) * fHeightDifference, pt3.z);
                }
                // endif;
                f += step;
            }
            glEnd();
        }
        glEndList();
    }
}
Exemple #28
0
int compileOBJList(struct OBJ_Model * obj)
{

	/*
	create	or replace a display list with :
	void glNewList( GLuint list, GLenum mode )
	void glEndList( void )
	where:
	list	Specifies the display-list name.

	mode	Specifies the compilation mode,	which can be
		GL_COMPILE or GL_COMPILE_AND_EXECUTE.

	  Display lists	are groups of GL commands that have been
	  stored for subsequent	execution.  Display lists are created
	  with glNewList.  All subsequent commands are placed in the
	  display list,	in the order issued, until glEndList is
	  called.

	  glNewList has	two arguments.	The first argument, list, is a
	  positive integer that	becomes	the unique name	for the
	  display list.	 Names can be created and reserved with
	  glGenLists
	*/

    glPushAttrib(GL_ALL_ATTRIB_BITS);
	long unsigned int i,j;

	//generate an empty display list, and save its id in dispList
	obj->dispList=glGenLists(1);

	glNewList(obj->dispList,GL_COMPILE);

	for(i=0; i<obj->numGroups; i++)
		{

		if (obj->matList!=0)
		 { //We might not have a material with our object!
			if( obj->matList[ obj->groups[i].material].hasTex)
			{
				if( obj->matList[ obj->groups[i].material].ldText>0)
				{
				  glEnable(GL_TEXTURE_2D);
				  glBindTexture(GL_TEXTURE_2D,  obj->matList[ obj->groups[i].material].ldText);
				}
			}
			else
			{
			  //glDisable(GL_TEXTURE_2D);
			}

            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  obj->matList[ obj->groups[i].material].ambient);
			glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  obj->matList[ obj->groups[i].material].diffuse);
			glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, obj->matList[ obj->groups[i].material].specular);

            #if DISABLE_SHININESS
			 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0 );
			#else
			 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, obj->matList[ obj->groups[i].material].shine);
            #endif

			if(  ( obj->groups[i].hasTex) ==0 )
			{
				InitAutoTex();
			}
			else
			{
				glDisable(GL_TEXTURE_GEN_S);
                glDisable(GL_TEXTURE_GEN_T);
			}
          } else
          {
              //No Matterials , No Textures
			   glDisable(GL_TEXTURE_GEN_S);
               glDisable(GL_TEXTURE_GEN_T);
               glDisable(GL_TEXTURE_2D);
          }

           doOBJDrawCallsForGroup(obj,i);


		}//FOR I
	glEndList();
glPopAttrib();
return 1;
}
Exemple #29
0
void GLBox::paintGL()
{
    glClearColor(0,0,0,255);

    glPushMatrix();
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glScalef(1.0, 1.0, 1.0);

    if (aThread)
    {
        unsigned samplesInBuffer = aThread->bufferSize;
        unsigned samplesInScale = 10000;
        unsigned samplesInvisible = samplesInBuffer - samplesInScale;
        unsigned viewLen = (unsigned)(samplesInScale/timeDiv);
        unsigned restLen = samplesInScale - viewLen;
        unsigned viewPos = (unsigned)(restLen*timeShift) + samplesInvisible/2;

        unsigned samplesToTransform = aThread->transformSize;
        unsigned samplesUntransformed = samplesInBuffer - samplesToTransform;
        unsigned transformedSamples = samplesToTransform/2;
        unsigned transformViewLen = (unsigned)(transformedSamples/timeDiv);
        unsigned transformRestLen = transformedSamples - transformViewLen;
        unsigned transformViewPos = (unsigned)(transformRestLen*timeShift);

        QString str;

        switch(viewMode)
        {
            case VIEWMODE_XT:
                aThread->bufferMutex.lock();
                for (int t = 0 ; t < MAX_CHANNELS; t++)
                {
                    if (chActive[t])
                    {
                        glNewList(gl_channels + dpIndex*MAX_CHANNELS + t, GL_COMPILE);
                        glBegin((interpolationMode == INTERPOLATION_OFF)?GL_POINTS:GL_LINE_STRIP);
                        unsigned p = aThread->triggerPoint + viewPos;
                        for (unsigned i = 0; i < viewLen; i++)
                        {
                            if (p >= samplesInBuffer)
                            {
                                p -= samplesInBuffer;
                            }
                            glVertex2f(i, aThread->buffer[p++][t]);
                        }
                        glEnd();
                        glEndList();
                    }
                }
                if (mathType != MATHTYPE_OFF)
                {
                    glNewList(gl_channels + dpIndex*MAX_CHANNELS + MAX_CHANNELS, GL_COMPILE);
                    glBegin((interpolationMode == INTERPOLATION_OFF)?GL_POINTS:GL_LINE_STRIP);
                    unsigned p = aThread->triggerPoint + viewPos;
                    for (unsigned i = 0; i < viewLen; i++)
                    {
                        if (p >= samplesInBuffer)
                        {
                            p -= samplesInBuffer;
                        }
                        int ch2Val = aThread->buffer[p][0] - VOLTAGE_SCALE/2;
                        int ch1Val = aThread->buffer[p++][1] - VOLTAGE_SCALE/2;
                        switch(mathType)
                        {
                            case MATHTYPE_1ADD2:
                                glVertex2f(i, ch1Val + ch2Val + chMOffset);
                                break;
                            case MATHTYPE_1SUB2:
                                glVertex2f(i, ch1Val - ch2Val + chMOffset);
                                break;
                            case MATHTYPE_2SUB1:
                                glVertex2f(i, ch2Val - ch1Val + chMOffset);
                                break;
                        }
                    }
                    glEnd();
                    glEndList();
                }
                aThread->bufferMutex.unlock();

                glPushMatrix();
                glTranslatef(-DIVS_TIME/2, -DIVS_VOLTAGE/2, 0);
                glScalef(DIVS_TIME*timeDiv/samplesInScale, DIVS_VOLTAGE/VOLTAGE_SCALE, 1.0);

                glEnable(GL_LINE_SMOOTH);
                glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

                for (int t = 0 ; t < MAX_CHANNELS; t++)
                {
                    if (chActive[t])
                    {
                        for (int i = (digitalPhosphor?DP_DEPTH:0); i >= 0; i--)
                        {
                            glColor4f(chColor[t][0], chColor[t][1], chColor[t][2],
                                chColor[t][3] - 0.7*log(i + 1));
                            int index = (dpIndex + i) % DP_DEPTH;
                            glCallList(gl_channels + index*MAX_CHANNELS + t);
                        }
                   }
                }
                if (mathType != MATHTYPE_OFF)
                {
                    // TODO: find error in math channel digital phosphor code
                    for (int i = (digitalPhosphor?DP_DEPTH:0); i >= 0; i--)
                    {
                        glColor4f(chColor[MAX_CHANNELS][0], chColor[MAX_CHANNELS][1],
                            chColor[MAX_CHANNELS][2], chColor[MAX_CHANNELS][3] - 0.7*log(i + 1));
                        int index = (dpIndex + i) % DP_DEPTH;
                        glCallList(gl_channels + index*MAX_CHANNELS + MAX_CHANNELS);
                    }
                }
                if (digitalPhosphor)
                {
                    if (++dpIndex >= DP_DEPTH)
                    {
                        dpIndex = 0;
                    }
                }

                glPopMatrix();
/*
                glPushMatrix();
                glColor4f(0.0, 1.0, 0.0, 1.0);
                glTranslatef(-DIVS_TIME/2, -DIVS_VOLTAGE/2, 0.0);
                str=QString("%1").arg("400ms");
                font.glString(str, 0.3);
                glPopMatrix();
*/
                glDisable(GL_LINE_SMOOTH);
		
		glLineStipple (1, 0x3333);
		for (int i = 0; i < MAX_CURSOR; ++i)
		{
		    if (cursors[i] != 0)
			cursors[i]->paintCursor(font);
		}
		
		glLineStipple (1, 0x00FF);
		glCallList(gl_grid);    // Draw grid
                break;

            case VIEWMODE_XY:
                glDisable(GL_LINE_SMOOTH);
		glLineStipple (1, 0x00FF);
                glCallList(gl_grid);
                break;

            case VIEWMODE_SPECTRUM:
                aThread->bufferMutex.lock();
                unsigned p = aThread->triggerPoint + samplesUntransformed/2;
                for (unsigned i = 0; i < samplesToTransform; i++, p++)
                {
                    if (p >= samplesInBuffer)
                    {
                        p -= samplesInBuffer;
                    }
                    for (int t = 0; t < MAX_CHANNELS; t++)
                    {
                        aThread->fhtBuffer[t][i] = (double)aThread->buffer[p][t];
                    }
                }
                aThread->transform();
                aThread->bufferMutex.unlock();

                glPushMatrix();
                glTranslatef(-DIVS_TIME/2, -DIVS_VOLTAGE/2, 0);
                glScalef(DIVS_TIME*timeDiv/transformedSamples, DIVS_VOLTAGE, 1.0);
                glLineWidth(1);
                for (int t = 0; t < MAX_CHANNELS; t++)
                {
                    glColor4f(chColor[t][0], chColor[t][1], chColor[t][2], chColor[t][3]);
                    glBegin((interpolationMode == INTERPOLATION_OFF)?GL_LINES:GL_QUADS);
                    GLfloat viewLen = transformViewLen;
                    if (interpolationMode != INTERPOLATION_OFF)
                    {
                        viewLen--;
                    }
                    for (unsigned i = 0; i < viewLen; i++)
                    {
                        glVertex2f(i, 0);
                        glVertex2f(i, aThread->fhtBuffer[t][i+transformViewPos]);
                        if (interpolationMode != INTERPOLATION_OFF)
                        {
                            glVertex2f(i+1, aThread->fhtBuffer[t][i+transformViewPos]);
                            glVertex2f(i+1, 0);
                        }
                    }
                    glEnd();
                }
                glPopMatrix();
                glDisable(GL_LINE_SMOOTH);
		glLineStipple (1, 0x00FF);
                glCallList(gl_grid);    // Draw grid
                break;
        }
    }
    glPopMatrix();
}
Exemple #30
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 ();
}