Search Results

Search found 1811 results on 73 pages for 'alpha blending'.

Page 1/73 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Incorrect colour blending when using a pixel shader with XNA

    - by MazK
    I'm using XNA 4.0 to create a 2D game and while implementing a layer tinting pixel shader I noticed that when the texture's alpha value is anything between 1 or 0 the end result is different than expected. The tinting works from selecting a colour and setting the amount of tint. This is achieved via the shader which works out first the starting colour (for each r, g, b and a) : float red = texCoord.r * vertexColour.r; and then the final tinted colour : output.r = red + (tintColour.r - red) * tintAmount; The alpha value isn't tinted and is left as : output.a = texCoord.a * vertexColour.a; The picture in the link below shows different backdrops against an energy ball object where it's outer glow hasn't blended as I would like it to. The middle two are incorrect as the second non tinted one should not show a glow against a white BG and the third should be entirely invisible. The blending function is NonPremultiplied. Why the alpha value is interfering with the final colour?

    Read the article

  • OpenGL ES Shader help (Blending)

    - by Chris
    Earlier I required assistance getting to grips with how to retain the alpha channel of a transparent texture in my colourised texture shader program. Whilst playing with that first version of my program (before obtaining the solution to my first requirement), I managed to enable transparency for the whole texture (effectively blending via GLSL), and I quite liked this, and I would now like to know if and how it is possible to retain this blending effect, on top of the existing output without affecting the original alpha channel - as I don't know how to input this transparency via the parameter that is already being provided with the textures alpha channel. A basic example of the blending program I am referring to (minus any other functionality) is as follows... varying vec2 texCoord; uniform sampler2D texSampler; void main() { gl_FragColor = vec4(texture2D(texSampler,texCoord).xyz,0.5); } Where 0.5 is the transparency (blending effect) of the whole texture. This is the current version of my program, which provides the ability to colour a texture according the colour parameter passed to the program, and retains the alpha channel of the original texture. varying vec2 texCoord; uniform sampler2D texSampler; uniform vec3 colour; void main() { gl_FragColor = vec4(colour,1) * vec4(texture2D(texSampler,texCoord).xyz,texture2D(texSampler,texCoord).w); } I need to know if it is possible to apply transparency on top this program, without affecting the original alpha channel which I have already preserved. I hope this makes enough sense, I am sure it is possible, and if so I should imagine it is rather simple, but this has me stumped. Any help much appreachiated. Cheers, Chris

    Read the article

  • Per-pixel per-component alpha blending in Windows

    - by Crend King
    I have a 24-bit bitmaps with R, G, B color channels and a 24-bit bitmap with R, G, B alpha channels. I want to alpha blend the first bitmap to a HDC in GDI or RenderTarget in Direct2D with the alpha channels respectively. For example, suppose for one pixel, the bitmap color is (192, 192, 192), the HDC color is (0, 255, 255) and the alpha channels are (30, 40, 50). The final HDC color should be (22, 245, 242). I know I can BitBlt the HDC to a memory HDC first, do alpha blending by manually calculating the color of each pixel and finally BitBlt back. I just want to avoid the additional blitting and leave APIs do their job (faster since they are in kernel space). The first idea comes to my mind is to split the source bitmap into 3 red-only, green-only and blue-only 8-bit bitmaps, do normal alpha blending, then composite the 3 output bitmaps into the HDC. But I don't find a way to do the splitting and composition natively in Windows (would Direct2D layer help?). Also, the splitting and compositing may require many additional copying. The performance overhead would be too high. Or maybe do the alpha blending in 3 passes. Each pass apply the blending for one channel, while maintaining the other 2 unchanged. Thanks for any comment. EDIT: I found this question, and the answer should be good reference to this problem. However, besides AC_SRC_OVER, there is no other blending operation supported. Why don't Microsoft improve their API?

    Read the article

  • Understanding how OpenGL blending works

    - by yuumei
    I am attempting to understand how OpenGL (ES) blending works. I am finding it difficult to understand the documentation and how the results of glBlendFunc and glBlendEquation effect the final pixel that is written. Do the source and destination out of glBlendFunc get added together with GL_FUNC_ADD by default? This seems wrong because "basic" blending of GL_ONE, GL_ONE would output 2,2,2,2 then (Source giving 1,1,1,1 and dest giving 1,1,1,1). I have written the following pseudo-code, what have I got wrong? struct colour { float r, g, b, a; }; colour blend_factor( GLenum factor, colour source, colour destination, colour blend_colour ) { colour colour_factor; float i = min( source.a, 1 - destination.a ); // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml switch( factor ) { case GL_ZERO: colour_factor = { 0, 0, 0, 0 }; break; case GL_ONE: colour_factor = { 1, 1, 1, 1 }; break; case GL_SRC_COLOR: colour_factor = source; break; case GL_ONE_MINUS_SRC_COLOR: colour_factor = { 1 - source.r, 1 - source.g, 1 - source.b, 1 - source.a }; break; // ... } return colour_factor; } colour blend( colour & source, colour destination, GLenum source_factor, // from glBlendFunc GLenum destination_factor, // from glBlendFunc colour blend_colour, // from glBlendColor GLenum blend_equation // from glBlendEquation ) { colour source_colour = blend_factor( source_factor, source, destination, blend_colour ); colour destination_colour = blend_factor( destination_factor, source, destination, blend_colour ); colour output; // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendEquation.xml switch( blend_equation ) { case GL_FUNC_ADD: output = add( source_colour, destination_colour ); case GL_FUNC_SUBTRACT: output = sub( source_colour, destination_colour ); case GL_FUNC_REVERSE_SUBTRACT: output = sub( destination_colour, source_colour ); } return output; } void do_pixel() { colour final_colour; // Blending if( enable_blending ) { final_colour = blend( current_colour_output, framebuffer[ pixel ], ... ); } else { final_colour = current_colour_output; } } Thanks!

    Read the article

  • how to properly implement alpha blending in a complex 3d scene

    - by Gajet
    I know this question might sound a bit easy to answer but It's driving me crazy. There are too many possible situations that a good alpha blending mechanism should handle, and for each Algorithm I can think of there is something missing. these are the methods I've though about so far: first of I though about object sorting by depth, this one simply fails because Objects are not simple shapes, they might have curves and might loop inside each other. so I can't always tell which one is closer to camera. then I thought about sorting triangles but this one also might fail, thought I'm not sure how to implement it there is a rare case that might again cause problem, in which two triangle pass through each other. again no one can tell which one is nearer. the next thing was using depth buffer, at least the main reason we have depth buffer is because of the problems with sorting that I mentioned but now we get another problem. Since objects might be transparent, in a single pixel there might be more than one object visible. So for which Object should I store pixel depth? I then thought maybe I can only store the most front Object depth, and using that determine how should I blend next draw calls at that pixel. But again there was a problem, think about 2 semi transparent planes with a solid plane in middle of them. I was going to render the solid plane at the end, one can see the most distant plane. note that I was going to merge every two planes until there is only one color left for that pixel. Obviously I can use sorting methods too because of the same reasons I've explained above. Finally the only thing I imagine being able to work is to render all objects into different render targets and then sort those layers and display the final output. But this time I don't know how can I implement this algorithm.

    Read the article

  • Blending textures together, texture fade over / fade in

    - by Deukalion
    What is the best way to render a texture overlapping effect? Like in this example: I want either the grass to fade in to the snow texture, or the other way around. No rough edges. Somehow make them blend over. So the grass has a bit of snow or the snow has a bit of grass How is this possible during runtime? If that's possible. I don't render this by using the SpriteBatch, since the ground isn't rectangles (they can be moved). This is the way I render each shape (each one of those squares): // LoadTexture // Apply EffectPass device.DrawUserIndexedPrimitives<VertexPositionNormalTexture> ( PrimitiveType.TriangleList, render.Item.Points, // Array of VertexPositionNormalTexture 0, render.Item.Points.Length, render.Item.Indexes, // Array of int indexes (triangulation) 0, render.Item.Indexes.Length / 3, VertexPositionNormalTexture.VertexDeclaration );

    Read the article

  • Z-order with Alpha blending in a 3D world

    - by user41765
    I'm working on a game in a 3D world with 2D sprites only (like Don't Starve game). (OpenGL ES2 with C++) Currently, I'm ordering elements back to front before drawing them without batch (so 1 element = 1 drawcall). I would like to implement batching in my framework to decrease draw calls. Here is what I've got for the moment: Order all elements of my scene back to front. Send order list of elements to the Renderer. Renderer look in his batch manager if a batch exist for the given element with his Material. Batch didn't exist: create a new one. Batch exist for element with this Material: Add sprite to the batch. Compute big mesh with all sprite for each batch (1 material type = 1 batch). When all batches are ok, the batch manager compute draw commands for the renderer. Renderer process draw commands (bind shader, bind textures, bind buffers, draw element) Image with my problem here: Explication here But I've got some problems because objects can be behind another objects inside another batch. How can I do something like that? Thanks!

    Read the article

  • Alpha issue with SharpDX SpriteBatch in WPF

    - by Kingdom
    .Hi devs, I'm coding a game using SharpDX in a WPF context. void Load() { sb = new SpriteBatch(GraphicsDevice); t2d = Content.Load<Texture2D>("Sprite.png"); } void Draw() { sb.Begin(); sb.Draw(t2d, new Rectangle(0, 0, 64, 64), Color.White); sb.End(); } I made Sprite.png, an object with pink color (alpha = 0%) for the background. The output show me my object but with the pink square at more or less 50% rate! So if I try to draw more sprites, it's like a little poney dream. Note If I apply Color.Black on the Draw method, the sprite is like expected :|

    Read the article

  • Convert a gray PNG with alpha to a 1-bit black rectanble with 8-bit alpha

    - by jcayzac
    I use a tool to render LaTeX equations as PNG. The resulting images are in RGBA8888 format. I would like to extract the luminance (grayscale from RGB channels, multiplied by the A channel) as my new alpha channel, set the picture fully black, and save the result in Gray1Alpha8 (G1A8) format. So far I've only managed to get G1A4 or G8A8 but not G1A8. Also, the resulting picture looks like it's not multiplied correctly… convert original.png \ \( -clone 0 -alpha extract \) \ \( -clone 0 -clone 1 -compose multiply -composite \) \ -delete 0 +swap -alpha off -compose copy_opacity -composite -colorspace Gray -depth 4 result.png What am I missing?

    Read the article

  • How can I make a 32 bit render target with a 16 bit alpha channel in DirectX?

    - by J Junker
    I want to create a render target that is 32-bit, with 16 bits each for alpha and luminance. The closest surface formats I can find in the DirectX SDK are: D3DFMT_A8L8 // 16-bit using 8 bits each for alpha and luminance. D3DFMT_G16R16F // 32-bit float format using 16 bits for the red channel and 16 bits for the green channel. But I don't think either of these will work, since D3DFMT_A8L8 doesn't have the precision and D3DFMT_G16R16F doesn't have an alpha channel (I need a separate blend state for alpha). How can I create a render target that allows a separate blend state for luminance and alpha, with 16 bit precision on each channel, that doesn't exceed 32 bits per pixel?

    Read the article

  • Alpha plugin in GStreamer not working

    - by Miguel Escriva
    Hi! I'm trying to compose two videos, and I'm using the alpha plug-in to make the white color transparent. To test the alpha plug-in I'm creating the pipeline with gst-launch. The first test I done was: gst-launch videotestsrc pattern=smpte75 \ ! alpha method=custom target-r=255 target-g=255 target-b=255 angle=10 \ ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink \ videotestsrc pattern=snow ! mixer. and it works great! Then I created two videos with those lines: gst-launch videotestsrc pattern=snow ! ffmpegcolorspace ! theoraenc ! oggmux ! filesink location=snow.ogv gst-launch videotestsrc pattern=smpte75 ! ffmpegcolorspace ! theoraenc ! oggmux ! filesink location=bars75.ogv And changed the videotestsrc to a filesrc and it continues working gst-launch filesrc location=bars75.ogv ! decodebin2 \ ! alpha method=custom target-r=255 target-g=255 target-b=255 angle=10 \ ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink \ filesrc location=snow.ogv ! decodebin2 ! alpha ! mixer. But, when I use the ideo I want to compose, I'm not able to make the white color transparent gst-launch filesrc location=video.ogv ! decodebin2 \ ! alpha method=custom target-r=255 target-g=255 target-b=255 angle=10 \ ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink \ filesrc location=snow.ogv ! decodebin2 ! alpha ! mixer. Can you help me? Any idea what is happening? I'm using GStreamer 0.10.28 You can download the test videos from here: http://polimedia.upv.es/pub/gst/gst.zip Thanks in advance, Miguel Escriva

    Read the article

  • Point sample opacity/alpha in Adobe Photoshop?

    - by Josh
    I opened a PNG containing an alpha channel in Photoshop and wanted to get the opacity / alpha of a given point in the PNG file, so that I could match that opacity in a new photoshop layer. How can I do this? is there any way to get an alpha value at a point the way the color sample tool gives RGB values at a given point?

    Read the article

  • Convert TIFF with Alpha Channel to PNG?

    - by Michael Stum
    I have a TIFF File that has a blue background and an Alpha Channel. I would like to save a PNG File which has the blue background transparent, using the Alpha Channel (because some pixels are not fully transparent) I use Photoshop CS5 Standard, but I haven't found an option there. I don't want to use the Magic Wand because it struggles with half-transparent pixels and because I do have a perfect Alpha Channel. Any ideas how this can be done?

    Read the article

  • D3D9 Alpha Blending on the surfaces

    - by Indeera
    I have a surface (OffScreenPlain or RenderTarget with D3DFMT_A8R8G8B8) which I copy pixels (ARGB) to, from a third party function. Before pixel copying, Bits are accessed by LockRect. This surface is then StretchRect to the Backbuffer which is (D3DFMT_A8R8G8B8). Surface and Backbuffer are different dimensions. Filtering is set to D3DTEXF_NONE. Just after creating the d3d device I've set following RenderState settings D3DRS_ALPHABLENDENABLE -> TRUE D3DRS_BLENDOP -> D3DBLENDOP_ADD D3DRS_SRCBLEND -> D3DBLEND_SRCALPHA D3DRS_DESTBLEND -> D3DBLEND_INVSRCALPHA But I see no alpha blending happening. I've verified that alpha is specified in pixels. I've done a simple test by creating a vertex buffer and drawing a triangle (DrawPrimitive) which displays with alpha blending. In this test surface was StretchRect first and then DrawPrimitive, and the surface content displays without alpha blending and the triangle displays with alpha blending. What am I missing here? Thanks

    Read the article

  • Preserving alpha issues with loaded UIImages - how to avoid discarding alpha values on import?

    - by Peter Hajas
    My application lets the user save/load images with alpha values to the camera roll on the device. I can see in the Photos application that these images are appropriately alpha'd, as alpha'd areas just appear black. However, when I load these images back into the application using the valueForKey:UIImagePickerControllerOriginalImage message to the info dictionary from (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info, the alpha values are turned to just white, making those sections opaque. Is there a way to preserve these alpha values?

    Read the article

  • When is a webapp called Beta, alpha, pre-alpha, or none

    - by dmontain
    I've come across many apps on the web that call themselves Beta. I've come across other apps that had an alpha designation. I've even come across some that called themselves pre-alpha, whatever that means (if you know please clarify). Then I've come across some really bad webapps that shouldn't have left the developer's computer and they didn't have any beta designations. I've also seen some well built apps that called themselves Beta, including Stack Exchange (the mother site of SO) which I believe is very full featured to be called a Beta. I'm a little confused. It seems people are doing it at their whims. Is there an established rule or a checklist that can help decide what stage an app is in (beta, alpha, pre-alpha, or none)? P.S. Please feel free to retag as appropriate.

    Read the article

  • Jlabel with alpha value

    - by jouzef19
    Hi: i have jLabel and i want to change its opacity (alpha value) each one second , i tried something like that but its not change each one second , jlable change its opacity with last alpha value . Color color = jLabel1.getBackground(); int alpha = 255; long initTime = System.currentTimeMillis(); while(true){ if(System.currentTimeMillis() - initTime >= 1000){ initTime = System.currentTimeMillis(); alpha -=1; Color color2 = new Color(color.getRed(),color.getGreen(),color.getBlue(),alpha); jLabel1.setBackground(color2); } if(alpha<=0) break; }

    Read the article

  • Controlling the alpha of a UIImageView with Slider ..Can' t get it

    - by user1824839
    first i' d like to say this Forum was really helpfull for me that just started coding some weeks ago .. I succeed to do a quite nice app for the moment , than, but i m stuck on this : HOW COULD I CONTROL THE ALPHA OF A UIIMAGEVIEW , WITH A SLIDER EMBEDED IN ANOTHER VIEW ??? ; Basically i' like to do like the alpha slider of this : http://www.edumobile.org/iphone/how-to-make-an-app-2/controlling-a-uiviews-properties-for-ipad/ , but for a UIImageView. I promised i searched for hours , and didnt find how to do it ... Could someone have some minutes to give me ideas ?? Sorry for my poor english too. Thanks if you can. L. The resume of the link i posted, only focussing on the alpha property would be : ( considering a UIView ( View ) embeded in a ViewController ( ViewController ): enter code here ----View.h----- @interface View : UIView @property ( nonatomic, assign ) CGFloat alpha; @end enter code here ----View.m---- @implementation View @synthesize alpha; ?} @end enter code here ------ViewController.h----- import "View.h" @interface ViewController : UIViewController @property (nonatomic, strong) IBOutlet View *view; ?- (IBAction)alphaChanged:(UISlider *)sender; @end enter code here -------ViewController.m------ @interface ViewController () @end @implementation ViewController @synthesize view; (View *)view {?     if (!view) {?        view = [[View alloc] init];?    }?    return view;?} enter code here (IBAction)redChanged:(UISlider *)sender? {?    self.circle.alpha = sender.value;?    [self.circle setNeedsDisplay];?} (void)viewDidLoad ?{?    [super viewDidLoad];?         ?    self.circle.alpha = (CGFloat)1;?} (void)didReceiveMemoryWarning? {?  [super didReceiveMemoryWarning];?    @end enter code here

    Read the article

  • Alpha plugin in GStreamer not working

    - by Miguel Escriva
    Hi! I'm trying to compose two videos, and I'm using the alpha plug-in to make the white color transparent. To test the alpha plug-in I'm creating the pipeline with gst-launch. The first test I done was: gst-launch videotestsrc pattern=smpte75 \ ! alpha method=custom target-r=255 target-g=255 target-b=255 angle=10 \ ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink \ videotestsrc pattern=snow ! mixer. and it works great! Then I created two videos with those lines: gst-launch videotestsrc pattern=snow ! ffmpegcolorspace ! theoraenc ! oggmux ! filesink location=snow.ogv gst-launch videotestsrc pattern=smpte75 ! ffmpegcolorspace ! theoraenc ! oggmux ! filesink location=bars75.ogv And changed the videotestsrc to a filesrc and it continues working gst-launch filesrc location=bars75.ogv ! decodebin2 \ ! alpha method=custom target-r=255 target-g=255 target-b=255 angle=10 \ ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink \ filesrc location=snow.ogv ! decodebin2 ! alpha ! mixer. But, when I use the ideo I want to compose, I'm not able to make the white color transparent gst-launch filesrc location=video.ogv ! decodebin2 \ ! alpha method=custom target-r=255 target-g=255 target-b=255 angle=10 \ ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink \ filesrc location=snow.ogv ! decodebin2 ! alpha ! mixer. Can you help me? Any idea what is happening? I'm using GStreamer 0.10.28 You can download the test videos from here: http://polimedia.upv.es/pub/gst/gst.zip Thanks in advance, Miguel Escriva

    Read the article

  • Blending pixels from Two Bitmaps

    - by MarkPowell
    I'm beating my head against a wall here, and I'm fairly certain I'm doing something stupid, so time to make my stupidity public. I'm trying to take two images, blend them together into a third image using standard blending algorithms (Hardlight, softlight, overlay, multiply, etc). Because Android does not have such blend properties build in, I've gone down the path of taking each pixel and combine them using an algorithm. However, the results are garbage. Any help would be appreciated. Below is the code, which I've tried to strip out all the "junk", but some may have made it through. I'll clean it up if something isn't clear. Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.base, options); Bitmap mutableBitmap = src.copy(Bitmap.Config.RGB_565, true); int imageId = getResources().getIdentifier("drawable/" + filter, null, getPackageName()); Bitmap filterBitmap = BitmapFactory.decodeResource(getResources(), imageId, options); float scaleWidth = ((float) mutableBitmap.getWidth()) / filterBitmap.getWidth(); float scaleHeight = ((float) mutableBitmap.getHeight()) / filterBitmap.getHeight(); IntBuffer buffSrc = IntBuffer.allocate(src.getWidth() * src.getHeight()); mutableBitmap.copyPixelsToBuffer(buffSrc); buffSrc.rewind(); IntBuffer buffFilter = IntBuffer.allocate(resizedFilterBitmap.getWidth() * resizedFilterBitmap.getHeight()); resizedFilterBitmap.copyPixelsToBuffer(buffFilter); buffFilter.rewind(); IntBuffer buffOut = IntBuffer.allocate(src.getWidth() * src.getHeight()); buffOut.rewind(); while (buffOut.position() < buffOut.limit()) { int filterInt = buffFilter.get(); int srcInt = buffSrc.get(); int alphaValueFilter = Color.alpha(filterInt); int redValueFilter = Color.red(filterInt); int greenValueFilter = Color.green(filterInt); int blueValueFilter = Color.blue(filterInt); int alphaValueSrc = Color.alpha(srcInt); int redValueSrc = Color.red(srcInt); int greenValueSrc = Color.green(srcInt); int blueValueSrc = Color.blue(srcInt); int alphaValueFinal = convert(alphaValueFilter, alphaValueSrc); int redValueFinal = convert(redValueFilter, redValueSrc); int greenValueFinal = convert(greenValueFilter, greenValueSrc); int blueValueFinal = convert(blueValueFilter, blueValueSrc); int pixel = Color.argb(alphaValueFinal, redValueFinal, greenValueFinal, blueValueFinal); buffOut.put(pixel); } buffOut.rewind(); mutableBitmap.copyPixelsFromBuffer(buffOut); BitmapDrawable drawable = new BitmapDrawable(getResources(), mutableBitmap); imageView.setImageDrawable(drawable); } int convert (int in1, int in2) { //simple multiply for example return in1 * in2 / 255; }

    Read the article

  • Detect Alpha Channel with ImageMagick

    - by brad
    Scenario I would like to save images with alpha transparency as .png and images without alpha transparency as .jpg (even if their original format is .png or .gif). How can I detect whether or not an image has alpha transparency using ImageMagick?

    Read the article

  • Alpha Beta Search

    - by Becky
    I'm making a version of Martian Chess in java with AI and so far I THINK my move searching is semi-working, it seems to work alright for some depths but if I use a depth of 3 it returns a move for the opposite side...now the game is a bit weird because when a piece crosses half of the board, it becomes property of the other player so I think this is part of the problem. I'd be really greatful if someone could look over my code and point out any errors you think are there! (pls note that my evaluation function isn't nearly complete lol) MoveSearch.java public class MoveSearch { private Evaluation evaluate = new Evaluation(); private int blackPlayerScore, whitePlayerScore; public MoveContent bestMove; public MoveSearch(int blackScore, int whiteScore) { blackPlayerScore = blackScore; whitePlayerScore = whiteScore; } private Vector<Position> EvaluateMoves(Board board) { Vector<Position> positions = new Vector<Position>(); for (int i = 0; i < 32; i++) { Piece piece = null; if (!board.chessBoard[i].square.isEmpty()) { // store the piece piece = board.chessBoard[i].square.firstElement(); } // skip empty squares if (piece == null) { continue; } // skip the other players pieces if (piece.pieceColour != board.whosMove) { continue; } // generate valid moves for the piece PieceValidMoves validMoves = new PieceValidMoves(board.chessBoard, i, board.whosMove); validMoves.generateMoves(); // for each valid move for (int j = 0; j < piece.validMoves.size(); j++) { // store it as a position Position move = new Position(); move.startPosition = i; move.endPosition = piece.validMoves.elementAt(j); Piece pieceAttacked = null; if (!board.chessBoard[move.endPosition].square.isEmpty()) { // if the end position is not empty, store the attacked piece pieceAttacked = board.chessBoard[move.endPosition].square.firstElement(); } // if a piece is attacked if (pieceAttacked != null) { // append its value to the move score move.score += pieceAttacked.pieceValue; // if the moving pieces value is less than the value of the attacked piece if (piece.pieceValue < pieceAttacked.pieceValue) { // score extra points move.score += pieceAttacked.pieceValue - piece.pieceValue; } } // add the move to the set of positions positions.add(move); } } return positions; } // EvaluateMoves() private int SideToMoveScore(int score, PieceColour colour) { if (colour == PieceColour.Black){ return -score; } else { return score; } } public int AlphaBeta(Board board, int depth, int alpha, int beta) { //int best = -9999; // if the depth is 0, return the score of the current board if (depth <= 0) { board.printBoard(); System.out.println("Score: " + evaluate.EvaluateBoardScore(board)); System.out.println(""); int boardScore = evaluate.EvaluateBoardScore(board); return SideToMoveScore(boardScore, board.whosMove); } // fill the positions with valid moves Vector<Position> positions = EvaluateMoves(board); // if there are no available positions if (positions.size() == 0) { // and its blacks move if (board.whosMove == PieceColour.Black) { if (blackPlayerScore > whitePlayerScore) { // and they are winning, return a high number return 9999; } else if (whitePlayerScore == blackPlayerScore) { // if its a draw, lower number return 500; } else { // if they are losing, return a very low number return -9999; } } if (board.whosMove == PieceColour.White) { if (whitePlayerScore > blackPlayerScore) { return 9999; } else if (blackPlayerScore == whitePlayerScore) { return 500; } else { return -9999; } } } // for each position for (int i = 0; i < positions.size(); i++) { // store the position Position move = positions.elementAt(i); // temporarily copy the board Board temp = board.copyBoard(board); // make the move temp.makeMove(move.startPosition, move.endPosition); for (int x = 0; x < 32; x++) { if (!temp.chessBoard[x].square.isEmpty()) { PieceValidMoves validMoves = new PieceValidMoves(temp.chessBoard, x, temp.whosMove); validMoves.generateMoves(); } } // repeat the process recursively, decrementing the depth int val = -AlphaBeta(temp, depth - 1, -beta, -alpha); // if the value returned is better than the current best score, replace it if (val >= beta) { // beta cut-off return beta; } if (val > alpha) { alpha = val; bestMove = new MoveContent(alpha, move.startPosition, move.endPosition); } } // return the best score return alpha; } // AlphaBeta() } This is the makeMove method public void makeMove(int startPosition, int endPosition) { // quick reference to selected piece and attacked piece Piece selectedPiece = null; if (!(chessBoard[startPosition].square.isEmpty())) { selectedPiece = chessBoard[startPosition].square.firstElement(); } Piece attackedPiece = null; if (!(chessBoard[endPosition].square.isEmpty())) { attackedPiece = chessBoard[endPosition].square.firstElement(); } // if a piece is taken, amend score if (!(chessBoard[endPosition].square.isEmpty()) && attackedPiece != null) { if (attackedPiece.pieceColour == PieceColour.White) { blackScore = blackScore + attackedPiece.pieceValue; } if (attackedPiece.pieceColour == PieceColour.Black) { whiteScore = whiteScore + attackedPiece.pieceValue; } } // actually move the piece chessBoard[endPosition].square.removeAllElements(); chessBoard[endPosition].addPieceToSquare(selectedPiece); chessBoard[startPosition].square.removeAllElements(); // changing piece colour based on position if (endPosition > 15) { selectedPiece.pieceColour = PieceColour.White; } if (endPosition <= 15) { selectedPiece.pieceColour = PieceColour.Black; } //change to other player if (whosMove == PieceColour.Black) whosMove = PieceColour.White; else if (whosMove == PieceColour.White) whosMove = PieceColour.Black; } // makeMove()

    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

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >