Exemple #1
0
int			sp_loadconf_textures(t_env *e)
{
	t_texture const		tmp[sp_num_textures] = {

	TEXTURE("Porcelain.tga"),
	TEXTURE("Wall.tga"),
	TEXTURE("metal.tga"),
	};
	memcpy(&e->textures, &tmp, sizeof(tmp));
	return (0);
}
void display_gl_memory_init(struct display_gl_s* display) {
	location_t			location[] = {
		{"in_Position", 0},
		{"in_Value", 1},
		{NULL, 0}
	};
	int32 width = display->grid_width;
	int32 height = display->grid_height;
	int32 size = width * height;

	display->hex_texture = display_gl_load_texture(TEXTURE("hex.png"));

	display_gl_load_shader(&display->memory_shader, SHADER("memory.vert"), SHADER("memory.frag"), location);
	display->memory_uniform_projection_matrix = glGetUniformLocation(display->memory_shader.id, "uni_ProjectionMatrix");
	display->memory_uniform_coord = glGetUniformLocation(display->memory_shader.id, "uni_Coord");
	display->memory_uniform_color = glGetUniformLocation(display->memory_shader.id, "uni_Color");
	display->memory_uniform_texture = glGetUniformLocation(display->memory_shader.id, "uni_Texture");

	{
		float delta = 1.f / 255.f;
		float uv[] = {
			0.f, 0.f, delta, 0.f, 0.f, 1.0f, delta, 1.0f
		};
		int id = 0;
		glUseProgram(display->memory_shader.id);
		glUniform2fv(display->memory_uniform_coord, 4, uv);
		glUniform1iv(display->memory_uniform_texture, 1, &id);
		glUseProgram(0);
	}

	display->memory_vao = display_gl_create_vao();


	display->memory_vertex_buffer = display_gl_create_buffer(GL_ARRAY_BUFFER, (size + height) * 4, GL_STREAM_DRAW, NULL);
	display->memory_vertex_count = (size + height) * 4;
	display->memory_index_count = (size + height) * 6;
	display->memory_size = (size + height);
	display->memory_width = DISPLAY_CELL_SIZE * width;
	display->memory_height = DISPLAY_CELL_SIZE * height + 1;
	display->memory_stride = width;

	glBindVertexArray(display->memory_vao);
	glBindBuffer(GL_ARRAY_BUFFER, display->grid_vertex_buffer);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (const void*)0);
	glBindBuffer(GL_ARRAY_BUFFER, display->memory_vertex_buffer);
	glVertexAttribPointer(1, 1, GL_UNSIGNED_BYTE, GL_FALSE, 1, (const void*)0);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glBindVertexArray(0);
}
void display_gl_io_init(struct display_gl_s* display) {
	location_t			location[] = {
		{"in_Position", 0},
		{"in_Value", 1},
		{NULL, 0}
	};

	display->write_texture = display_gl_load_texture(TEXTURE("write.png"));
	display->read_texture = display_gl_load_texture(TEXTURE("read.png"));

	display_gl_load_shader(&display->io_shader, SHADER("io.vert"), SHADER("io.frag"), location);
	display->io_uniform_projection_matrix = glGetUniformLocation(display->io_shader.id, "uni_ProjectionMatrix");
	display->io_uniform_color = glGetUniformLocation(display->io_shader.id, "uni_Color");
	display->io_uniform_texture = glGetUniformLocation(display->io_shader.id, "uni_Texture");

	glUseProgram(display->io_shader.id);
	GLint		samplerId = 0;
	glUniform1iv(display->io_uniform_texture, 1, &samplerId);
	glUseProgram(0);

	display->io_read_buffer = (uint8*)malloc(display->memory_size * 4);
	display->io_write_buffer = (uint8*)malloc(display->memory_size * 4);
}
Exemple #4
0
void CqShaderVM::SO_ctexture1()
{
	VARFUNC;
	TEXTURE( type_color, m_pEnv->SO_ctexture1 );
}
Exemple #5
0
void CqShaderVM::SO_ftexture1()
{
	VARFUNC;
	TEXTURE( type_float, m_pEnv->SO_ftexture1 );
}
Exemple #6
0
void CqShaderVM::SO_bump1()
{
	VARFUNC;
	TEXTURE( type_point, m_pEnv->SO_bump1 );
}
void X_MODEL::Load(const char* FileName) {

	FILE *fp = NULL;
	fopen_s(&fp, FileName, "r");
	assert(fp != NULL);

	char buf[256];


	fseek(fp, SEEK_SET, 0);

	while (!feof(fp)) {

		fscanf_s(fp, "%s", buf, sizeof(buf));

		if (strcmp(buf, "template") == 0) {
			while (strcmp(buf, "}") != 0) {
				fscanf_s(fp, "%s", buf, sizeof(buf));
			}
		}

		if (strcmp(buf, "Frame") == 0) {
			NODE t_node;
			m_nodeArray.push_back(t_node);
			fscanf_s(fp, "%s", buf, sizeof(buf));
			m_nodeArray[m_nodeArray.size() - 1].nodeName = buf;
			fscanf_s(fp, "%*1s");

			fscanf_s(fp, "%s", buf, sizeof(buf));
			if (strcmp(buf, "FrameTransformMatrix") == 0) {
				fscanf_s(fp, "%s", buf, sizeof(buf));
				if (strcmp(buf, "{") == -1) {
					fscanf_s(fp, "%*1s");
				}
				float mat[16];
				for (int i = 0; i < 16; ++i) {
					fscanf_s(fp, "%f", &mat[i], sizeof(mat[i]));
					fscanf_s(fp, "%*1s");
				}
				fscanf_s(fp, "%*1s");
				
				for (int i = 0; i < 4; ++i) {
					for (int k = 0; k < 4; ++k) {
						m_nodeArray[m_nodeArray.size() - 1].nodeMat[i][k] = mat[k + (i * 4)];
					}
				}
			}

		}

		if (strcmp(buf, "Mesh") == 0) {
			fscanf_s(fp, "%s", buf, sizeof(buf));
			if (strcmp(buf, "{") == -1) {
				fscanf_s(fp, "%*1s");
			}
			unsigned int nVertics;
			fscanf_s(fp, "%u", &nVertics, sizeof(nVertics));
			fscanf_s(fp, "%s", buf, sizeof(buf));


			for (int count = 0; count < nVertics; ++count) {
				float vertices[3];

				for (int i = 0; i < 3; ++i) {
					fscanf_s(fp, "%f", &vertices[i], sizeof(vertices[i]));
					fscanf_s(fp, "%*1s");
				};
				fscanf_s(fp, "%*1s");

				VERTEX vtx;
				vtx.x = vertices[0];
				vtx.y = vertices[1];
				vtx.z = vertices[2];

				m_nodeArray[m_nodeArray.size() - 1].vertexArray.push_back(vtx);
			}

			//
			unsigned int nIndicies;
			fscanf_s(fp, "%u", &nIndicies, sizeof(nIndicies));
			fscanf_s(fp, "%1s", buf, sizeof(buf));

			for (int count = 0; count < nIndicies; ++count) {
				int indices;

				fscanf_s(fp, "%2s", buf, sizeof(buf));

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

					fscanf_s(fp, "%d", &indices, sizeof(indices));
					fscanf_s(fp, "%1s", buf, sizeof(buf));

					m_nodeArray[m_nodeArray.size() - 1].indexArray.push_back(indices);
				};
				fscanf_s(fp, "%1s", buf, sizeof(buf));

			}
		}
		else if (strcmp(buf, "MeshNormals") == 0) {
			fscanf_s(fp, "%s", buf, sizeof(buf));
			if (strcmp(buf, "{") == -1) {
				fscanf_s(fp, "%*1s");
			}

			unsigned int nNormals;
			fscanf_s(fp, "%u", &nNormals, sizeof(nNormals));
			fscanf_s(fp, "%*1s");

			for (int count = 0; count < nNormals; ++count) {
				float normals[3];

				for (int i = 0; i < 3; ++i) {
					fscanf_s(fp, "%f", &normals[i], sizeof(normals[i]));
					fscanf_s(fp, "%*1s");
				};
				fscanf_s(fp, "%*1s");

				NORMAL nor;
				nor.x = normals[0];
				nor.y = normals[1];
				nor.z = normals[2];

				m_nodeArray[m_nodeArray.size() - 1].normalArray.push_back(nor);

			}
		}
		else if (strcmp(buf, "MeshTextureCoords") == 0) {
			fscanf_s(fp, "%s", buf, sizeof(buf));
			if (strcmp(buf, "{") == -1) {
				fscanf_s(fp, "%*1s");
			}

			unsigned int nTexCoords;
			fscanf_s(fp, "%u", &nTexCoords, sizeof(nTexCoords));
			fscanf_s(fp, "%*1s");

			for (int count = 0; count < nTexCoords; ++count) {
				float texcoords[2];

				for (int i = 0; i < 2; ++i) {
					fscanf_s(fp, "%f", &texcoords[i], sizeof(texcoords[i]));
					fscanf_s(fp, "%*1s");
				};
				fscanf_s(fp, "%*1s");

				TEXCOORD tex;
				tex.u = texcoords[0];
				tex.v = texcoords[1];

				m_nodeArray[m_nodeArray.size() - 1].texcoordArray.push_back(tex);
			}


		}
		else if (strcmp(buf, "Material") == 0) {
			fscanf_s(fp, "%s", buf, sizeof(buf));
			if (strcmp(buf, "{") == -1) {
				fscanf_s(fp, "%*1s");
			}

			float diffuse[4];

			for (int i = 0; i < 4; ++i) {
				fscanf_s(fp, "%f", &diffuse[i], sizeof(diffuse[i]));
				fscanf_s(fp, "%*1s");
			};
			fscanf_s(fp, "%*1s");

			MATERIAL material;
			material.diffuse.x = diffuse[0];
			material.diffuse.y = diffuse[1];
			material.diffuse.z = diffuse[2];
			material.diffuse.w = diffuse[3];

			//shinness
			float shinness;
			fscanf_s(fp, "%f", &shinness, sizeof(shinness));
			fscanf_s(fp, "%*1s");

			material.shininess = shinness;

			//specular
			float specular[3];
			for (int i = 0; i < 3; ++i) {
				fscanf_s(fp, "%f", &specular[i], sizeof(specular[i]));
				fscanf_s(fp, "%*1s");
			};
			fscanf_s(fp, "%*1s");

			material.specular.x = specular[0];
			material.specular.y = specular[1];
			material.specular.z = specular[2];

			//ambient
			float ambient[3];
			for (int i = 0; i < 3; ++i) {
				fscanf_s(fp, "%f", &ambient[i], sizeof(ambient[i]));
				fscanf_s(fp, "%*1s");
			};
			fscanf_s(fp, "%*1s");

			material.ambient.x = ambient[0];
			material.ambient.y = ambient[1];
			material.ambient.z = ambient[2];


			fscanf_s(fp, "%s", buf, sizeof(buf));
			if (strcmp(buf, "TextureFilename") == 0) {
				fscanf_s(fp, "%s", buf, sizeof(buf));
				if (strcmp(buf, "{") == -1) {
					fscanf_s(fp, "%*1s");
				}

				fscanf_s(fp, "%s", buf, sizeof(buf));
				//material.FileName = buf;
				//std::string str = material.FileName;
				
				std::string str = buf;
				material.texFileName = str.substr(str.find_first_of('\"', 0) + 1, str.find_last_of('\"', 255) - 1);
				printf("Load Filename : %s\n", material.texFileName.c_str());
				
				TEXTURE tex;
				m_nodeArray[m_nodeArray.size() - 1].textureArray.push_back(tex);
				m_nodeArray[m_nodeArray.size() - 1].textureArray[m_nodeArray[m_nodeArray.size() - 1].textureArray.size() - 1] =  TEXTURE(material.texFileName.c_str());
				
				material.texNo = m_nodeArray[m_nodeArray.size() - 1].textureArray.size();
				GLuint addID;
				m_nodeArray[m_nodeArray.size() - 1].texID.push_back(addID);
				glGenTextures(1, (GLuint*) &m_nodeArray[m_nodeArray.size() - 1].texID[m_nodeArray[m_nodeArray.size() - 1].textureArray.size() - 1]);
				glBindTexture(GL_TEXTURE_2D, m_nodeArray[m_nodeArray.size() - 1].texID[m_nodeArray[m_nodeArray.size() - 1].textureArray.size() - 1]);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

				glEnable(GL_TEXTURE_2D);
				
				glTexImage2D(GL_TEXTURE_2D, 
					0, 
					GL_RGBA, 
					m_nodeArray[m_nodeArray.size() - 1].textureArray[m_nodeArray[m_nodeArray.size() - 1].textureArray.size() - 1].Width, m_nodeArray[m_nodeArray.size() - 1].textureArray[m_nodeArray[m_nodeArray.size() - 1].textureArray.size() - 1].Height,
					0, 
					GL_RGBA, GL_UNSIGNED_BYTE, 
					m_nodeArray[m_nodeArray.size() - 1].textureArray[m_nodeArray[m_nodeArray.size() - 1].textureArray.size() - 1].image);
				
				glDisable(GL_TEXTURE_2D);

			}
			fscanf_s(fp, "%*1s");
			fscanf_s(fp, "%*1s");

			m_nodeArray[m_nodeArray.size() - 1].materialArray.push_back(material);
		}

		//Animation

		//else if (strcmp(buf, "Animation") == 0) {
		//	fscanf_s(fp, "%*1s");
		//	fscanf_s(fp, "%s", buf, sizeof(buf));

		//	if(strcmp(buf, "AnimationKey")){
		//		unsigned int keyType;
		//		fscanf_s(fp, "%u", &keyType, sizeof(keyType));

		//		if(keyType == 0){//Rotate
		//		}
		//		else if(keyType == 1){//Scale
		//		}
		//		else if(keyType == 2){//Translate
		//		}
		//		else if (keyType == 3) {//matrix

		//		}

		//	}

		//}


	}




	fclose(fp);

}