{"id":175,"date":"2010-02-23T20:42:18","date_gmt":"2010-02-23T17:42:18","guid":{"rendered":"http:\/\/goruk.hessvillage.com\/?p=175"},"modified":"2013-12-12T08:58:28","modified_gmt":"2013-12-12T05:58:28","slug":"creating-objects-manually-programmatically-using-sio2","status":"publish","type":"post","link":"http:\/\/goruk.hessvillage.com\/?p=175","title":{"rendered":"Creating Objects Manually \/ Programmatically Using SIO2Interactive"},"content":{"rendered":"<h2>How to create objects in code with SIO2Interactive<\/h2>\n<p>In the following example a material is created with a texture and a flat square with texture coordinates is created <a href=\"http:\/\/www.east-inflatables.ca\/Cheap-1016-Inflatables-Christmas\/\">Inflatables Christmas For Sale<\/a>.<\/p>\n<p><!--more--><\/p>\n<h2>Initialize A New Material<\/h2>\n<pre lang=\"cpp\">SIO2material * material;\r\nmaterial = sio2MaterialInit(\"material_name\");\r\n\r\n\/\/ Material Texture Flags\r\n\r\nmaterial-&gt;tflags[SIO2_MATERIAL_CHANNEL0] = SIO2_IMAGE_MIPMAP|SIO2_IMAGE_CLAMP;\r\n\r\n\/\/ Material Diffuse Color\r\nmaterial-&gt;diffuse-&gt;x = 1.0f;\r\nmaterial-&gt;diffuse-&gt;y = 1.0f;\r\nmaterial-&gt;diffuse-&gt;z = 1.0f;\r\nmaterial-&gt;diffuse-&gt;w = 1.0f;\r\n\r\n\/\/ Material Specular Color\r\nmaterial-&gt;specular-&gt;x = 1.0f;\r\nmaterial-&gt;specular-&gt;y = 1.0f;\r\nmaterial-&gt;specular-&gt;z = 1.0f;\r\n\r\n\/\/ Material Alpha\r\nmaterial-&gt;alpha = 1;\r\nmaterial-&gt;alvl = 0;\r\nmaterial-&gt;diffuse-&gt;w = material-&gt;alpha;\r\nmaterial-&gt;specular-&gt;w = material-&gt;alpha;\r\nmaterial-&gt;shininess = 12;\r\nmaterial-&gt;blend = 0;\r\n\r\n\/\/ Material Texture Name\r\nstrcpy(material-&gt;tname[ SIO2_MATERIAL_CHANNEL0 ], \"image_name.png\");\r\n\r\n\/\/ Material Texure Image in Channel 0\r\nmaterial-&gt;_SIO2image[SIO2_MATERIAL_CHANNEL0] = loadImage(\"image_name.png\", SIO2_IMAGE_MIPMAP|SIO2_IMAGE_CLAMP);<\/pre>\n<h2>Initialize A New Object<\/h2>\n<pre lang=\"cpp\">\r\nSIO2object * square = sio2ObjectInit(\"square\");\r\n\r\nfloat square_width = 32.0f;\r\nfloat square_height = 32.0f;\r\n\r\nsquare-&gt;dim-&gt;x = square_width;\r\nsquare-&gt;dim-&gt;y = square_height;\r\nsquare-&gt;dim-&gt;z = 0;\r\n\r\n\/\/ VBO ( See sio2ObjectBindVBO to see how these are used )\r\nsquare-&gt;vbo_offset[ SIO2_OBJECT_SIZE    ] = 80;\r\n\/\/ This is the size of all the vertex buffers ( sizeof(v_coords) + sizeof(uv_coords) ) ...\r\n\r\nsquare-&gt;vbo_offset[ SIO2_OBJECT_NORMALS ] = 0;\r\nsquare-&gt;vbo_offset[ SIO2_OBJECT_VCOLOR  ] = 0;\r\nsquare-&gt;vbo_offset[ SIO2_OBJECT_TEXUV0  ] = 48; \/\/ 0 + sizeof(v_coords) = 3*sizeof(float)*4 = 3*4*4 = 48\r\n\/\/ The position in byte offset from the beginning of the buffer for this data.\r\n\r\nsquare-&gt;vbo_offset[ SIO2_OBJECT_TEXUV1  ] = 0;\r\n\r\n\/\/ Vertex Buffer ( All data(vertices,colors,uv0,uv1,normals) except for triangle indexes is copied into this buffer )\r\nsquare-&gt;buf = (unsigned char*)malloc(square-&gt;vbo_offset[ SIO2_OBJECT_SIZE ]);\r\n\r\n\/\/ Vertices\r\nGLfloat v_coords[] = {\r\n        square_width, square_height, 0,\r\n        0, square_height, 0,\r\n        0, 0, 0,\r\n        square_width, 0, 0\r\n};\r\n\r\n\/\/ Vertex Array Goes First in the buffer.\r\nmemcpy(square-&gt;buf, v_coords, sizeof(v_coords));\r\n\r\n\/\/ UV Coords\r\nfloat uvwidth = 1.0f;\r\nfloat uvheight = 1.0f;\r\n\r\nGLfloat uv_coords[] = {\r\n        uvwidth, 0,\r\n        0, 0,\r\n        0, uvheight,\r\n        uvwidth, uvheight,\r\n};\r\n\r\n\/\/ The position depends on where you place the offsets it could be different.\r\n\/\/ In this case it is directly after the vertex array.\r\nmemcpy(square-&gt;buf + 48, uv_coords, sizeof(uv_coords));\r\n\r\n\/\/ Vertex Groups ( Only Creating One Vertex Group )\r\n\r\n\/\/ Allocate Array of Pointers 1 For Each Vertex Group\r\nsquare-&gt;n_vgroup = 1;\r\nsquare-&gt;_SIO2vertexgroup = ( SIO2vertexgroup ** ) malloc( square-&gt;n_vgroup * sizeof( SIO2vertexgroup * ) );\r\n\r\n\/\/ Init Each Vertex Group\r\nsquare-&gt;_SIO2vertexgroup[0] = sio2VertexGroupInit(\"null\");\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;mode = GL_TRIANGLES;\r\n\r\n\/\/ Set Material\r\nstrcpy(square-&gt;_SIO2vertexgroup[0]-&gt;mname, material-&gt;name);\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;_SIO2material = material;\r\n\r\n\/\/ Setup Triangle Indices(Faces)\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;n_ind = 6;\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind = ( unsigned short * ) malloc( square-&gt;_SIO2vertexgroup[0]-&gt;n_ind &lt;&lt; 1 );\r\n\/\/ The malloc here is sizeof(unsigned short)*n_ind = 6*2\r\n\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind[0] = 0;\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind[1] = 1;\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind[2] = 2;\r\n\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind[3] = 0;\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind[4] = 2;\r\nsquare-&gt;_SIO2vertexgroup[0]-&gt;ind[5] = 3;\r\n\r\n\/\/ Store The Buffers(VBO) .. Send to openGL buffers\r\nsio2ObjectGenId(square);\r\n\r\n\/\/ Store the indices .. Send to openGL buffers (GL_ELEMENT_ARRAY_BUFFER)\r\nsio2VertexGroupGenId(square-&gt;_SIO2vertexgroup[0]);\r\n\/\/ Do this more if you have more vertex groups\r\n\r\n\/\/ Set Location ( Centered in Landscape )\r\nsquare-&gt;_SIO2transform-&gt;loc-&gt;x = 240 - square_width\/2;\r\nsquare-&gt;_SIO2transform-&gt;loc-&gt;y = 160 - square_height\/2;\r\nsquare-&gt;_SIO2transform-&gt;loc-&gt;z = 0;\r\n\r\n\/\/ Bind Location as usual\r\nsio2TransformBindMatrix(square-&gt;_SIO2transform);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to create objects in code with SIO2Interactive In the following example a material is created with a texture and a flat square with texture coordinates is created Inflatables Christmas For Sale.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,8],"tags":[],"_links":{"self":[{"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=\/wp\/v2\/posts\/175"}],"collection":[{"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":9,"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":406,"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions\/406"}],"wp:attachment":[{"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/goruk.hessvillage.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}