Convert an UIImage in a texture

I haven’t test the following but i will decompose the conversion in 3 steps: Extract info for your image: UIImage* image = [UIImage imageNamed:@”imageToApplyAsATexture.png”]; CGImageRef imageRef = [image CGImage]; int width = CGImageGetWidth(imageRef); int height = CGImageGetHeight(imageRef); Allocate a textureData with the above properties: GLubyte* textureData = (GLubyte *)malloc(width * height * 4); // if … Read more

CUDA allocation alignment is 256 bytes – seriously?

The pointers which are allocated by using any of the CUDA Runtime’s device memory allocation functions e.g cudaMalloc or cudaMallocPitch are guaranteed to be 256 byte aligned, i.e. the address is a multiple of 256. Consider the following example: char *ptr1, *ptr2; int bytes = 1; cudaMalloc((void**)&ptr1,bytes); cudaMalloc((void**)&ptr2,bytes); Suppose the address returned in ptr1 is … Read more

WebGL – wait for texture to load

The easiest way to fix that is to make a 1×1 texture at creation time. var tex = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, tex); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([255, 0, 0, 255])); // red Then when the image loads you can replace the 1×1 pixel texture with the image. No flags needed and … Read more

Multiple textures in GLSL – only one works

Here’s a basic GLUT example (written on OS X, adapt as needed) that generates two checkerboard textures, loads a shader with two samplers and combines them by tinting each (one red, one blue) and blending. See if this works for you: #include <stdio.h> #include <stdlib.h> #include <GLUT/glut.h> #include <OpenGL/gl.h> #include <OpenGL/glu.h> #define kTextureDim 64 GLuint … Read more

DAE files image texture doesn’t show up in Aframe when exported from Maya

I presume You added Your collada ( dae ) model like presented on the aframe docs: <a-scene> <a-assets> <a-asset-item id=”head” src=”https://stackoverflow.com/path/to/head.dae”></a-asset-item> </a-assets> <a-entity collada-model=”#head”></a-entity> </a-scene> To texture the model, You either need to: 1. Make a reference to the texture in the material of the entity. In <a-assets> make an img reference: <img id=”texture” src=”https://stackoverflow.com/questions/44451617/head.jpg”> … Read more

Read pixels from a WebGL texture

You can try attaching the texture to a framebuffer and then calling readPixels on the frame buffer. at init time // make a framebuffer fb = gl.createFramebuffer(); // make this the current frame buffer gl.bindFramebuffer(gl.FRAMEBUFFER, fb); // attach the texture to the framebuffer. gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); // check if you can read … Read more