update: 2012/05/25
reference:
Tutorial - Getting Started with the OpenGL Shading Language (GLSL)
前置準備
A. 說明:
本文章內容沿用 OpenGL: Basic Setup 所建立的專案, 來加入新的檔案.
新加入的檔案來源皆從 joshbeam.com GLSL 取得.
-------------------------------------------------------------------------------
B. 下載檔案與專案調整: (前置準備)
1. 下載檔案: glsl_lighting-1.tar.gz
2. 解壓縮後, 將所有 *.c 的檔案皆改成 *.cpp (因為我們使用 C++ 的專案),
再將 main.cpp 更名成 GLSLmain.cpp (防止專案中名稱重複).
3. 接著將所有檔案(除了 Makefile 與 README.txt), 包含 data 資料夾,
全部 copy 到專案目錄下.
a. 在專案建立一個群組: GLSL, 將剛剛 copy 到專案下的檔案全部加到群組裡.
開啓 main.cpp 檔案, 修改如下:
// main function for loading 3d models
//int main(int argc, char * argv[])
int main_forLoading3dMmodels(int argc, char * argv[])
{
....
}
c. 檢查工作目錄:
(1). 點選專案左上方的 Scheme, 選取: "Edit Scheme..."
(2). 接著, 先選取左邊的 "Run MyOpenGL Debug", 再選取右邊的: "Options":
勾選: Use Custom working directory:
/Lanli/RD/Projects/OpenGL/MyOpenGL
> OK
5. 分析專案內容:
執行 "Product" > "Analyze":
> 修正相關錯誤:
*****************************************************
a. opengl.h // line 34
message: 'GL/gl.h' file not found
修正:
#ifndef __OPENGL_H__
#define __OPENGL_H__
//@fixed for Apple:'GL/gl.h' file not found
#ifndef APPLE
#define APPLE
#endif
#ifdef APPLE
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glut.h>
#endif /* APPLE */
#endif /* __OPENGL_H__ */
*****************************************************
b. scene.cpp
// line 67
message: Assigning to 'float *' from incompatible type 'void *';
修正:
/* generate vertex data */
//@fixed: Assigning to 'float *' from incompatible type 'void *';
//v = malloc(sizeof(float) * size);
v = (float *)malloc(sizeof(float) * size);
// line 127
message: Assigning to 'char *' from incompatible type 'void *';
修正:
/* get the program info log */
glGetProgramiv(g_program, GL_INFO_LOG_LENGTH, &length);
//@fixed: Assigning to 'char *' from incompatible type 'void *';
//log = malloc(length);
log = (char *)malloc(length);
glGetProgramInfoLog(g_program, length, &result, log);
*****************************************************
c. shader.cpp
// line 53, message:
Cannot initialize a variable of type 'char *' with an rvalue of type 'void *'
修正:
/* read the entire file into a string */
while((tmp = fread(buf, 1, blockSize, fp)) > 0) {
//@fixed: Cannot initialize a variable of type 'char *' with an rvalue of type 'void *'
//char *newSource = malloc(sourceLength + tmp + 1);
char *newSource = (char *)malloc(sourceLength + tmp + 1);
....
// line 110
message: Assigning to 'char *' from incompatible type 'void *';
修正:
/* get the shader info log */
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
//@fixed: Assigning to 'char *' from incompatible type 'void *';
//log = malloc(length);
log = (char *)malloc(length);
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。