コード例 #1
0
ファイル: isosurf.c プロジェクト: Hiroyuki-Nagata/mona
int main(int argc, char **argv)
{
   GLenum type;
   char *extensions;

   GLuint arg_mode = Args(argc, argv);

   if (arg_mode & QUIT)
      exit(0);

#ifndef MONA
   read_surface( "isosurf.dat" );
#else
   read_surface( "/MESA/ISOSURF.DAT" );
#endif

   glutInitWindowPosition(0, 0);
   glutInitWindowSize(400, 400);

   type = GLUT_DEPTH;
   type |= GLUT_RGB;
   type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
   glutInitDisplayMode(type);

   if (glutCreateWindow("Isosurface") <= 0) {
      exit(0);
   }

   /* Make sure server supports the vertex array extension */
   extensions = (char *) glGetString( GL_EXTENSIONS );

   if (!strstr( extensions, "GL_EXT_vertex_array" ))
   {
      printf("Vertex arrays not supported by this renderer\n");
      allowed &= ~(LOCKED|DRAW_ARRAYS|DRAW_ELTS|ARRAY_ELT);
   }
   else if (!strstr( extensions, "GL_EXT_compiled_vertex_array" ))
   {
      printf("Compiled vertex arrays not supported by this renderer\n");
      allowed &= ~LOCKED;
   }

   Init(argc, argv);
   ModeMenu(arg_mode);

   glutCreateMenu(ModeMenu);
   glutAddMenuEntry("GL info",               GLINFO);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Lit",                   LIT);
   glutAddMenuEntry("Unlit",                 UNLIT);
   glutAddMenuEntry("Reflect",               REFLECT);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Smooth",                SHADE_SMOOTH);
   glutAddMenuEntry("Flat",                  SHADE_FLAT);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Fog",                   FOG);
   glutAddMenuEntry("No Fog",                NO_FOG);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Stipple",               STIPPLE);
   glutAddMenuEntry("No Stipple",            NO_STIPPLE);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Polygon Mode Fill",     POLYGON_FILL);
   glutAddMenuEntry("Polygon Mode Line",     POLYGON_LINE);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Point Filtered",        POINT_FILTER);
   glutAddMenuEntry("Linear Filtered",       LINEAR_FILTER);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("GL_TRIANGLES",          TRIANGLES);
   glutAddMenuEntry("GL_TRIANGLE_STRIPS",    STRIPS);
   glutAddMenuEntry("GL_POINTS",             POINTS);
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Displaylist",           DISPLAYLIST);
   glutAddMenuEntry("Immediate",             IMMEDIATE);
   glutAddMenuEntry("", 0);
   if (allowed & LOCKED) {
      glutAddMenuEntry("Locked Arrays (CVA)", LOCKED);
      glutAddMenuEntry("Unlocked Arrays",     UNLOCKED);
      glutAddMenuEntry("", 0);
   }
   glutAddMenuEntry("glVertex",               GLVERTEX);
   if (allowed & DRAW_ARRAYS) {
      glutAddMenuEntry("glDrawElements",      DRAW_ELTS);
      glutAddMenuEntry("glDrawArrays",	      DRAW_ARRAYS);
      glutAddMenuEntry("glArrayElement",      ARRAY_ELT);
   }
   glutAddMenuEntry("", 0);
   glutAddMenuEntry("Quit",                   QUIT);
   glutAttachMenu(GLUT_RIGHT_BUTTON);

   glutReshapeFunc(Reshape);
   glutKeyboardFunc(Key);
   glutSpecialFunc(SpecialKey);
   glutDisplayFunc(Display);

   glutMainLoop();
   return 0;
}
コード例 #2
0
ファイル: ac3d.c プロジェクト: chrisBGithub/unflobtactical
ACObject *ac_load_object(FILE *f, ACObject *parent)
{
    char t[20];
    ACObject *ob = NULL;

    while (!feof(f))
    {
	read_line(f);

	sscanf(buff, "%s", t);

        if (streq(t, "MATERIAL"))
	{
            float shi, tran;
            ACMaterial m;
	    
            if (get_tokens(buff, &tokc, tokv) != 22)
	    {
                printf("expected 21 params after \"MATERIAL\" - line %d\n", line);
	    }
            else
	    {
		m.name = STRING(tokv[1]);
		m.rgb.r = (float)atof(tokv[3]);
		m.rgb.g = (float)atof(tokv[4]);
		m.rgb.b = (float)atof(tokv[5]);

		m.ambient.r = (float)atof(tokv[7]);
		m.ambient.g = (float)atof(tokv[8]);
		m.ambient.b = (float)atof(tokv[9]);

		m.emissive.r = (float)atof(tokv[11]);
		m.emissive.g = (float)atof(tokv[12]);
		m.emissive.b = (float)atof(tokv[13]);

		m.specular.r = (float)atof(tokv[15]);
		m.specular.g = (float)atof(tokv[16]);
		m.specular.b = (float)atof(tokv[17]);

		m.shininess = (float)atof(tokv[19]);
		m.transparency = (float)atof(tokv[21]);

		shi = (float)atof(tokv[6]);
		tran = (float)atof(tokv[7]);

		palette[num_palette++] = m;

	    }
	}
        else
	    if (streq(t, "OBJECT"))
            {
		char type[20];
		char str[20];
		ob = new_object();

		sscanf(buff, "%s %s", str, type);
		
		ob->type = string_to_objecttype(type);
            }
	    else
		if (streq(t, "data"))
		{
		    if (get_tokens(buff, &tokc, tokv) != 2)
			printf("expected 'data <number>' at line %d\n", line);
		    else
		    {
			char *str;
			int len;

			len = atoi(tokv[1]);
			if (len > 0)
			{
			    str = (char *)myalloc(len+1);
			    fread(str, len, 1, f);
			    str[len] = 0;
			    fscanf(f, "\n"); line++;
			    ob->data = STRING(str);
			    myfree(str);
			}
		    }
		}
		else
		    if (streq(t, "name"))
		    {
			int numtok = get_tokens(buff, &tokc, tokv);
			if (numtok != 2)
			{
			    printf("expected quoted name at line %d (got %d tokens)\n", line, numtok);
			}
			else
			    ob->name = STRING(tokv[1]);
		    }
		    else
			if (streq(t, "texture"))
			{
			    if (get_tokens(buff, &tokc, tokv) != 2)
				printf("expected quoted texture name at line %d\n", line);

			    else
			    {
				//ob->texture = ac_load_texture(tokv[1]);
				ob->textureName = STRING(tokv[1]);
			    }
			}
			else
			    if (streq(t, "texrep"))
			    {
				if (get_tokens(buff, &tokc, tokv) != 3)
				    printf("expected 'texrep <float> <float>' at line %d\n", line);
				else
				{
				    ob->texture_repeat_x = (float)atof(tokv[1]);
				    ob->texture_repeat_y = (float)atof(tokv[2]);
				}
			    }
			    else
				if (streq(t, "texoff"))
				{
				    if (get_tokens(buff, &tokc, tokv) != 3)
					printf("expected 'texoff <float> <float>' at line %d\n", line);
				    else
				    {
					ob->texture_offset_x = (float)atof(tokv[1]);
					ob->texture_offset_y = (float)atof(tokv[2]);
				    }
				}
				else
				    if (streq(t, "rot"))
				    {
					float r[9];
					char str2[5];
					int n;

					sscanf(buff, "%s %f %f %f %f %f %f %f %f %f", str2, 
					       &r[0], &r[1], &r[2], &r[3], &r[4], &r[5], &r[6], &r[7], &r[8] );

					for (n = 0; n < 9; n++)
					    ob->matrix[n] = r[n];

				    }
				    else
					if (streq(t, "loc"))
					{
					    char str[5];
					    sscanf(buff, "%s %f %f %f", str,
						   &ob->loc.x, &ob->loc.y, &ob->loc.z);			
					}
					else
					    if (streq(t, "url"))
					    {
						if (get_tokens(buff, &tokc, tokv) != 2)
						    printf("expected one arg to url at line %d (got %s)\n", line, tokv[0]);
						else
						    ob->url = STRING(tokv[1]);
					    }
					    else
						if (streq(t, "numvert"))
						{
						    int num, n;
						    char str[10];

						    sscanf(buff, "%s %d", str, &num);

						    if (num > 0)
						    {
							ob->num_vert = num;
							ob->vertices = (ACVertex *)myalloc(sizeof(ACVertex)*num);

							for (n = 0; n < num; n++)
							{
							    ACVertex p;
							    fscanf(f, "%f %f %f\n", &p.x, &p.y, &p.z); line++;
							    ob->vertices[n] = p;
							}

						    }
						}
						else
						    if (streq(t, "numsurf"))
						    {
							int num, n;
							char str[10];

							sscanf(buff, "%s %d", str, &num);
							if (num > 0)
							{
							    ob->num_surf = num;
							    ob->surfaces = (ACSurface *)myalloc(sizeof(ACSurface) * num);

							    for (n = 0; n < num; n++)
							    {
								ACSurface *news = read_surface(f, &ob->surfaces[n], ob);
								if (news == NULL)
								{
								    printf("error whilst reading surface at line: %d\n", line);
								    return(NULL);
								}
						
							    }
							}
						    }
						    else
							if (streq(t, "kids")) /** 'kids' is the last token in an object **/
							{
							    int num, n;

							    sscanf(buff, "%s %d", t, &num);
			
							    if (num != 0)
							    {
								ob->kids = (ACObject **)myalloc(num * sizeof(ACObject *) );
								ob->num_kids = num;

								for (n = 0; n < num; n++)
								{
								    ACObject *k = ac_load_object(f, ob);

								    if (k == NULL)
								    {
									printf("error reading expected child object %d of %d at line: %d\n", n+1, num, line);
									return(ob);
								    }
								    else
									ob->kids[n] = k;
								}

							    }
							    return(ob);
							}

    }
    return(ob);

}