示例#1
0
//定义纹理的函数  
void init()  
{  
    glGenTextures(3, texture); // 第一参数是需要生成标示符的个数, 第二参数是返回标示符的数组  
    texload(0, "Monet.bmp");  
    texload(1, "Crack.bmp");  
    //下面生成自定义纹理  
    drawMyTex();  
    glBindTexture(GL_TEXTURE_2D, texture[2]);  
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //设置像素存储模式控制所读取的图像数据的行对齐方式.  
    glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, image);  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大过滤,线性过滤  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//缩小过滤,线性过滤  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);//S方向重复  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);//T方向重复  
}  
示例#2
0
void Screen::setVideo(string path, int n){
    for (int i = 0; i < n; i++){
        stringstream ss;
        string str;
        ss << i;
        ss >> str;
        
        GLuint texture;
        glGenTextures(1, &texture);
        
        string texPath = path + "/" + str + ".bmp";
        
        char ch[30];
        strcpy(ch, texPath.c_str());
        texload(texture, ch);
        
        videoFrames.push_back(texture);
    }
    curFrame = 0;
}
示例#3
0
void CDocObj::change_value(CMFCPropertyGridProperty* pProp)
{
	CString name = pProp->GetName();  //被改变的参数名
	COleVariant t = pProp->GetValue(); //改变之后的值
	//m_obj->m_x += 1;
	if (name == "X")
	{
		m_obj->m_x = GLfloat(t.fltVal);
		return;
	}
	if (name == "Y")
	{
		m_obj->m_y = GLfloat(t.fltVal);
		return;
	}
	if (name == "Z")
	{
		m_obj->m_z = GLfloat(t.fltVal);
		return;
	}

	if (name == "长")
	{
		m_obj->m_l = GLfloat(t.fltVal);
		return;
	}
	if (name == "宽")
	{
		m_obj->m_w = GLfloat(t.fltVal);
		return;
	}
	if (name == "高")
	{
		m_obj->m_h = GLfloat(t.fltVal);
		return;
	}

	if (name == "X轴角度")
	{
		m_obj->m_angle_x = GLfloat(t.fltVal);
		return;
	}
	if (name == "Y轴角度")
	{
		m_obj->m_angle_y = GLfloat(t.fltVal);
		return;
	}
	if (name == "X轴角度")
	{
		m_obj->m_angle_z = GLfloat(t.fltVal);
		return;
	}
	if (name == "是否纹理")
	{
		m_whether_texture = (t.boolVal != 0);
		return;
	}
	if (name == "选择纹理文件")
	{
		m_texture_file_name = t;
		if (m_bitmapData != NULL)
		{
			delete[] m_bitmapData;
			m_bitmapData = NULL;
		}

		//M$我操你大爷,搞得这么麻烦
		//注意:以下n和len的值大小不同,n是按字符计算的,len是按字节计算的
		int n = m_texture_file_name.GetLength();    // n = 14, len = 18
		//获取宽字节字符的大小,大小是按字节计算的
		int len = WideCharToMultiByte(CP_ACP, 0, m_texture_file_name, m_texture_file_name.GetLength(), NULL, 0, NULL, NULL);
		//为多字节字符数组申请空间,数组大小为按字节计算的宽字节字节大小
		char * pFileName = new char[len + 1];  //以字节为单位
		//宽字节编码转换成多字节编码
		WideCharToMultiByte(CP_ACP, 0, m_texture_file_name, m_texture_file_name.GetLength(), pFileName, len, NULL, NULL);
		WideCharToMultiByte(CP_ACP, 0, m_texture_file_name, m_texture_file_name.GetLength() + 1, pFileName, len + 1, NULL, NULL);
		pFileName[len + 1] = 0;  //多字节字符以'/0'结束

		texload(pFileName);

		return;
	}
}
示例#4
0
bool ObjModel::loadMTL(){
    
    
    cout << "Loading MTL file " << mtlFile << endl;
    
    ObjMaterial temp_mtl;
    
    
    string filename = filePath + "/" + mtlFile;
    
    FILE* file = fopen(filename.c_str(), "r");
    
    if( file == NULL ){
        printf("Impossible to open the file !!!\n");
        return false;
    }
    
    while(true){
        
        char lineHeader[128];
        // read the first word of the line
        int res = fscanf(file, "%s", lineHeader);
        if (res == EOF)
            break; // EOF = End Of File. Quit the loop.
        
        // else : parse lineHeader
        
        
        
        if (strcmp(lineHeader, "newmtl") == 0 ){
            cout<<"new mtl"<<endl;
            if (!temp_mtl.name.empty()){
                materials[temp_mtl.name] = temp_mtl;
            }
            temp_mtl.clear();
            char ch[128];
            fscanf(file, "%s", ch);
            temp_mtl.name = ch;
        }
        else if (strcmp(lineHeader, "Kd") == 0 ){
            fscanf(file, "%f %f %f\n", &temp_mtl.diffuse[0], &temp_mtl.diffuse[1], &temp_mtl.diffuse[2]);
            temp_mtl.diffuse[3] = 1.0f;
        }
        else if (strcmp(lineHeader, "Ka") == 0){
            fscanf(file, "%f %f %f\n", &temp_mtl.ambient[0], &temp_mtl.ambient[1], &temp_mtl.ambient[2]);
            temp_mtl.ambient[3] = 1.0f;
        }
        else if (strcmp(lineHeader, "Ks") == 0 ){
            fscanf(file, "%f %f %f\n", &temp_mtl.specular[0], &temp_mtl.specular[1], &temp_mtl.specular[2]);
            temp_mtl.specular[3] = 1.0f;
        }
        else if (strcmp(lineHeader, "Ke") == 0 ){
            fscanf(file, "%f %f %f\n", &temp_mtl.emmissive[0], &temp_mtl.emmissive[1], &temp_mtl.emmissive[2]);
            temp_mtl.emmissive[3] = 1.0f;
        }
        else if (strcmp(lineHeader, "Ns") == 0 ){
            fscanf(file, "%f\n", &temp_mtl.shininess);
        }
        else if (strcmp(lineHeader, "map_Kd") == 0 ){
            char ch[128];
            fscanf(file, "%s", ch);
            GLuint texture;
            glGenTextures(1, &texture);
            temp_mtl.texture = texture;
            cout << ch << endl;
            string texPath = filePath + "/" + ch;
            strcpy(ch, texPath.c_str());
            texload(texture, ch);
        }
        else{
            // Probably a comment, eat up the rest of the line
            char stupidBuffer[1000];
            fgets(stupidBuffer, 1000, file);
        }
    }
    
    if (!temp_mtl.name.empty()){
        materials[temp_mtl.name] = temp_mtl;
    }
    
    return true;
}