int init_buffers(void) { glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(2, vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]); shader_program_bind(&program); // получаем аттрибут для вершин attr_position = shader_program_get_attrib_loc(&program, "position"); if(attr_position != -1) { glVertexAttribPointer(attr_position, 3, GL_FLOAT, GL_FALSE, sizeof(vector3f), (const GLvoid*) 0); glEnableVertexAttribArray(attr_position); } glUniform3f(uniform_volume_step, volume_step.x, volume_step.y, volume_step.z); glActiveTexture(GL_TEXTURE0); texture_bind(&volume_texture); glUniform1i(uniform_volume_texture, 0); shader_program_unbind(&program); return 1; }
static void clutter_glx_texture_pixmap_update_area (ClutterX11TexturePixmap *texture, gint x, gint y, gint width, gint height) { ClutterGLXTexturePixmapPrivate *priv; Display *dpy; CLUTTER_NOTE (TEXTURE, "Updating texture pixmap"); priv = CLUTTER_GLX_TEXTURE_PIXMAP (texture)->priv; dpy = clutter_x11_get_default_display(); if (!CLUTTER_ACTOR_IS_REALIZED (texture)) return; if (priv->use_fallback) { CLUTTER_NOTE (TEXTURE, "Falling back to X11"); parent_class->update_area (texture, x, y, width, height); return; } if (priv->glx_pixmap == None) return; if (texture_bind (CLUTTER_GLX_TEXTURE_PIXMAP(texture))) { CLUTTER_NOTE (TEXTURE, "Really updating via GLX"); clutter_x11_trap_x_errors (); (_gl_bind_tex_image) (dpy, priv->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL); XSync (clutter_x11_get_default_display(), FALSE); /* Note above fires X error for non name pixmaps - but * things still seem to work - i.e pixmap updated */ if (clutter_x11_untrap_x_errors ()) CLUTTER_NOTE (TEXTURE, "Update bind_tex_image failed"); priv->bound = TRUE; } else g_warning ("Failed to bind initial tex"); if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR(texture))) clutter_actor_queue_redraw (CLUTTER_ACTOR(texture)); }
void render_update_volume_tex(void) { static int init = 0; if(init) { // если текстура уже инициализирована, то сначало удаляем её texture_release(&volume_texture); init = 0; } // создаем текстуру с данными скалярного поля. // используем только red компоненту texture_create3d_from_data(&volume_texture, GL_R32F, GL_RED, volume_size.x, volume_size.y, volume_size.z, GL_FLOAT, (void*) volume); texture_bind(&volume_texture); glUniform3f(uniform_volume_step, volume_step.x, volume_step.y, volume_step.z); init = 1; }
void sprite_draw(Sprite* sprite, const mat4* view, GLuint umatrix_id, GLuint utexture_id) { mat4 mvp; m4_x_m4(&mvp, view, &sprite->transform); glUniformMatrix4fv(umatrix_id, 1, GL_FALSE, (float*) &mvp); texture_bind(sprite->texture); glUniform1i(utexture_id, 0); int i; for(i = 0; i < NB_VERTEX_ATTRIB; ++i) { glEnableVertexAttribArray(i); buffer_bind(sprite->attributes[i].buffer); glVertexAttribPointer(i, sprite->attributes[i].size, GL_FLOAT, GL_FALSE, 0, NULL); } glDrawArrays(GL_TRIANGLES, 0, num_vertices); for(i = 0; i < NB_VERTEX_ATTRIB; ++i) { glDisableVertexAttribArray(i); } }
void render_draw(void) { IF_FAILED(init); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glActiveTexture(GL_TEXTURE0); texture_bind(&volume_texture); shader_program_bind(&program); glBindVertexArray(vao); glEnableVertexAttribArray(attr_position); glDrawElements(GL_TRIANGLES, num_elements, GL_UNSIGNED_INT, NULL); glDisableVertexAttribArray(attr_position); glBindVertexArray(0); shader_program_unbind(&program); }
void RenderTarget::draw(Shader* shader, const glm::vec2& pos, const glm::vec2& size){ glm::mat4 model(1.f); model = glm::translate(model, glm::vec3(pos.x, pos.y, 0.0f)); model = glm::scale(model, glm::vec3(size.x, size.y, 1.0f)); Shader::upload_model_matrix(model); shader->bind(); texture_bind(Shader::TEXTURE_2D_0); depth_bind(Shader::TEXTURE_2D_1); glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]); glVertexAttribPointer(Shader::ATTR_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, pos)); glVertexAttribPointer(Shader::ATTR_TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, uv)); glVertexAttribPointer(Shader::ATTR_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, normal)); glVertexAttribPointer(Shader::ATTR_TANGENT, 3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, tangent)); glVertexAttribPointer(Shader::ATTR_BITANGENT, 3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, bitangent)); glVertexAttribPointer(Shader::ATTR_COLOR, 4, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, color)); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, 0); }
static void clutter_glx_texture_pixmap_free_glx_pixmap (ClutterGLXTexturePixmap *texture) { ClutterGLXTexturePixmapPrivate *priv = texture->priv; Display *dpy; dpy = clutter_x11_get_default_display (); if (priv->glx_pixmap && priv->bound) { texture_bind (texture); clutter_x11_trap_x_errors (); (_gl_release_tex_image) (dpy, priv->glx_pixmap, GLX_FRONT_LEFT_EXT); XSync (clutter_x11_get_default_display(), FALSE); if (clutter_x11_untrap_x_errors ()) CLUTTER_NOTE (TEXTURE, "Failed to release?"); CLUTTER_NOTE (TEXTURE, "Destroyed pxm: %li", priv->glx_pixmap); priv->bound = FALSE; } clutter_x11_trap_x_errors (); if (priv->glx_pixmap) glXDestroyGLXPixmap (dpy, priv->glx_pixmap); XSync (dpy, FALSE); clutter_x11_untrap_x_errors (); priv->glx_pixmap = None; }
void con_render(renderer_t r) { unsigned int width, height; if ( NULL == con_default ) return; renderer_size(r, &width, &height); if ( CONSOLE_HIDDEN == con_default->state) { /* todo: draw the "last 4 lines" */ } else { float pitchx, pitchy; int i, offs, cursor_screen_offs; font_get_pitch(con_default->font, &pitchx, &pitchy); int const num_lines = con_display_lines; int const visible_height = pitchy * (num_lines + 1); int const border_top = height - visible_height - 5; if (con_default->conback) { glEnable(GL_TEXTURE_2D); texture_bind(con_default->conback); /* try toggling disabling blend - looks nice in different ways in each setting */ /* glDisable(GL_BLEND); */ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); glColor4f(1,1,1,1); glTexCoord2f(0, 0); glVertex2i(0, border_top); glTexCoord2f(1, 0); glVertex2i(width, border_top); glTexCoord2f(1, 1); glVertex2i(width, height); glTexCoord2f(0, 1); glVertex2i(0, height); glEnd(); glEnable(GL_BLEND); } else { glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glColor4f(0, 1.f, 0, 0.f); glVertex2i(0, border_top); glVertex2i(width, border_top); glVertex2i(width, height); glVertex2i(0, height); glEnd(); glEnable(GL_TEXTURE_2D); } offs = (con_default->lines_size % CONSOLE_MAX_LINES) - num_lines; for(i = 0; i < num_lines; i++, offs++) { if (offs < 0 && con_default->lines_size < CONSOLE_MAX_LINES) { /* well, this line hasn't actually been typed, so do nothing. */ } else { if (offs < 0) offs += CONSOLE_MAX_LINES; font_print(con_default->font, 0, border_top + i * pitchy, con_default->lines[offs % CONSOLE_MAX_LINES]); } } /* offset the input line if it's wider than the screen can show. we also keep a buffer of 3 characters at the "other side" of it, so that inplace editing is a bit more sensible. */ /* todo: blatantly should be able to move the character "within" the buffer within a current line when offset, and only scroll when at the left- or right- edges. */ /* should probably do this with a "current line display window" type concept. */ offs = 0; cursor_screen_offs = con_default->cursor_offs; if (pitchx * con_default->cursor_offs > width) { offs = con_default->cursor_offs - (width / pitchx) + 3; offs = offs < 0 ? 0 : offs; cursor_screen_offs = (width / pitchx) - 3; } font_print(con_default->font, 0, height - pitchy, &con_default->input_line[offs]); /* flashing cursor */ if (SDL_GetTicks() % 1000 < 500) { glBegin(GL_QUADS); glColor4f(1,1,1,1); glVertex2i(cursor_screen_offs * pitchx, height); glVertex2i(cursor_screen_offs * pitchx + pitchx, height); glVertex2i(cursor_screen_offs * pitchx + pitchx, height - 2); glVertex2i(cursor_screen_offs * pitchx, height - 2); glEnd(); } } }
void texture_download(gfx_texture* texture, SDL_Surface* target) { texture_bind(texture, TEX_UNIT_0); SDL_LockSurface(target); glGetTexImage(GL_TEXTURE_2D, _LOD, GL_RGBA, GL_UNSIGNED_BYTE, target->pixels ); SDL_UnlockSurface(target); }