Search Results

Search found 1308 results on 53 pages for 'texture'.

Page 9/53 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • opengl 3d texture issue

    - by user1478217
    Hi i'm trying to use a 3d texture in opengl to implement volume rendering. Each voxel has an rgba colour value and is currently rendered as a screen facing quad.(for testing purposes). I just can't seem to get the sampler to give me a colour value in the shader. The quads always end up black. When I change the shader to generate a colour (based on xyz coords) then it works fine. I'm loading the texture with the following code: glGenTextures(1, &tex3D); glBindTexture(GL_TEXTURE_3D, tex3D); unsigned int colours[8]; colours[0] = Colour::AsBytes<unsigned int>(Colour::Blue); colours[1] = Colour::AsBytes<unsigned int>(Colour::Red); colours[2] = Colour::AsBytes<unsigned int>(Colour::Green); colours[3] = Colour::AsBytes<unsigned int>(Colour::Magenta); colours[4] = Colour::AsBytes<unsigned int>(Colour::Cyan); colours[5] = Colour::AsBytes<unsigned int>(Colour::Yellow); colours[6] = Colour::AsBytes<unsigned int>(Colour::White); colours[7] = Colour::AsBytes<unsigned int>(Colour::Black); glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, colours); The colours array contains the correct data, i.e. the first four bytes have values 0, 0, 255, 255 for blue. Before rendering I bind the texture to the 2nd texture unit like so: glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_3D, tex3D); And render with the following code: shaders["DVR"]->Use(); shaders["DVR"]->Uniforms["volTex"].SetValue(1); shaders["DVR"]->Uniforms["World"].SetValue(Mat4(vl_one)); shaders["DVR"]->Uniforms["viewProj"].SetValue(cam->GetViewTransform() * cam->GetProjectionMatrix()); QuadDrawer::DrawQuads(8); I have used these classes for setting shader params before and they work fine. The quaddrawer draws eight instanced quads. The vertex shader code looks like this: #version 330 layout(location = 0) in vec2 position; layout(location = 1) in vec2 texCoord; uniform sampler3D volTex; ivec3 size = ivec3(2, 2, 2); uniform mat4 World; uniform mat4 viewProj; smooth out vec4 colour; void main() { vec3 texCoord3D; int num = gl_InstanceID; texCoord3D.x = num % size.x; texCoord3D.y = (num / size.x) % size.y; texCoord3D.z = (num / (size.x * size.y)); texCoord3D /= size; texCoord3D *= 2.0; texCoord3D -= 1.0; colour = texture(volTex, texCoord3D); //colour = vec4(texCoord3D, 1.0); gl_Position = viewProj * World * vec4(texCoord3D, 1.0) + (vec4(position.x, position.y, 0.0, 0.0) * 0.05); } uncommenting the line where I set the colour value equal to the texcoord works fine, and makes the quads coloured. The fragment shader is simply: #version 330 smooth in vec4 colour; out vec4 outColour; void main() { outColour = colour; } So my question is, what am I doing wrong, why is the sampler not getting any colour values from the 3d texture? [EDIT] Figured it out but can't self answer (new user): As soon as I posted this I figured it out, I'll put the answer up to help anyone else (it's not specifically a 3d texture issue, and i've also fallen afoul of it before, D'oh!). I didn't generate mipmaps for the texture, and the default magnification/minification filters weren't set to either GL_LINEAR, or GL_NEAREST. Boom! no textures. Same thing happens with 2d textures.

    Read the article

  • What are the different ways to texture a terrain?

    - by ApocKalipsS
    I'm working with XNA on a 3D Game, and I'm trying to have a proper and nice environnement. I actually followed a tutorial to create a terrain from a Heightmap, and to texture it, I just apply a grass texture on it and tile it a number of times. But what I want to do is to have a really realistic texturing, but also generate it automatically (for example if I want to use a perlin noise to generate a terrain and then texture it). I already learnt about multi-texturing, loading a map file with different colors for different textures, but I don't think this is really efficient, for instance for cliffs or very steep areas it will tile a texture badly as it's a view from the top. Also I don't know how i'll draw roads or dirt paths with that. I hope you understood me despite my english! If you don't, basically, here what I want to do: How do I texture a randomly generated terrain? :) Thank you for your answers!

    Read the article

  • What are some ways to texture map a terrain?

    - by ApocKalipsS
    I'm working with XNA on a 3D Game, and I'm trying to have a proper and nice environnement. I actually followed a tutorial to create a terrain from a heightmap. To texture it, I just apply a grass texture on it and tile it a number of times. But what I want to do is to have a really realistic texturing, but also generate it automatically (for example if I want to use Perlin noise to generate a terrain and then texture it). I already learned about multi-texturing, loading a map file with different colors for different textures, but I don't think this is really efficient, for instance for cliffs or very steep areas it will tile a texture badly as it's a view from the top. (Also, I don't know how I'll draw roads or dirt paths with that.) I'm looking for an efficient solution to realistically texture mapping procedurally-generated terrain.

    Read the article

  • OpenGL 3.0+ framebuffer to texture/images

    - by user827992
    I need a way to capture what is rendered on screen, i have read about glReadPixels but it looks really slow. Can you suggest a more efficient or just an alternative way for just copying what is rendered by OpenGL 3.0+ to the local RAM and in general to output this in a image or in a data stream? How i can achieve the same goal with OpenGL ES 2.0 ? EDIT: i just forgot: with this OpenGL functions how i can be sure that I'm actually reading a complete frame, meaning that there is no overlapping between 2 frames or any nasty side effect I'm actually reading the frame that comes right next to the previous one so i do not lose frames

    Read the article

  • Reading from a staging 2D texture array in DirectX10

    - by Don Reba
    I have a DX10 program, where I create an array of 3 16x16 textures, then map, read, and unmap each subresource in turn. I use a single mip level, set resource usage to staging and CPU access to read. Now, here is the problem: Subresource 0 contains 1024 bytes, pitch 64, as expected. Subresource 1 contains 512 bytes, pitch 64. Subresource 2 contains 256 bytes, pitch 64. I expect all three to be the same size. Debugging output is enabled, but not reporting any warnings or errors. Am I missing something, or might this be some sort of driver issue? Here is the code. The language is Nemerle, but C# and C++ would look almost the same. I have looked through the generated code, and am fairly confident the problem is not language-related. def cpuTexture = Texture2D ( device , Texture2DDescription() <- { Width = 16; Height = 16; MipLevels = 1; ArraySize = 3; Format = Format.R32_Float; Usage = ResourceUsage.Staging; CpuAccessFlags = CpuAccessFlags.Read; SampleDescription = SampleDescription(count = 1, quality = 0); } ); foreach (subresource in [0 .. 2]) { def data = cpuTexture.Map(subresource, MapMode.Read, MapFlags.None); Console.WriteLine($"subresource $subresource"); Console.WriteLine($"length = $(data.Data.Length)"); Console.WriteLine($"pitch = $(data.Pitch)"); cpuTexture.Unmap(subresource); }

    Read the article

  • E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809) when loading a cube texture

    - by Boreal
    I'm trying to implement a skybox into my engine, and I'm having some trouble loading the image as a cube map. Everything works (but it doesn't look right) if I don't load using an ImageLoadInformation struct in the ShaderResourceView.FromFile() method, but it breaks if I do. I need to, of course, because I need to tell SlimDX to load it as a cubemap. How can I fix this? Here is my new loading code after the "fix": public static void LoadCubeTexture(string filename) { ImageLoadInformation loadInfo = ImageLoadInformation.FromDefaults(); loadInfo.OptionFlags = ResourceOptionFlags.TextureCube; textures.Add(filename, ShaderResourceView.FromFile(Graphics.device, "Resources/" + filename, loadInfo)); }

    Read the article

  • Setting up cube map texture parameters in OpenGL

    - by KaiserJohaan
    I see alot of tutorials and sources use the following code snippet when defining each face of a cube map: for (i = 0; i < 6; i++) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, InternalFormat, size, size, 0, Format, Type, NULL); Is it safe to assume GL_TEXTURE_CUBE_MAP_POSITIVE_X + i will properly iterate the following cube map targets, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y etc?

    Read the article

  • How to draw texture to screen in Unity?

    - by user1306322
    I'm looking for a way to draw textures to screen in Unity in a similar fashion to XNA's SpriteBatch.Draw method. Ideally, I'd like to write a few helper methods to make all my XNA code work in Unity. This is the first issue I've faced on this seemingly long journey. I guess I could just use quads, but I'm not so sure it's the least expensive way performance-wise. I could do that stuff in XNA anyway, but they made SpriteBatch not without a reason, I believe.

    Read the article

  • Dynamic Terrain Texture

    - by lgrevenl
    I've been looking at a 2D physics game called 'Hill Climb Racing' (Android and iOS) and was wondering how they went about texturing the terrain? I've had a think about it and I've come up with nothing and finding a resource on the web has proved impossible. Please help. The game mentioned uses Cocos2d. Would it be just as doable in a different environment? EDIT: I was looking at another question: Drawing large 2D sidescroller level terrain The end result is what I'm looking for, but in my mind I was thinking that there would be some way to add this effect (using small textures) to some terrain specified by vertices rather than making a very large image to match whatever is seen in the level.

    Read the article

  • OpenGL ES rotate texture

    - by 0xSina
    I just got started with OpenGL ES... I have a fragment: const char * sFragment = _STRINGIFY( varying highp vec2 coordinate; precision mediump float; uniform vec4 maskC; uniform float threshold; uniform sampler2D videoframe; uniform sampler2D videosprite; uniform vec4 mask; uniform vec4 maskB; uniform int recording; vec3 normalize(vec3 color, float meanr) { return color*vec3(0.75 + meanr, 1., 1. - meanr); } void main() { float d; float dB; float dC; float meanr; float meanrB; float meanrC; float minD; vec4 pixelColor; vec4 spriteColor; pixelColor = texture2D(videoframe, coordinate); spriteColor = texture2D(videosprite, coordinate); meanr = (pixelColor.r + mask.r)/8.; meanrB = (pixelColor.r + maskB.r)/8.; meanrC = (pixelColor.r + maskC.r)/8.; d = distance(normalize(pixelColor.rgb, meanr), normalize(mask.rgb, meanr)); dB = distance(normalize(pixelColor.rgb, meanrB), normalize(maskB.rgb, meanrB)); dC = distance(normalize(pixelColor.rgb, meanrC), normalize(maskC.rgb, meanrC)); minD = min(d, dB); minD = min(minD, dC); gl_FragColor = spriteColor; if (minD > threshold) { gl_FragColor = pixelColor; } } Now, depending on wether recording is 0 or 1, I want to rotate uniform sampler2D videosprite 180 degrees (reflection in x-axis, flip vertically). How can I do that? I found the function glRotatef(), but how do i specify that I want to rotate video sprite and not videoframe? Thanks

    Read the article

  • LWJGL GL_QUADS texture artifact

    - by Dajgoro Labinac
    I managed to get working lwjgl in Java, and i loaded a test image(tv test card), but i keep getting weird artifacts outside the image. Image link: http://tinypic.com/r/vhv9g/6 Code: glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2i(10, 10); glTexCoord2f(1, 0); glVertex2i(500, 10); glTexCoord2f(1, 1); glVertex2i(500, 500); glTexCoord2f(0, 1); glVertex2i(10, 500); glEnd(); What could be the cause?

    Read the article

  • what is the easiest way to make a hitbox that rotates with it's texture

    - by Matthew Optional Meehan
    In xna when you have a sprite that doesnt rotate it's very easy to get the four corner of a sprite to make a hitbox, but when you do a rotation the points get moved and I assume there is some kind of math that I can use to aquire them. I am using the four points to draw a rectangle that visually represents the hitboxes. I have seen some per-pixel collission examples but I can forsee they would be hard to draw a box/'convex hull' around. I have also seen physics like farseer but I'm not sure if there is a quick tutorial to do what I want. What do you guys think is the best approach becuase I am looking to complete this work by the end of the week.

    Read the article

  • How to use a mask texture with Kobold2D

    - by alex
    I am an iOS developer but I'm new to cocos2d. I'm working on new game, I use Kobold2D, have cocos2d installed too, and I want to make this effect: I know how is done with Flash, but can't make it with Kobold2D. There's 2 images with the same size: one is a low-res image for the background and the second is a hi-res over the first one. When the "reticle" mask moves, it reveals the second image inside the circle and the background is visible outside only. I googled with no success, saw some Ray Wenderlich projects they weren't helpful.

    Read the article

  • Doing imagemagick like stuff in Unity (using a mask to edit a texture)

    - by Codejoy
    There is this tutorial in imagemagick http://www.imagemagick.org/Usage/masking/#masks I was wondering if there was some way to mimic the behavior (like cutting the image up based on a black image mask that turns image parts transparent... ) and then trim that image in game... trying to hack around with the webcam feature and reproduce some of the imagemagick opencv stuff in it in Unity but I am saddly unequipped with masks, shaders etc in unity skill/knowledge. Not even sure where to start.

    Read the article

  • How to draw a texture to a MS Terrain object - Farseer

    - by Brad
    I'm using Farseer to make a game in XNA and I can't seem to figure this out. I've decided to use MSTerrain for making my game's terrain because I wanted destructible terrain and MSTerrain seemed like the best bet. Unfortunately, I'm stumped on how to actually show the terrain. When I generate the terrain it's visible in debug view, but MSTerrain does not have a Draw method, so I'm wondering how it is supposed to be drawn to the screen? Is it worth pursuing? I'm starting to think that MSTerrain is more trouble than it's worth, is there another better way to do this with bodies? I appreciate any help you can give. Thanks.

    Read the article

  • Problem with migrating from Texture2D to CCTexture2D (Setting CCSprite texture)

    - by marie
    My problem is that whenever I change the texture of a sprite, the new texture will retain the size of the original sprite's texture. I have this code: mySprite = [CCSprite spriteWithFile:@"mySprite.png"]]; ... // change current stage here CCTexture2D *newTexture=[[[CCTexture2D alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"stage number %d.png",currentStageNumber]]]autorelease]; [mySprite setTexture:newTexture]; The new sprite is stretched or compressed depending on the size of the original sprite. If the original sprite is larger, the new texture is stretched. I didn't have this problem when I was using cocos2d v0.8 What am I doing wrong?

    Read the article

  • DirectX Sphere Texture Coordinates

    - by Rushyo
    I have a sphere with per-vertex normals and I'm trying to derive the texture coordinates for the object using the algorithm: U = Asin(Norm.X) / PI + 0.5 V = Asin(Norm.Y) / PI + 0.5 With a polka dot texture, I get: Here's the same object without the texture applied: The issue I'm particuarly looking at (I know there's a few) is the misalignment of the textures. I am inclined to believe the issue resides in my use of those algorithms, as the specular highlighting (which doesn't utilise any textures but does rely on the normals being correct) appears to have no artifacts. Any ideas?

    Read the article

  • Use only alpha channel of texture in OpenGL?

    - by Chris
    Hey, I'm trying to draw a constant color to the framebuffer and blend it using the alpha channel from an RGBA texture. I've been looking at glBlendFunc and glBlendColor, but can't seem to figure out a way to ignore the RGB values from the texture. I'm thinking I'll have to pull out the alpha values myself and make a second texture with GL_ALPHA. Is there a better way to do this? Thanks!

    Read the article

  • Change texture opacity in OpenGL

    - by zoul
    Hello! This is hopefully a simple question: I have an OpenGL texture and would like to be able to change its opacity, how do I do that? The texture already has an alpha channel and blending works fine, but I want to be able to decrease the opacity of the whole texture, to fade it into the background. I have fiddled with glBlendFunc, but with no luck – it seems that I would need something like GL_SRC_ALPHA_MINUS_CONSTANT, which is not available. I am working on iPhone, with OpenGL ES.

    Read the article

  • [C] Texture management / pointer question

    - by ndg
    I'm working on a texture management and animation solution for a small side project of mine. Although the project uses Allegro for rendering and input, my question mostly revolves around C and memory management. I wanted to post it here to get thoughts and insight into the approach, as I'm terrible when it comes to pointers. Essentially what I'm trying to do is load all of my texture resources into a central manager (textureManager) - which is essentially an array of structs containing ALLEGRO_BITMAP objects. The textures stored within the textureManager are mostly full sprite sheets. From there, I have an anim(ation) struct, which contains animation-specific information (along with a pointer to the corresponding texture within the textureManager). To give you an idea, here's how I setup and play the players 'walk' animation: createAnimation(&player.animations[0], "media/characters/player/walk.png", player.w, player.h); playAnimation(&player.animations[0], 10); Rendering the animations current frame is just a case of blitting a specific region of the sprite sheet stored in textureManager. For reference, here's the code for anim.h and anim.c. I'm sure what I'm doing here is probably a terrible approach for a number of reasons. I'd like to hear about them! Am I opening myself to any pitfalls? Will this work as I'm hoping? anim.h #ifndef ANIM_H #define ANIM_H #define ANIM_MAX_FRAMES 10 #define MAX_TEXTURES 50 struct texture { bool active; ALLEGRO_BITMAP *bmp; }; struct texture textureManager[MAX_TEXTURES]; typedef struct tAnim { ALLEGRO_BITMAP **sprite; int w, h; int curFrame, numFrames, frameCount; float delay; } anim; void setupTextureManager(void); int addTexture(char *filename); int createAnimation(anim *a, char *filename, int w, int h); void playAnimation(anim *a, float delay); void updateAnimation(anim *a); #endif anim.c void setupTextureManager() { int i = 0; for(i = 0; i < MAX_TEXTURES; i++) { textureManager[i].active = false; } } int addTextureToManager(char *filename) { int i = 0; for(i = 0; i < MAX_TEXTURES; i++) { if(!textureManager[i].active) { textureManager[i].bmp = al_load_bitmap(filename); textureManager[i].active = true; if(!textureManager[i].bmp) { printf("Error loading texture: %s", filename); return -1; } return i; } } return -1; } int createAnimation(anim *a, char *filename, int w, int h) { int textureId = addTextureToManager(filename); if(textureId > -1) { a->sprite = textureManager[textureId].bmp; a->w = w; a->h = h; a->numFrames = al_get_bitmap_width(a->sprite) / w; printf("Animation loaded with %i frames, given resource id: %i\n", a->numFrames, textureId); } else { printf("Texture manager full\n"); return 1; } return 0; } void playAnimation(anim *a, float delay) { a->curFrame = 0; a->frameCount = 0; a->delay = delay; } void updateAnimation(anim *a) { a->frameCount ++; if(a->frameCount >= a->delay) { a->frameCount = 0; a->curFrame ++; if(a->curFrame >= a->numFrames) { a->curFrame = 0; } } }

    Read the article

  • Texture repeats even with GL_CLAMP_TO_EDGE set

    - by Lliane
    Hi, i'm trying to put a translucing texture on a face which uses points 1 to 4 (don't mind the numbers) on the following screenshot Sadly as you can see the texture repeats herself in both dimensions, I tried to switch the TEXTURE_WRAP_S from REPEAT to CLAMP_to_EDGE but it doesn't change anything. Texture loading code is here : gl.glBindTexture(gl.GL_TEXTURE_2D, mTexture.get(4)); gl.glActiveTexture(4); gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, shadowbmp.width, shadowbmp.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_SHORT_4_4_4_4, shadowbmp.buffer); Texture coordinates are the following : float shadow_bot_text[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; Thanks

    Read the article

  • Texture repeats even with GL_CLAMP_TO_EDGE set [FIXED]

    - by Lliane
    Hi, i'm trying to put a translucing texture on a face which uses points 1 to 4 (don't mind the numbers) on the following screenshot Sadly as you can see the texture repeats herself in both dimensions, I tried to switch the TEXTURE_WRAP_S from REPEAT to CLAMP_to_EDGE but it doesn't change anything. Texture loading code is here : gl.glBindTexture(gl.GL_TEXTURE_2D, mTexture.get(4)); gl.glActiveTexture(4); gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, shadowbmp.width, shadowbmp.height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_SHORT_4_4_4_4, shadowbmp.buffer); Texture coordinates are the following : float shadow_bot_text[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f }; Thanks

    Read the article

  • XNA Xbox 360 Content Manager Thread freezing Draw Thread

    - by Alikar
    I currently have a game that takes in large images, easily bigger than 1MB, to serve as backgrounds. I know exactly when this transition is supposed to take place, so I made a loader class to handle loading these large images in the background, but when I load the images it still freezes the main thread where the drawing takes place. Since this code runs on the 360 I move the thread to the 4th hardware thread, but that doesn't seem to help. Below is the class I am using. Any thoughts as to why my new content manager which should be in its own thread is interrupting the draw in my main thread would be appreciated. namespace FileSystem { /// <summary> /// This is used to reference how many objects reference this texture. /// Everytime someone references a texture we increase the iNumberOfReferences. /// When a class calls remove on a specific texture we check to see if anything /// else is referencing the class, if it is we don't remove it. If there isn't /// anything referencing the texture its safe to dispose of. /// </summary> class TextureContainer { public uint uiNumberOfReferences = 0; public Texture2D texture; } /// <summary> /// This class loads all the files from the Content. /// </summary> static class FileManager { static Microsoft.Xna.Framework.Content.ContentManager Content; static EventWaitHandle wh = new AutoResetEvent(false); static Dictionary<string, TextureContainer> Texture2DResourceDictionary; static List<Texture2D> TexturesToDispose; static List<String> TexturesToLoad; static int iProcessor = 4; private static object threadMutex = new object(); private static object Texture2DMutex = new object(); private static object loadingMutex = new object(); private static bool bLoadingTextures = false; /// <summary> /// Returns if we are loading textures or not. /// </summary> public static bool LoadingTexture { get { lock (loadingMutex) { return bLoadingTextures; } } } /// <summary> /// Since this is an static class. This is the constructor for the file loadeder. This is the version /// for the Xbox 360. /// </summary> /// <param name="_Content"></param> public static void Initalize(IServiceProvider serviceProvider, string rootDirectory, int _iProcessor ) { Content = new Microsoft.Xna.Framework.Content.ContentManager(serviceProvider, rootDirectory); Texture2DResourceDictionary = new Dictionary<string, TextureContainer>(); TexturesToDispose = new List<Texture2D>(); iProcessor = _iProcessor; CreateThread(); } /// <summary> /// Since this is an static class. This is the constructor for the file loadeder. /// </summary> /// <param name="_Content"></param> public static void Initalize(IServiceProvider serviceProvider, string rootDirectory) { Content = new Microsoft.Xna.Framework.Content.ContentManager(serviceProvider, rootDirectory); Texture2DResourceDictionary = new Dictionary<string, TextureContainer>(); TexturesToDispose = new List<Texture2D>(); CreateThread(); } /// <summary> /// Creates the thread incase we wanted to set up some parameters /// Outside of the constructor. /// </summary> static public void CreateThread() { Thread t = new Thread(new ThreadStart(StartThread)); t.Start(); } // This is the function that we thread. static public void StartThread() { //BBSThreadClass BBSTC = (BBSThreadClass)_oData; FileManager.Execute(); } /// <summary> /// This thread shouldn't be called by the outside world. /// It allows the File Manager to loop. /// </summary> static private void Execute() { // Make sure our thread is on the correct processor on the XBox 360. #if WINDOWS #else Thread.CurrentThread.SetProcessorAffinity(new int[] { iProcessor }); Thread.CurrentThread.IsBackground = true; #endif // This loop will load textures into ram for us away from the main thread. while (true) { wh.WaitOne(); // Locking down our data while we process it. lock (threadMutex) { lock (loadingMutex) { bLoadingTextures = true; } bool bContainsKey = false; for (int con = 0; con < TexturesToLoad.Count; con++) { // If we have already loaded the texture into memory reference // the one in the dictionary. lock (Texture2DMutex) { bContainsKey = Texture2DResourceDictionary.ContainsKey(TexturesToLoad[con]); } if (bContainsKey) { // Do nothing } // Otherwise load it into the dictionary and then reference the // copy in the dictionary else { TextureContainer TC = new TextureContainer(); TC.uiNumberOfReferences = 1; // We start out with 1 referece. // Loading the texture into memory. try { TC.texture = Content.Load<Texture2D>(TexturesToLoad[con]); // This is passed into the dictionary, thus there is only one copy of // the texture in memory. // There is an issue with Sprite Batch and disposing textures. // This will have to wait until its figured out. lock (Texture2DMutex) { bContainsKey = Texture2DResourceDictionary.ContainsKey(TexturesToLoad[con]); Texture2DResourceDictionary.Add(TexturesToLoad[con], TC); } // We don't have the find the reference to the container since we // already have it. } // Occasionally our texture will already by loaded by another thread while // this thread is operating. This mainly happens on the first level. catch (Exception e) { // If this happens we don't worry about it since this thread only loads // texture data and if its already there we don't need to load it. } } Thread.Sleep(100); } } lock (loadingMutex) { bLoadingTextures = false; } } } static public void LoadTextureList(List<string> _textureList) { // Ensuring that we can't creating threading problems. lock (threadMutex) { TexturesToLoad = _textureList; } wh.Set(); } /// <summary> /// This loads a 2D texture which represents a 2D grid of Texels. /// </summary> /// <param name="_textureName">The name of the picture you wish to load.</param> /// <returns>Holds the image data.</returns> public static Texture2D LoadTexture2D( string _textureName ) { TextureContainer temp; lock (Texture2DMutex) { bool bContainsKey = false; // If we have already loaded the texture into memory reference // the one in the dictionary. lock (Texture2DMutex) { bContainsKey = Texture2DResourceDictionary.ContainsKey(_textureName); if (bContainsKey) { temp = Texture2DResourceDictionary[_textureName]; temp.uiNumberOfReferences++; // Incrementing the number of references } // Otherwise load it into the dictionary and then reference the // copy in the dictionary else { TextureContainer TC = new TextureContainer(); TC.uiNumberOfReferences = 1; // We start out with 1 referece. // Loading the texture into memory. try { TC.texture = Content.Load<Texture2D>(_textureName); // This is passed into the dictionary, thus there is only one copy of // the texture in memory. } // Occasionally our texture will already by loaded by another thread while // this thread is operating. This mainly happens on the first level. catch(Exception e) { temp = Texture2DResourceDictionary[_textureName]; temp.uiNumberOfReferences++; // Incrementing the number of references } // There is an issue with Sprite Batch and disposing textures. // This will have to wait until its figured out. Texture2DResourceDictionary.Add(_textureName, TC); // We don't have the find the reference to the container since we // already have it. temp = TC; } } } // Return a reference to the texture return temp.texture; } /// <summary> /// Go through our dictionary and remove any references to the /// texture passed in. /// </summary> /// <param name="texture">Texture to remove from texture dictionary.</param> public static void RemoveTexture2D(Texture2D texture) { foreach (KeyValuePair<string, TextureContainer> pair in Texture2DResourceDictionary) { // Do our references match? if (pair.Value.texture == texture) { // Only one object or less holds a reference to the // texture. Logically it should be safe to remove. if (pair.Value.uiNumberOfReferences <= 1) { // Grabing referenc to texture TexturesToDispose.Add(pair.Value.texture); // We are about to release the memory of the texture, // thus we make sure no one else can call this member // in the dictionary. Texture2DResourceDictionary.Remove(pair.Key); // Once we have removed the texture we don't want to create an exception. // So we will stop looking in the list since it has changed. break; } // More than one Object has a reference to this texture. // So we will not be removing it from memory and instead // simply marking down the number of references by 1. else { pair.Value.uiNumberOfReferences--; } } } } /*public static void DisposeTextures() { int Count = TexturesToDispose.Count; // If there are any textures to dispose of. if (Count > 0) { for (int con = 0; con < TexturesToDispose.Count; con++) { // =!THIS REMOVES THE TEXTURE FROM MEMORY!= // This is not like a normal dispose. This will actually // remove the object from memory. Texture2D is inherited // from GraphicsResource which removes it self from // memory on dispose. Very nice for game efficency, // but "dangerous" in managed land. Texture2D Temp = TexturesToDispose[con]; Temp.Dispose(); } // Remove textures we've already disposed of. TexturesToDispose.Clear(); } }*/ /// <summary> /// This loads a 2D texture which represnets a font. /// </summary> /// <param name="_textureName">The name of the font you wish to load.</param> /// <returns>Holds the font data.</returns> public static SpriteFont LoadFont( string _fontName ) { SpriteFont temp = Content.Load<SpriteFont>( _fontName ); return temp; } /// <summary> /// This loads an XML document. /// </summary> /// <param name="_textureName">The name of the XML document you wish to load.</param> /// <returns>Holds the XML data.</returns> public static XmlDocument LoadXML( string _fileName ) { XmlDocument temp = Content.Load<XmlDocument>( _fileName ); return temp; } /// <summary> /// This loads a sound file. /// </summary> /// <param name="_fileName"></param> /// <returns></returns> public static SoundEffect LoadSound( string _fileName ) { SoundEffect temp = Content.Load<SoundEffect>(_fileName); return temp; } } }

    Read the article

  • How to programmatically alpha fade a textured object in OpenGL ES 1.1 (iPhone)

    - by PewterSoft
    I've been using OpenGL ES 1.1 on the iPhone for 10 months, and in that time there is one seemingly simple task I have been unable to do: programmatically fade a textured object. To keep it simple: how can I alpha fade, under code control, a simple 2D triangle that has a texture (with alpha) applied to it. I would like to fade it in/out while it is over a scene, not a simple colored background. So far the only technique I have to do this is to create a texture with multiple pre-faded copies of the texture on it. (Yuck) As an example, I am unable to do this using Apple's GLSprite sample code as a starting point. It already textures a quad with a texture that has its own alpha. I would like to fade that object in and out.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >