int main () { bcm_host_init(); printf("Note: ensure you have sufficient gpu_mem configured\n"); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); // Setup the model world init_model_proj(state); // initialise the OGLES texture(s) init_textures(state); while (!terminate) { update_model(state); redraw_scene(state); } exit_func(); return 0; }
int main(int argc, char** argv) { init_ogl(p_state); create_perspective_matrix(&p_state->p_matrix, 45, 1.0, 0.1, 100); identity(&p_state->mv_matrix); identity(&p_state->send_mv_matrix); rotate_matrix(&p_state->send_mv_matrix, 180, 1.0, 0, 0); translate_matrix(&p_state->send_mv_matrix, 0, 0, -5); //rotate_matrix(&p_state->mv_matrix, 45, 1.0, 0, 0); translate_matrix(&p_state->mv_matrix, 0, 0, -5); init_shaders(p_state); init_framebuffer(p_state); init_textures(p_state); encode_loop(p_state); while(1) { } // return NULL; }
static void open_ogl (void) { TRACE_VC_MEMORY ("state 0"); #if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_EGL) bcm_host_init (); TRACE_VC_MEMORY ("after bcm_host_init"); #endif /* Start OpenGLES */ init_ogl (state); TRACE_VC_MEMORY ("after init_ogl"); /* Wrap the EGL display */ state->gst_display = gst_egl_display_new (state->display, NULL); /* Setup the model world */ init_model_proj (state); TRACE_VC_MEMORY ("after init_model_proj"); /* initialize the OGLES texture(s) */ init_textures (state); TRACE_VC_MEMORY ("after init_textures"); }
static int teapot_gl_init(RASPITEX_STATE *raspitex_state) { const char *model_path = "/opt/vc/src/hello_pi/hello_teapot/teapot.obj.dat"; TEAPOT_STATE_T *state = NULL; int rc = 0; // Clear scene state state = calloc(1, sizeof(TEAPOT_STATE_T)); raspitex_state->scene_state = state; state->screen_width = raspitex_state->width; state->screen_height = raspitex_state->height; rc = raspitexutil_gl_init_1_0(raspitex_state); if (rc != 0) goto end; // Start OGLES init_ogl(state); // Setup the model world init_model_proj(state); state->model = load_wavefront(model_path, NULL); if (! state->model) { vcos_log_error("Failed to load model from %s\n", model_path); rc = -1; } end: return rc; }
void scm_render::set_size(int w, int h) { free_ogl(); width = w; height = h; init_ogl(); init_matrices(); }
scm_render::scm_render(int w, int h) : width(w), height(h), blur(0), wire(false), frame0(0), frame1(0) { init_ogl(); init_matrices(); for (int i = 0; i < 16; i++) midentity(previous_T[i]); }
int main () { char vertex_shader[512]; char fragment_shader[512]; char geometry_shader[512]; int terminate = 0; GLfloat cx, cy; bcm_host_init(); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); glm::vec3 resolution((float)state->screen_width,(float)state->screen_height,0.0f); cx = state->screen_width/2; cy = state->screen_height/2; state->verbose=1; Shader shader(vertex_shader, fragment_shader,geometry_shader); init_shaders(state); //glBindAttribLocation (shader.Program, 0 , "position"); shader.linkProg(); shader.Use(); state->program=shader.Program; GLint resLoc = glGetUniformLocation(shader.Program, "iResolution"); glUniform3f(resLoc,resolution.x,resolution.y,resolution.z); GLfloat currentTime = 0.0f; GLint timeLoc = glGetUniformLocation(shader.Program, "time"); glUniform1f(timeLoc,currentTime); //draw_mandelbrot_to_texture(state, cx, cy, 0.003); while (!terminate) { int x, y, b; currentTime=currentTime+0.02; timeLoc = glGetUniformLocation(shader.Program, "time"); glUniform1f(timeLoc,currentTime); b = get_mouse(state, &x, &y); if (b) break; draw_triangles(state, cx, cy, 0.003, x, y); } return 0; }
int main () { bcm_host_init(); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); init_shaders(state); draw_triangles(state); sleep(2); return 0; }
static void open_ogl (void) { TRACE_VC_MEMORY ("state 0"); #if defined (USE_OMX_TARGET_RPI) bcm_host_init (); TRACE_VC_MEMORY ("after bcm_host_init"); #endif /* Create surface and gl context */ init_ogl (state); TRACE_VC_MEMORY ("after init_ogl"); /* Wrap the EGLDisplay to GstGLDisplayEGL */ state->gst_display = gst_gl_display_egl_new_with_egl_display (state->display); }
void init_graphics(int nargs, char** args, const char* title_bar, int x, int y) { /*KKCODEBLOCKSSUCKS*/#define SKMK_GLUT #ifdef SKMK_GLUT glutInit(&nargs, args); glutInitDisplayMode(GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL); //kk glutInitContextVersion(3, 3); glutInitContextVersion(3, 1); glutInitContextProfile(GLUT_CORE_PROFILE); #ifdef SKMK_DEBUG glutInitContextFlags(GLUT_DEBUG); #endif glutInitWindowSize(x, y); glutInitWindowPosition(300, 300); int window = glutCreateWindow(title_bar); ogl_load_funcs(); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); skmk.ogl_state = malloc(sizeof(struct ogl_state)); init_ogl(skmk.ogl_state); //!! glutDisplayFunc(ogl_draw); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); #elif SKMK_SDL2 //SDL_GLContext glcontext = SDL_GL_CreateContext(SDL_WINDOW); { SDL_Init(SDL_INIT_EVERYTHING); //TODO: Check errors K_SDL_WINDOW = SDL_CreateWindow(title_bar, 0, 0, x, y, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); K_GL_CONTEXT = SDL_GL_CreateContext(K_SDL_WINDOW); ogl_init(); } #else #error You have to either use GLUT or SDL. #endif }
int main(int argc, char *argv[]) { bcm_host_init(); init_ogl(p_state); glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glFlush(); eglSwapBuffers(p_state->display, p_state->surface); while (1) { sleep(10); } return 0; }
int _main () { bcm_host_init(); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); // Setup the model world init_model_proj(state); // initialise the OGLES texture(s) init_textures(state); while (!terminate) { update_model(state); redraw_scene(state); } exit_func(); return 0; }
void *render_task(void *dummy) { init_ogl(p_state); create_perspective_matrix(&p_state->p_matrix, 45, 1.0, 0.1, 100); identity(&p_state->mv_matrix); identity(&p_state->send_mv_matrix); rotate_matrix(&p_state->send_mv_matrix, 180, 1.0, 0, 0); translate_matrix(&p_state->send_mv_matrix, 0, 0, -5); //rotate_matrix(&p_state->mv_matrix, 45, 1.0, 0, 0); translate_matrix(&p_state->mv_matrix, 0, -10, -15); init_shaders(p_state); init_framebuffer(p_state); init_textures(p_state); encode_loop(p_state, &robot); return NULL; }
void test_nodeui_base(){ RtAudio dac; RtAudio::StreamParameters parm; parm.deviceId = 0;//dac.getDefaultOutputDevice(); parm.nChannels = 2; parm.firstChannel = 0; RtAudio::StreamOptions so; unsigned int bufferFrames = BUFFERSIZE; AudioScheduler a_sched; ControlScheduler c_sched; dac.openStream(&parm,NULL,RTAUDIO_SINT16, 44100, &bufferFrames, & saw, (void *) &a_sched); dac.startStream(); init_ogl(1024,1024); GLProgram shader = make_program("shaders/naive.vert","shaders/naive.frag"); UiBox ub1(Vec2f(-400.0,-300.0),Vec2f(800.0,600.0),{0.0,0.0,0.0,1.0},0.0,{0.0,0.0,0.0,0.0}); square_vbo = make_buffer<float>( {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}, 2,ARRAY_BUFFER, STATIC_DRAW); line_vbo = make_buffer<float>({0.0,0.0,1.0,1.0}, 2,ARRAY_BUFFER, STATIC_DRAW); float it = 0.0; scale =0.5; camera_x = 200.0; camera_y = -50.0; bool running = true; bool pause_proc = false; bool pause_ready = false; NodeGridInputHandler ngrid(&pause_proc, &pause_ready);; ngrid.backend.register_scheduler(&a_sched); ngrid.backend.register_scheduler(&c_sched); ngrid.shader = shader; ngrid.node_creators["osc"] = [](){return new Osc(440);}; ngrid.node_creators["add-audio"] = [](){return new AddAudio();}; ngrid.node_creators["audio-out"] = [](){return new AudioOut3();}; ngrid.node_creators["line-play"] = [](){return new line_play(1.0,std::vector<float>({0.0})) ;}; ngrid.node_creators["phasor"] = [](){return new Phasor(440) ;}; ngrid.node_creators["multiply"] = []() {return new MultNode();}; ngrid.node_creators["sub-audio"] = [](){return new SubAudio();}; ngrid.node_creators["divide"] = []() {return new DivNode();}; ngrid.node_creators["clip"] = []() {return new ClipNode();}; ngrid.node_creators["quit-program"] = [&running](){return new QuitProgramNode(&running);}; ngrid.node_creators["save-patch"] = [&ngrid](){return new SavePatchNode(&ngrid);}; ngrid.node_creators["load-patch"] = [&ngrid](){return new LoadPatchNode(&ngrid);}; Node * n1 = ngrid.create_and_insert_node("osc", Vec2f(0.0,0.0)); Node *n2 = ngrid.create_and_insert_node("audio-out", Vec2f(0.0,50.0)); Node *n3 = ngrid.create_and_insert_node("line-play 0.01 10 12 10 8",Vec2f(0.0,-100)); ngrid.connect(n1,0,n2,0); ngrid.connect(n3,0,n1,0); mouse_move_spawner.register_listener(&ngrid); mouse_click_handler.register_listener(&ngrid); char_event_spawner.register_listener(&ngrid); key_event_handler.register_listener(&ngrid); mouse_wheel_event_spawner.register_listener(&ngrid); std::thread ngrid_thread([&](){ while(running){ if(pause_proc){ pause_ready = true; }else{ pause_ready = false; ngrid.backend.update(); } } }); while(running){ float t = get_time(); if(ngrid.change){ shader.uniformf("camera_scale",1.0,1.0); shader.uniformf("camera_translate",0.0,0.0); bind_buffer_object(square_vbo,0); shader.uniformf("size",2.0,2.0); shader.uniformf("pos",-1.0,-1.0); shader.uniformf("color",0.0,0.0,0.5,1.0); draw_buffers_triangle_fan(4); shader.uniformf("camera_scale",2.0/1024.0*scale,2.0/1024.0*scale); shader.uniformf("camera_translate",camera_x,camera_y); ngrid.draw(); ngrid.draw2(shader); ngrid.change = false; }else{ std::cout << "Graphics sleeping.. \n"; } swapbuffers(); std::cout << "DT: " << get_time() - t << "\n"; float t_left = 1.0/30.0 - (get_time() - t); std::cout << t_left << "\n"; if(t_left > 0){ sleep_sec(t_left); } } ngrid_thread.join(); }
int main(int argc, char *argv[]) { bcm_host_init(); // Start OGLES init_ogl(state); ////////////////////// // Setup vertices ///////////////////// // Vertices static const GLfloat vertices[] = { -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f }; // Generate vertex buffer GLuint vbo; glGenBuffers(1, &vbo); // Set buffer glBindBuffer(GL_ARRAY_BUFFER, vbo); // Fill buffer glBufferData(GL_ARRAY_BUFFER, 2*4*sizeof(GLfloat), vertices, GL_STATIC_DRAW); // Elements GLubyte elements[] = { 2, 3, 0, 0, 1, 2 }; // Generate element buffer GLuint ebo; glGenBuffers(1, &ebo); // Set buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); // Fill buffer glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*sizeof(GLubyte), elements, GL_STATIC_DRAW); ///////////////////// // Setup shaders //////////////////// // Compile vertex shader GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, 1, &vertexSource, NULL); glCompileShader(vertexShader); showlog(vertexShader); // Compile frag shader GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentSource, NULL); glCompileShader(fragmentShader); showlog(fragmentShader); // Create shader program GLuint shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); // Link and use program glLinkProgram(shaderProgram); glUseProgram(shaderProgram); // Specify and enable vertex attribute GLint posAttrib = glGetAttribLocation(shaderProgram, "position"); glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(posAttrib); // Clear the screen glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // Event loop while(!terminate) { // Draw square glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0); // Swap buffers eglSwapBuffers(state->display, state->surface); } // Clean up before exit exit_func(); return 0; }
LRESULT CALLBACK MainDlg(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam) { PAINTSTRUCT ps; BITMAPINFO bmi; char str[255]; static int timer=FALSE; static int xpos=0,ypos=0,LMB=FALSE,dx=0,dy=0; static HWND hview=0; static HGLRC hglrc=0; static HDC hdc=0; int i; #ifdef _DEBUG // if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE) // debug_printf("message=%08X wparam=%08X lparam=%08X\n",message,wparam,lparam); #endif switch(message) { case WM_INITDIALOG: bufA=malloc(bwidth*bheight*bdepth); bufB=malloc(bwidth*bheight*bdepth); if(bufA==0 || bufB==0) MessageBox(hwnd,"malloc failed","error",MB_OK); else{ memset(bufB,0,bwidth*bheight*bdepth); rand_fill(bufA,bwidth,bheight,bdepth); } create_grippy(hwnd); BringWindowToTop(hwnd); BringWindowToTop(hwnd); update_title(hwnd); SendMessage(hwnd,WM_KEYDOWN,VK_TAB,0); SendMessage(hwnd,WM_LBUTTONDOWN,0,0); create_view_windows(hwnd,&hview); init_ogl(hview,&hglrc,&hdc); resize_view(hwnd,hview); break; case WM_SIZE: { int w,h; w=LOWORD(lparam); h=HIWORD(lparam); grippy_move(hwnd); resize_view(hwnd,hview); reshape(w,h); } break; case WM_TIMER: if(LMB) handle_click(xpos,ypos); display_view1(hview,hglrc); break; case WM_COMMAND: switch(LOWORD(wparam)) { case IDC_ONTOP: SetWindowPos(hwnd,IsDlgButtonChecked(hwnd,LOWORD(wparam))? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); break; case WM_DESTROY: #ifndef _DEBUG if(MessageBox(hwnd,"Sure you want to quit?","QUIT",MB_OKCANCEL)!=IDOK) break; #endif PostQuitMessage(0); break; } break; case WM_PAINT: /* hdc=BeginPaint(hwnd,&ps); memset(&bmi,0,sizeof(BITMAPINFO)); bmi.bmiHeader.biBitCount=24; bmi.bmiHeader.biWidth=BUF_WIDTH; bmi.bmiHeader.biHeight=BUF_HEIGHT; bmi.bmiHeader.biPlanes=1; bmi.bmiHeader.biSize=40; if(stretch) StretchDIBits(hdc,0,0,client_rect.right,client_rect.bottom,0,0,BUF_WIDTH,BUF_HEIGHT,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY); else SetDIBitsToDevice(hdc,0,0,BUF_WIDTH,BUF_HEIGHT,0,0,0,BUF_WIDTH,buffer,&bmi,DIB_RGB_COLORS); screen_updated=TRUE; EndPaint(hwnd,&ps); */ break; case WM_CLOSE: case WM_QUIT: PostQuitMessage(0); break; case WM_DROPFILES: break; case WM_RBUTTONDOWN: case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: xpos=LOWORD(lparam); ypos=HIWORD(lparam); break; case WM_MOUSEMOVE: { int x,y; int key=wparam; x=LOWORD(lparam); y=HIWORD(lparam); if(key&MK_LBUTTON){ x=xpos-x; ry=x; y=ypos-y; rx=y; printf("rz=%.1f ry=%.1f\n",rx,ry); } if(key&MK_RBUTTON){ x=xpos-x; rz=-x; printf("z=%.1f\n",rz); } update_title(hwnd); } break; case WM_MOUSEWHEEL: if(wparam&0x80000000) SendMessage(hwnd,WM_KEYDOWN,VK_NEXT,0); else SendMessage(hwnd,WM_KEYDOWN,VK_PRIOR,0); break; case WM_KEYUP: break; case WM_KEYDOWN: { int ctrl=GetKeyState(VK_CONTROL)&0x8000; int shift=GetKeyState(VK_SHIFT)&0x8000; #ifdef _DEBUG // debug_printf("message=%08X wparam=%08X lparam=%08X\n",message,wparam,lparam); #endif switch(wparam) { case VK_INSERT: clear_screen(); break; case 0xBD: case 0xBB: break; case 'Q': rx=ry=rz=0; printf("angles reset\n"); break; case 'W': break; case 0xC0: rand_fill(swap?bufB:bufA,bwidth,bheight,bdepth); break; case 'K': set_offsety(1); break; case 'L': set_offsety(-1); break; case 'X': if(shift) scale+=10; else scale++; printf("scale=%i\n",scale); break; case 'Z': if(shift) scale-=10; else scale--; printf("scale=%i\n",scale); break; //case 0xC0: change_direction(0); rx=ry=rz=0; break; case '0': case '1': //tube(); frame_step=1; break; case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': change_direction(wparam-'0'); break; case VK_SPACE: break; case VK_TAB: if(timer) KillTimer(hwnd,1); else SetTimer(hwnd,1,60,NULL); timer=!timer; break; case VK_F1: display_help(hwnd); break; /* case VK_F2: i=CreateDialog(ghInstance,MAKEINTRESOURCE(IDD_DIALOG2),hwnd,request_value); ShowWindow(i,SW_SHOWNORMAL); debug_printf("return =%i\r\n",i); break;*/ case VK_F5: break; case VK_F9: stretch=!stretch; break; case 0xDEADBEEF: break; case VK_DOWN: if(GetKeyState(VK_CONTROL)&0x8000) move_center(3); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(12); else change_direction(2); break; case VK_UP: if(GetKeyState(VK_CONTROL)&0x8000) move_center(4); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(11); else change_direction(1); break; case VK_LEFT: if(GetKeyState(VK_CONTROL)&0x8000) move_center(1); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(14); else change_direction(4); break; case VK_RIGHT: if(GetKeyState(VK_CONTROL)&0x8000) move_center(2); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(13); else change_direction(3); break; case VK_ADD: break; case VK_SUBTRACT: break; case VK_NEXT: //page key if(GetKeyState(VK_CONTROL)&0x8000) ; else if(GetKeyState(VK_SHIFT)&0x8000) ; change_direction(100); break; case VK_PRIOR: //page key if(GetKeyState(VK_CONTROL)&0x8000) ; else if(GetKeyState(VK_SHIFT)&0x8000) ; change_direction(100); break; case VK_HOME: change_direction(5); break; case VK_END: ; break; case ZOOM_IN_KEY: //[ if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case ZOOM_OUT_KEY: //] if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case 0xBE: //> if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case 0xBC: //< if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case 'V': if(GetKeyState(VK_CONTROL)&0x8000){ if(OpenClipboard(NULL)){ char *p=GetClipboardData(CF_TEXT); if(p!=0){ strncpy(str,p,sizeof(str)); SetDlgItemText(hwnd,IDC_EDIT1,str); } CloseClipboard(); } } break; case VK_ESCAPE: if(MessageBox(hwnd,"Sure you want to quit?","QUIT",MB_OKCANCEL)==IDOK) PostQuitMessage(0); break; } update_title(hwnd); } break; } return 0; }
/* * start of code */ void graphics_init() { const char *vShaderStr = "attribute vec4 a_position; \n" "uniform mat4 u_ViewMatrix; // A constant representing the combined model/view matrix. \n" "attribute vec2 a_texCoord; \n" "varying vec2 v_texCoord; \n" "void main() \n" "{ \n" " gl_Position = u_ViewMatrix * a_position; \n" " v_texCoord = a_texCoord; \n" "} \n"; #if 0 const char *vShaderStr = "attribute vec4 a_position; \n" "uniform mat4 u_ViewMatrix; // A constant representing the combined model/view matrix. \n" "attribute vec2 a_texCoord; \n" "varying vec2 v_texCoord; \n" "void main() \n" "{ \n" " gl_Position = u_ViewMatrix * a_position; \n" " v_texCoord = a_texCoord; \n" "} \n"; #endif const char *fShaderStr = "precision mediump float; \n" "varying vec2 v_texCoord; \n" "uniform sampler2D s_texture; \n" "void main() \n" "{ \n" " gl_FragColor = texture2D( s_texture, v_texCoord );\n" " // gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n" "} \n"; int i; init_ogl(); assert( glGetError() == GL_NO_ERROR ); // Set background color and clear buffers glClearColor(0.15f, 0.25f, 0.35f, 1.0f); // Load the shaders and get a linked program object programObject = LoadProgram( vShaderStr, fShaderStr ); assert( glGetError() == GL_NO_ERROR ); // Get the attribute locations positionLoc = glGetAttribLocation ( programObject, "a_position" ); texCoordLoc = glGetAttribLocation ( programObject, "a_texCoord" ); assert( glGetError() == GL_NO_ERROR ); viewMatrixLoc = glGetUniformLocation( programObject, "u_ViewMatrix" ); // Get the sampler location samplerLoc = glGetUniformLocation ( programObject, "s_texture" ); // glGenBuffers( 1, &vertexBufferID ); glGenBuffers( 1, &indexBufferID ); assert( glGetError() == GL_NO_ERROR ); for( i = 0; i < MAX_TILES; i++ ) tiles[i].vertexBufferID = -1; // Enable back face culling. // glEnable(GL_CULL_FACE); }
int main () { int terminate = 1; bcm_host_init(); // Clear application state memset( state, 0, sizeof( *state ) ); // Start OGLES init_ogl(state); //init_shaders(state); char vShaderSource[] = "attribute vec4 vPosition; \n" "uniform vec4 offset; \n" "void main() \n" "{ \n" " vec4 nPosition = (vPosition*vec4(0.25, 0.25, 0.25, 1.0))+offset; \n" " gl_Position = nPosition; \n" "} \n"; //everything is black char fShaderSource[] = "precision mediump float; \n" "void main() \n" "{ \n" " gl_FragColor = vec4(1.0, 1.0, 1.0, 0.5); \n" "} \n"; GLuint vshader = LoadShader(vShaderSource, GL_VERTEX_SHADER); GLuint fshader = LoadShader(fShaderSource, GL_FRAGMENT_SHADER); GLuint programObj = glCreateProgram(); GLint linked; check(); assert(programObj != 0); glAttachShader(programObj, vshader); glAttachShader(programObj, fshader); glBindAttribLocation(programObj, 0, "vPosition"); check(); glLinkProgram(programObj); check(); glGetProgramiv(programObj, GL_LINK_STATUS, &linked); if(linked != GL_TRUE) { showprogramlog(programObj); glDeleteProgram(programObj); return -1; } GLint offset = glGetUniformLocation(programObj, "offset"); check(); GLfloat vVertices[] = { 0.f, -0.25f, 0.0f, 0.5f, 0.25f, 0.0f, 0.75f, -0.25f, 0.0f }; glViewport(0,0, state->screen_width, state->screen_height); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(programObj); GLfloat offet_vector[] = { 0.5f, 0.0f, 0.0f, 0.0f }; glUniform4fv(offset, 4, offet_vector); glVertexAttribPointer(0,3, GL_FLOAT, GL_FALSE, 0, vVertices); glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); GLfloat square[] = { -1.00f, -1.00f, 0.0f, // Bottom Left 1.00f, -1.00f, 0.0f, // Bottom Right -1.00f, 1.00f, 0.0f, // Top Left 1.00f, 1.00f, 0.0f //Top Right }; GLfloat sqoffet_vector[] = { -0.5f, 0.0f, 0.0f, 0.0f }; glUniform4fv(offset, 4, sqoffet_vector); //glUniform1f(offset, -0.5); glVertexAttribPointer(0,3, GL_FLOAT, GL_FALSE, 0, square); glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableVertexAttribArray(0); eglSwapBuffers(state->display, state->surface); getchar(); while (!terminate) { } return 0; }