int tux_material( ClientData cd, Tcl_Interp *ip, int argc, const char *argv[] ) { const char *errmsg; const char *mat_name; scalar_t diffuse[3]; scalar_t specular[3]; double spec_exp; if (5 != argc) { Tcl_AppendResult(ip, argv[0], ": invalid number of arguments\n", "Usage: ", argv[0], " <name> { <ambient colour> } " "{ <specular colour> } <specular exponent", (char *)0 ); return TCL_ERROR; } /* obtain material name */ mat_name = argv[1]; /* obtain diffuse colour */ if (TCL_OK != get_tcl_tuple(ip,argv[2],diffuse,3)) { Tcl_AppendResult(ip, argv[0], ": invalid diffuse colour", (char *)0 ); return TCL_ERROR; } /* obtain specular colour */ if (TCL_OK != get_tcl_tuple(ip,argv[3],specular,3)) { Tcl_AppendResult(ip, argv[0], ": invalid specular colour", (char *)0 ); return TCL_ERROR; } /* obtain specular exponent */ if (TCL_OK != Tcl_GetDouble(ip,argv[4],&spec_exp)) { Tcl_AppendResult(ip, argv[0], ": invalid specular exponent", (char *)0 ); return TCL_ERROR; } errmsg = create_material(mat_name,make_colour_from_array(diffuse), make_colour_from_array(specular), spec_exp); /* report error, if any */ if (errmsg) { Tcl_AppendResult(ip, argv[0], ": ", errmsg, (char *)0 ); return TCL_ERROR; } return TCL_OK; }
int main(int argc, char **argv) { std::string fileName(argv[1]); primaryOBJ = new model(fileName, verticesPerFace); //setup glut window setupGlut(argc, argv); //setup the projection and view matrices initViewport(); //initialize the cube map textures that will form our skybox initCubeMap(); // initialize the fbo for dynamic cubemapping //initDynamicCubeMap(); // standard light initialization. Relatively unchanged from the Bunny project create_lights(); //standard material initialization. Relatively unchanged from the Bunny project create_material(); teapotShader = set_shaders((char *)"phongEC"); planeShader = set_shaders((char *)"plane"); // This will read in the texture that will be applied to the teapot, if a texture is applied to the teapot at all // initTeapotTexture((char*)"textures/bubble_color.ppm"); initCircleTexture((char*)"textures/circle.tga"); // setting up the main shader for the teapot defaultShader = set_shaders((char*)"phongEC"); // setting up the shader for the skybox / cube map skyboxShader = set_shaders((char*)"skybox"); // set up the skybox geometry cube initSkyboxGeometry(); // Main loop functions glutDisplayFunc(draw_AA); glutKeyboardFunc(keyBindings); glutSpecialFunc(translateCam); glutMainLoop(); return 0; }
Primitive * create_scene(cl_uint & n_primitives) { int curr_prim = 0; Primitive * primitive_list; if (CHOOSE_SCENE == 0){ n_primitives = 17; primitive_list = (Primitive *) malloc(sizeof(Primitive) * n_primitives); memset(primitive_list, 0, sizeof(Primitive) * n_primitives); float light = 0.85f; //create_plane(create_material(r, g, b, refl, refr, refr_index, diff, spec), is_light, x, y, z, depth/radius); // floor plane primitive_list[curr_prim++] = create_plane(create_material(0.6f, 0.6f, 0.6f, 0.0f, 0.0f, 0.0f, 0.4f, 1.8f), false, 0.0f, 0.75f, 0.0f, 4.4f); // big sphere primitive_list[curr_prim++] = create_sphere(create_material(0.08f, 0.08f, 0.08f, 0.2f, 1.0f, 1.4f, 0.0f, 0.0f), false, 3.4f, -3.4f, 23.0f, 2.5f); // small sphere 5 primitive_list[curr_prim++] = create_sphere(create_material(0.07f, 0.17f, 0.07f, 0.1f, 1.0f, 1.2f, 0.0f, 0.0f), false, -0.7f, -4.90f, 27.0f, 1.0f); // small sphere primitive_list[curr_prim++] = create_sphere(create_material(1.0f, 1.0f, 1.0f, 0.8f, 0.0f, 0.0f, 0.0f, 0.0f), false, -3.4f, -3.4f, 29.0f, 2.5f); // small sphere 2 primitive_list[curr_prim++] = create_sphere(create_material(1.5f, 0.7f, 0.7f, 0.1f, 0.0f, 0.0f, 0.2f, 0.2f), false, 0.5f, -4.1f, 29.0f, 1.5f); // small sphere 3 primitive_list[curr_prim++] = create_sphere(create_material(0.7f, 0.7f, 1.7f, 0.2f, 0.0f, 0.0f, 0.2f, 0.2f), false, -6.0f, -4.1f, 32.0f, 1.5f); // small sphere 4 primitive_list[curr_prim++] = create_sphere(create_material(0.07f, 0.17f, 0.07f, 0.3f, 1.0f, 1.2f, 0.2f, 0.8f), false, -6.7f, -4.90f, 29.0f, 1.0f); // small sphere 6 up front primitive_list[curr_prim++] = create_sphere(create_material(0.08f, 0.08f, 0.08f, 0.7f, 1.0f, 1.3f, 0.8f, 0.0f), false, 6.4f, -4.9f, 18.0f, 1.0f); // left wall primitive_list[curr_prim++] = create_plane(create_material(1.0f, 0.6f, 0.6f, 0.0f, 0.0f, 0.0f, 0.8f, 1.5f), false, 0.7f, 0.0f, 0.0f, 5.4f); // right wall primitive_list[curr_prim++] = create_plane(create_material(0.7f, 0.6f, 1.0f, 0.0f, 0.0f, 0.0f, 0.8f, 0.8f), false, -0.7f, 0.0f, 0.0f, 5.4f); // top wall primitive_list[curr_prim++] = create_plane(create_material(1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.2f, 0.8f), false, 0.0f, -0.8f, 0.0f, 5.4f); // back wall primitive_list[curr_prim++] = create_plane(create_material(1.5f, 1.5f, 1.5f, 0.0f, 0.0f, 0.0f, 1.2f, 0.8f), false, 0.0f, 0.0f, -0.14f, 5.4f); // front wall primitive_list[curr_prim++] = create_plane(create_material(0.1f, 0.1f, 0.1f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f), false, 0.0f, 0.0f, 0.72f, 5.4f); // light source center primitive_list[curr_prim++] = create_sphere(create_material(light, light, light, 0.0f, 0.0f, 0.0f, 0.0f, 1.8f), true, 0.0f, 6.5f, 22.0f, 0.35f); // light source right primitive_list[curr_prim++] = create_sphere(create_material(light, light, light, 0.0f, 0.0f, 0.0f, 0.0f, 1.8f), true, -3.0f, 6.5f, 22.0f, 0.35f); // light source left primitive_list[curr_prim++] = create_sphere(create_material(light, light, light, 0.0f, 0.0f, 0.0f, 0.0f, 1.8f), true, 3.0f, 6.5f, 22.0f, 0.35f); /* // light source ground back primitive_list[curr_prim++] = create_sphere(create_material(0.85f, 0.25f, 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), false, -5.8f, -5.55f, 31.0f, 0.35f); */ }else if(CHOOSE_SCENE == 1){ n_primitives = 64; primitive_list = (Primitive *) malloc(sizeof(Primitive) * n_primitives); memset(primitive_list, 0, sizeof(Primitive) * n_primitives); //create_plane(create_material(r, g, b, refl, refr, refr_index, diff, spec), is_light, x, y, z, depth/radius); // floor plane primitive_list[curr_prim++] = create_plane(create_material(0.4f, 0.3f, 0.3f, 0.0f, 0.0f, 1.0f, 1.0f, 0.8f), false, 0.0f, 1.0f, 0.0f, 4.4f); // big sphere primitive_list[curr_prim++] = create_sphere(create_material(0.7f, 0.7f, 1.0f, 0.0f, 1.0f, 1.3f, 0.2f, 0.8f), false, 2.0f, 0.8f, 3.0f, 2.5f); // small sphere primitive_list[curr_prim++] = create_sphere(create_material(0.7f, 0.7f, 1.0f, 0.5f, 0.0f, 1.0f, 0.1f, 0.8f), false, -5.5f, -0.5f, 7.0f, 2.0f); // light source 1 primitive_list[curr_prim++] = create_sphere(create_material(0.4f, 0.4f, 0.4f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f), true, 0.0f, 5.0f, 5.0f, 0.1f); // light source 2 primitive_list[curr_prim++] = create_sphere(create_material(0.6f, 0.6f, 0.8f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f), true, -3.0f, 5.0f, 1.0f, 0.1f); // sphere 3 primitive_list[curr_prim++] = create_sphere(create_material(1.0f, 0.4f, 0.4f, 0.5f, 0.0f, 1.0f, 0.2f, 0.8f), false, -1.5f, -3.8f, 1.0f, 1.5f); // back plane primitive_list[curr_prim++] = create_plane(create_material(0.5f, 0.3f, 0.5f, 0.0f, 0.0f, 1.0f, 0.6f, 0.0f), false, 0.4f, 0.0f, -1.0f, 12.0f); // ceiling plane primitive_list[curr_prim++] = create_plane(create_material(0.4f, 0.7f, 0.7f, 0.0f, 0.0f, 1.0f, 0.5f, 0.0f), false, 0.0f, -1.0f, 0.0f, 7.4f); for (int x = 0; x < 8; x++) for (int y = 0; y < 7; y++) { primitive_list[curr_prim++] = create_sphere(create_material(0.3f, 1.0f, 0.4f, 0.0f, 0.0f, 1.0f, 0.6f, 0.6f), false, -4.5f + x * 1.5f, -4.3f + y * 1.5f, 10.0f, 0.3f); } } return primitive_list; }
CSGShapeSpatialGizmoPlugin::CSGShapeSpatialGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/csg", Color(0.2, 0.5, 1, 0.1)); create_material("shape_material", gizmo_color); create_handle_material("handles"); }
int main() { /* Really this is for testing purposes, in no way will this be the final usage */ GFXContext context; context.major = 0; context.minor = 0; if(!gfx_init(context, GFX_ERROR_MODE_DEBUG)) { GFXError error; if(gfx_errors_peek(&error)) print_error(error); return 0; } /* Setup 2 windows */ GFXColorDepth depth; depth.redBits = 8; depth.greenBits = 8; depth.blueBits = 8; GFXWindow* window1 = gfx_window_create(NULL, 0, &depth, "Window Unos", 100, 100, 800, 600, GFX_WINDOW_RESIZABLE); GFXWindow* window2 = gfx_window_create(NULL, 0, &depth, "Window Deux", 200, 200, 800, 600, GFX_WINDOW_RESIZABLE); /* Pipeline */ GFXPipeline* pipeline = gfx_pipeline_create(); char targets[] = { 0 }; GFXViewport viewport = { 0, 0, 800, 600 }; pipeline->viewport = viewport; gfx_pipeline_target(pipeline, 1, targets); GFXPipe* bucket = gfx_pipeline_push_bucket(pipeline, 0); gfx_pipe_get_state(bucket)->render.state = GFX_STATE_DEFAULT | GFX_CLEAR_COLOR; /* Texture */ GFXTextureFormat format; format.components = 3; format.type.unpacked = GFX_UNSIGNED_BYTE; format.interpret = GFX_INTERPRET_NORMALIZED; GFXTexture* tex = gfx_texture_create(GFX_TEXTURE_2D, format, 0, 800, 600, 1); GFXTextureImage image; image.texture = tex; image.mipmap = 0; image.layer = 0; gfx_pipeline_attach(pipeline, image, GFX_COLOR_ATTACHMENT, 0); /* Post processing */ const char* vertSrc = "in ivec4 data;" "out vec2 coord;" "void main() {" "gl_Position = vec4(data.xy, 0, 1);" "coord = data.zw;" "}"; const char* fragSrcA = "in vec2 coord;" "out vec3 color;" "uniform sampler2D tex;" "void main() {" "color = vec3(1.0f) - texture(tex, coord).rgb;" "}"; const char* fragSrcB = "in vec2 coord;" "out vec3 color;" "uniform sampler2D tex;" "void main() {" "color = texture(tex, coord).rgb;" "}"; GFXShader* vert = gfx_shader_create(GFX_VERTEX_SHADER); GFXShader* frag = gfx_shader_create(GFX_FRAGMENT_SHADER); gfx_shader_set_source(vert, 1, &vertSrc, NULL); gfx_shader_set_source(frag, 1, &fragSrcA, NULL); GFXShader* shaders[] = { vert, frag }; GFXPipe* pipeA = gfx_pipeline_push_process(pipeline, window1, 0); GFXProgram* programA = gfx_pipe_process_add(pipeA->process, GFX_ALL_SHADERS, 1); gfx_program_set_attribute(programA, 0, "data"); gfx_program_link(programA, 2, shaders, 0); gfx_shader_set_source(frag, 1, &fragSrcB, NULL); GFXPipe* pipeB = gfx_pipeline_push_process(pipeline, window2, 0); GFXProgram* programB = gfx_pipe_process_add(pipeB->process, GFX_ALL_SHADERS, 1); gfx_program_set_attribute(programB, 0, "data"); gfx_program_link(programB, 2, shaders, 0); gfx_shader_free(vert); gfx_shader_free(frag); /* Property map */ GFXSampler sampler = { .minFilter = GFX_FILTER_LINEAR, .mipFilter = GFX_FILTER_NEAREST, .magFilter = GFX_FILTER_LINEAR, .maxAnisotropy = 1.0f, .lodMin = 0, .lodMax = 0, .wrapS = GFX_WRAP_REPEAT, .wrapT = GFX_WRAP_REPEAT, .wrapR = GFX_WRAP_REPEAT }; GFXPropertyMap* mapA = gfx_pipe_process_get_map(pipeA->process, 1); GFXPropertyMap* mapB = gfx_pipe_process_get_map(pipeB->process, 1); gfx_property_map_forward_named(mapA, 0, 0, 0, GFX_FRAGMENT_SHADER, "tex"); gfx_property_map_set_sampler(mapA, 0, 0, sampler); gfx_property_map_set_texture(mapA, 0, 0, tex); gfx_property_map_forward_named(mapB, 0, 0, 0, GFX_FRAGMENT_SHADER, "tex"); gfx_property_map_set_sampler_share(mapB, 0, 0, mapA, 0, 0); gfx_property_map_set_texture(mapB, 0, 0, tex); /* Mesh and material */ GFXMaterial* material = create_material(); GFXMesh* mesh = create_mesh(); /* Batch */ GFXBatch* batch = gfx_batch_create( bucket->bucket, material, mesh, 0, 0, 1, 1); gfx_batch_set_level( batch, 0, 0, 0, 1); gfx_batch_set( batch, 0, 1, 1); /* Setup a loop */ while(gfx_poll_events() && gfx_get_num_windows()) { /* Execute pipeline & swap buffers */ gfx_pipeline_execute(pipeline, 0); /* Print time */ //double time = gfx_get_time(); //gfx_set_time(0.0); //printf("%f\n", 1.0 / time); /* Print all the errors! */ GFXError error; while(gfx_errors_peek(&error)) { print_error(error); gfx_errors_pop(); } } /* Free all the things */ gfx_batch_free(batch); gfx_mesh_free(mesh); gfx_material_free(material); gfx_program_map_free(programMap); gfx_texture_free(tex); gfx_pipeline_free(pipeline); gfx_window_free(window1); gfx_window_free(window2); gfx_terminate(); return 0; }