textures

Texture Sampling Coordinates to Render a Sprite

丶灬走出姿态 提交于 2019-11-30 08:48:51
Let's say we have a texture (in this case 8x8 pixels) we want to use as a sprite sheet. One of the sub-images (sprite) is a subregion of 4x3 inside the texture, like in this image: (Normalized texture coordinates of the four corners are shown) Now, there are basically two ways to assign texture coordinates to a 4px x 3px-sized quad so that it effectively becomes the sprite we are looking for; The first and most straightforward is to sample the texture at the corners of the subregion: // Texture coordinates GLfloat sMin = (xIndex0 ) / imageWidth; GLfloat sMax = (xIndex0 + subregionWidth ) /

How to use multiple textures in WebGL?

ε祈祈猫儿з 提交于 2019-11-30 05:07:39
问题 I wanted to use 6 different textures on a cube, one per side, but can't find the mistake. Here's my current code: var texturen = new Array(); function initTexture(sFilename,texturen) { var anz = texturen.length; texturen[anz] = gl.createTexture(); texturen[anz].image = new Image(); texturen[anz].image.onload = function() { gl.bindTexture(gl.TEXTURE_2D, texturen[anz]); gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); gl.texImage2D (gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texturen

How to change single texel in OpenGL texture

ぃ、小莉子 提交于 2019-11-30 04:30:49
问题 I want to change the some texels in a OpenGL texture for a given location. Can anyone help me with this pls ? This is the functionnality that I want, void ChangeTexelColor(int x, int y, GLuint id, int texW, int texH, GLenum format) { //What is here ? } This will use to maintain the minimap of my game (if anyone have a better idea of maintaining a dynamic map-texture-). Btw, this must done fast. Thanks. 回答1: OpenGL has the glTexSubImage2D function, which is exactly for your purpose. Here's a

libgdx: Rotate a texture when drawing it with spritebatch

允我心安 提交于 2019-11-30 03:48:23
Im trying to rotate textures when I draw them. I figured it would make more sense to do this than to rotate the images 90 degrees in paint.net and save them in different files. I looked thought the api documentation for spritebatch drawing arguments but I just dont understand. There are a bunch of arguments such as srcX, srcY, originX and so on. Also i would like to know how to do the same for texture regions. Heres a link to the api documentation page: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/SpriteBatch.html Thank you! again from the documentation ,

Animating Canvas Billboard in THREE.js

亡梦爱人 提交于 2019-11-30 03:13:14
问题 Everyone, I'm trying to animate a Canvas-based texture that is mapped onto a plane, like a billboard. I've made a point of including material.needsUpdate & texture.needsUpdate , but I'm still unable to get the texture to come to life. I've also included a rotating cube just so I know the animation routine is functioning on some level. Here is the code: if ( window.innerWidth === 0 ) { window.innerWidth = parent.innerWidth; window.innerHeight = parent.innerHeight; } var camera, scene, renderer

dart:web_gl: RENDER WARNING: texture bound to texture unit 0 is not renderable

穿精又带淫゛_ 提交于 2019-11-30 03:00:32
问题 I'm getting the error [.WebGLRenderingContext]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete' when I run my web app in dartium. I've been trying to troubleshoot this issue for two days, including a full rewrite of the code, But I can't isolate the issue. I think the problem lies in this piece of code, however. void main() { ... var texture = gl.createTexture(); var image = new

Android OpenGL combination of SurfaceTexture (external image) and ordinary texture

霸气de小男生 提交于 2019-11-30 02:48:20
i would like to mix camera preview SurfaceTexture with some overlay texture. I am using these shaders for processing: private final String vss = "attribute vec2 vPosition;\n" + "attribute vec2 vTexCoord;\n" + "varying vec2 texCoord;\n" + "void main() {\n" + " texCoord = vTexCoord;\n" + " gl_Position = vec4 ( vPosition.x, vPosition.y, 0.0, 1.0 );\n" + "}"; private final String fss = "#extension GL_OES_EGL_image_external : require\n" + "precision mediump float;\n" + "uniform samplerExternalOES sTexture;\n" + "uniform sampler2D filterTexture;\n" + "varying vec2 texCoord;\n" + "void main() {\n" +"

Programmatically creating directx 11 textures, pros and cons of the three different methods

≯℡__Kan透↙ 提交于 2019-11-30 02:05:57
The msdn documentation explains that in directx 11 there are multiple ways to fill a directx 11 texture programmatically: (1) Create the texture with default usage texture and initialize it with data from memory (2) Create the texture with dynamic usage, use DeviceContext Map to get a pointer to texture memory, write to it, then use Unmap to indicate you are done (at which point I guess it is copied to the gpu) (3) Create the texture with staging usage and follow same steps as for dynamic texture, but follow that with a call to ID3D11DeviceContext.CopyResource to use this staging texture to in

Loading texture for OpenGL with OpenCV

本秂侑毒 提交于 2019-11-30 00:59:27
I have seen many code samples for loading textures for OpenGL , many of them a bit complicated to understand or requiring new functions with a lot of code. I was thinking that as OpenCV allows us to load any image format it can be a simple an efficient way to load textures to OpenGL , but I am missing something. I have this piece of code in c++ : cv::Mat texture_cv; GLuint texture[1]; int Status=FALSE; if( texture_cv = imread("stones.jpg")) { Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameterf(GL

OpenGL ES Texture Coordinates Slightly Off

☆樱花仙子☆ 提交于 2019-11-30 00:45:14
I'm trying to draw a subregion of a texture in OpenGL by specifying the coordinates I want. What's happening though is that, depending on the size of the image, it seems there's a slight offset in the origin of where it selects the texture coordinates. The offset amount seems to be less than the size of a pixel & the output is is blurred combination of neighboring pixels. Here's an idea of what I'm describing. In this case I'd want to select the 6x5 green/white region but what OpenGL is rendering includes a slight pink tint to the top & left pixels. What the output would look like: I can fix