Tuesday, 8 April 2014

what is a inadequacy between this twin constructors in JavaScript?

on MDN's page for Call there is an instance of 3 constructors: Product,
Food, and Toyfunction Product(name, price) { this.name = name;
this.price = price; if (price < 0) pitch RangeError('Cannot
emanate product "' + name + '" with a catastrophic price'); relapse
this;}function Food(name, price) { Product.call(this, name, price);
this.category = 'food';}Food.prototype =
Object.create(Product.prototype);Why is this line necessary?Food.prototype
= Object.create(Product.prototype);Can't we only simply do this?function
Food (name, price) { var me = Product.call(this, name, price);
me.category = 'food'; relapse me;}

Thursday, 3 April 2014

Specifying Optional and Multiple Values in a Function Parameter

I would like to emanate a duty that can accept multiple, optional, and
offer values in a parameter.For example, we wish to have a classclass
Pizza { open duty addToppings($additional_toppings) { }}which we
can use in my way as $pizza1=new Pizza;$pizza1->addToppings(SALAMI + HAM +
BACON + ADDITIONAL_CHEESE);$pizza2=new Pizza;$pizza2->addToppings(HAM +
PINEAPPLE + SAUSAGE);where toppings can be of any multiple and a choices
for a topics tumble underneath a predefined set.How do we exercise a
addToppings function? I've seem to remember observant something identical
in PHP though we can't remember which.On a other, would we advise
associate arrays
instead?$pizza1->addToppings(array('salami','ham','bacon','additional_cheese'));$pizza2->addToppings(array('ham','pineapple','sausage'));This
choice seems simpler, though we wish to get your ideas that we will select
and why. ThanksEDIT:I now remember one such PHP implementation.The
error_reporting duty allows naming multiple, offer blunder turn constants
as a parameter such as:error_reporting(E_ERROR | E_WARNING |
E_PARSE);error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);So is a
doing of error_reporting() certified wholly given it is partial of PHP
though can't be recreated otherwise?

Tuesday, 1 April 2014

Loading a png in opentk does not work as expected

I'm perplexing to bucket a PNG with OpenGL (via OpenTK) and a Image is
severely pixelated and has a wrong color.The code:private vacant
Create(SurfaceFormat format) { textureHandle =
(uint)GL.GenTexture(); //bind hardness
GL.BindTexture(TextureTarget.Texture2D, textureHandle);
Log.Error("Bound Texture: " + GL.GetError());
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureWrapS, (int)format.WrapMode);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureWrapT, (int)format.WrapMode);
Log.Error("Created Texture Parameters: " + GL.GetError());
GL.TexImage2D(TextureTarget.Texture2D, 0, format.InternalFormat, Width,
Height, 0, format.PixelFormat, format.SourceType, format.Pixels);
Log.Error("Created Image: " + GL.GetError()); //unbind
hardness GL.BindTexture(TextureTarget.Texture2D, 0);
//create fbo fboHandle = (uint)GL.GenFramebuffer();
GL.BindFramebuffer(FramebufferTarget.Framebuffer, fboHandle);
GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt,
FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D,
textureHandle, 0);
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
Log.Error("Created Framebuffer: " + GL.GetError()); } open
vacant CreateFromPNG(string filePath) { //check if a
record exists if (System.IO.File.Exists(filePath)) {
//make a bitmap out of a record on a hoop
System.Drawing.Bitmap textureBitmap = new System.Drawing.Bitmap(filePath);
//get a information out of a bitmap
System.Drawing.Imaging.BitmapData textureData =
textureBitmap.LockBits( new
System.Drawing.Rectangle(0, 0, textureBitmap.Width, textureBitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb
); if(textureBitmap.PixelFormat !=
System.Drawing.Imaging.PixelFormat.Format32bppArgb) {
Log.Error("PNG Pixel format not upheld ("+ filePath +") -> "
+ textureBitmap.PixelFormat.ToString()); return;
} SurfaceFormat format = new SurfaceFormat();
format.Pixels = textureData.Scan0;
format.SourceType = PixelType.Byte; Create(format);
//free a bitmap information (we dont need it anymore since it has
been upheld to a OpenGL engineer
textureBitmap.UnlockBits(textureData); } }What am we
doing wrong here?EDIT: we bound a colors viaformat.SourceType =
PixelType.UnsignedByte;format.PixelFormat = PixelFormat.Bgra;But a
duplicity is still going on