#include #include #include "gl/glew.h"
#include #include static gtkwidget *window;
file *fp;
// shaders 以定義字串的方式給出
const glchar* vertexshadersource = "#version 330 core\n"
"layout (location = 0) in vec3 position;\n"
"void main()\n"
"\0";
const glchar* fragmentshadersource = "#version 330 core\n"
"uniform vec4 mycolor;\n"
"void main()\n"
"\n\0";
//main函式呼叫,定義成全域性形式
gluint vao, vbo;/*宣告vao,vbo*/
gluint vertexshader, fragmentshader, shaderprogram;/*宣告著色器物件和著色器程式物件*/
void slog_init()}
void slog(char * fmt,...)}
//vbo,vao初始化
void draw_init();
//生成頂點陣列物件vao
glgenvertexarrays(1, &vao);
//生成頂點緩衝物件vbo
glgenbuffers(1, &vbo);
//繫結vao
glbindvertexarray(vao);
//繫結vbo
glbindbuffer(gl_array_buffer, vbo);
//複製頂點資料到vb0
glbufferdata(gl_array_buffer, sizeof(vertices), vertices, gl_static_draw);
//解釋頂點資料鏈結方式
glvertexattribpointer(0, 3, gl_float, gl_true, 3 * sizeof(glfloat),(glvoid *) 0);
//glvertexattribpointer(0, 3, gl_float, gl_true, 0, 0);/*兩個頂點屬性之間無間隙,第五個引數可設定為0*/
glenablevertexattribarray(0);/*開啟頂點屬性,引數是頂點屬性location*/
//解綁vbo
glbindbuffer(gl_array_buffer, 0);
//解綁vao
glbindvertexarray(0);
//生成頂點著色器
vertexshader = glcreateshader(gl_vertex_shader);
glshadersource(vertexshader, 1, &vertexshadersource, null);/*著色器原始碼附加到著色器物件上*/
glcompileshader(vertexshader);/*編譯頂點著色器*/
//檢查頂點著色器是否編譯成功,不成功輸出錯誤資訊
glint success;
glchar infolog[512];
glgetshaderiv(vertexshader, gl_compile_status, &success);
if (!success)
//生成片段著色器
fragmentshader = glcreateshader(gl_fragment_shader);
glshadersource(fragmentshader, 1, &fragmentshadersource, null);
glcompileshader(fragmentshader);
//檢查片段著色器是否編譯成功,不成功輸出錯誤資訊
glgetshaderiv(fragmentshader, gl_compile_status, &success);
if (!success)
//生成著色器程式物件,並連線著色器
shaderprogram = glcreateprogram();
glattachshader(shaderprogram, vertexshader);/*把編譯好的著色器附加到著色器程式物件上*/
glattachshader(shaderprogram, fragmentshader);
//嘗試鏈結
gllinkprogram(shaderprogram);
//檢查鏈結著色器程式是否成功,不成功輸出錯誤資訊
glgetprogramiv(shaderprogram, gl_link_status, &success);
if(!success)
//刪除著色器
gldeleteshader(vertexshader);
gldeleteshader(fragmentshader);}
gboolean
display(gpointer user_data)
gboolean
render(gtkwidget *area, gpointer user_data)
void
realize(gtkwidget *area, gpointer user_data)
draw_init();
// 新增定時時間,每100ms呼叫一次display
g_timeout_add(100, display, area);}
static void create_window(void)
int main(int argc, char *ar**)
編譯
反正就是顏色來回變化
LearnOpenGL 繪製迴圈變色的三角形
include include include void processinput glfwwindow window void framebuffer size callback glfwwindow window,int width,int height int main glfwmakecon...
上三角矩陣下三角矩陣
要求給定矩陣,輸出其上三角矩陣或下三角矩陣 源 如下 include include include include const int m 5 void proc int array m m void main printf n proc a printf result array is n fo...
python楊輝三角 楊輝三角I II
給定乙個非負整數 numrows,生成楊輝三角的前 numrows 行。在楊輝三角中,每個數是它左上方和右上方的數的和。示例 輸入 5 輸出 1 1,1 1,2,1 1,3,3,1 1,4,6,4,1 可以一行一行錯位加,當然這裡提供更簡便的方法。任取一行描述 1,2,1 如何得到 1,3,3,1 ...