Rendering image using texSubImage2D in Haxe - webgl

I am learning how to stamp an image onto my canvas using Haxe and I have read that texSubImage2D should be the function I need to do the job.
I have read some documentation found here and thought I could implement what I was after by completing the following params:
void gl.texSubImage2D(target, level, xoffset, yoffset, format, type, HTMLImageElement? pixels);
This is what I did:
gl.texSubImage2D (cast fluid.dyeRenderTarget.writeToTexture, 0, Math.round(mouse.x), Math.round(mouse.y), gl.RGB, gl.UNSIGNED_BYTE, document.querySelector('img[src="images/myImage.jpg"]'));
However, when I try to build the project, I am getting the following errors:
src/Main.hx:571: characters 135-191 : js.html.Element should be Int
src/Main.hx:571: characters 135-191 : For function argument 'format'
When I went back to the docs, the format I have passed gl.RGB is an accepted param, so I am not sure where I am going wrong.
Any guidance would be really appreciated.

I can't quite reproduce the error message you're getting, I think the errors might have improved a bit in more in recent Haxe versions. Anyway, there's a few issues here:
Firstly, by doing gl.RGB / gl.UNSIGNED_BYTE, you're trying to access static fields from an instance. I actually get a helpful error for this:
Cannot access static field RGB from a class instance
While other languages allow this, Haxe does not, you have to access them through the class name. To fix this, simply prefix js.html.webgl.RenderingContext.
Secondly, querySelector() returns a plain js.html.Element, which none of the overloads accepts. They all want something more specific: VideoElement, ImageElement or CanvasElement. So you'd have to cast it first:
var image:js.html.ImageElement = cast document.querySelector('img[src="images/myImage.jpg"]');
Finally, it seems a bit suspicious that you'd need to cast the first parameter. Even if it works, there might be a nicer way of doing that with the wrapper you're using.
So in summary, the following should compile:
gl.texSubImage2D(cast fluid.dyeRenderTarget.writeToTexture, 0,
Math.round(mouse.x), Math.round(mouse.y),
RenderingContext.RGB, RenderingContext.UNSIGNED_BYTE, image);

Related

applying MSDDetector in colab

I have trouble writing the MSD detector correctly. However, it has no attribute ''create''.
I wrote the following code. But my session crashed for an unknown reason.
msd=cv2.xfeatures2d.MSDDetector()
kps1=msd.detect(I1)
I will appreciate any help.
unfortunately, you've found a bug here.
there should be a ´XXX_create()´ function, but someone forgot to expose it to the python api, by adding a CV_WRAP to the function signature here
(and no, you cannot use the 'ordinary' constructor, it does not produce a valid instance (will segfault, if you call any method on it !!))
please raise an issue here
if you're able to build from src, try to fix it locally, by changing that line to:
CV_WRAP static Ptr<MSDDetector> create(....

SharpDX ShaderBytecode.CompileFromFile to PixelShader

Currently i am working on a migration from SlimDX to SharpDX. Some things are different between them, like loading shaders etc:
I have a problem creating the PixelShader class (same applies to the VertexShader class). The problem is, every example I found on this subject will not compile.
For example:
using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile(filename, "PS", "ps_5_0", shaderFlags))
shader.PixelShader = new SharpDX.Direct3D11.PixelShader(device, pixelShaderByteCode);
The problem is, SharpDX.Direct3D11.PixelShader does not take a ComplilationResult as parameter. I could use the vertexShaderByteCode.Bytecode which is a ShaderBytecode, but this is also invalid.
There is a vertexShaderByteCode.Bytecode.Data which is a DataStream. I might create the byte[] from it, but I think this could be solved easier? Did I missed something?
using: SharpDX 3.1.1
I have found the problem:
Looks like i need to reference the SharpDX.D3DCompiler also, to compile for DX11. It was using the DX9 compiler.
SharpDX.D3DCompiler.ShaderBytecode(DX11) vs SharpDX.Direct3D9.ShaderBytecode(DX9)
I'll leave this for anyone who has the same struggles.
CompilationResult is returned by the compile and you can test if the bytecode is null, if it is, you can then check the error codes (Best in debug though :)).
HasErrors : boolean
Message : string
Check these also.

Getting Error Array Type Required

I am trying to run this code:
RichViewEdit1.LineCount[i]:= Cipher.EncryptString(RichViewEdit1.LineCount[i]);
And I keep getting an error: Array Type Required.
Why I'm I getting this error?
More Info:
LineCount is - System.Integer
And TRichViewEdit does not have a "Lines" property.
Because RichViewEdit1.LineCount is not an array.
What it is ? don't know. Look into your sources, we cannot see them here.
PS. There seem to be no .Line*** properties at all: http://www.trichview.com/help/pme_cp_trichviewedit.html
Dunno if that still is relevant - http://www.trichview.com/support/trichview.support.examples/retrievingtext.htm
Also read through http://www.trichview.com/help/idh_rvgettext.html
PPS. since you paid for the component, you're entitled to get their programming examples and their customer support service. Both this and that are available at http://www.trichview.com/support/

cpSpaceHashEach - 2 problems at the same line

I'm trying to grasp basics of Chipmunk. In some tutorial I found a line:
cpSpaceHashEach(space->activeShapes, &updateShape, nil);
But I get 2 mistakes here:
1) Implicit declaration of function is invalid in C99
2) No member named 'activeShapes' in 'struct cpSpace'
What is wrong? Why doesn't it work? Do I need to include something else?
Just to clarify with some code in case anyone else runs into this problem, instead of
cpSpaceHashEach(space->activeShapes, &updateShape, nil);
you'd use:
cpSpaceEachShape(space, &updateShape, nil);
Apparently this change was done so it is easier to keep the code future-proof since the activeShapes were not meant to be used in this way.
Digging into the changelog: (https://github.com/slembcke/Chipmunk-Physics/blob/master/VERSION.txt)
If you look, you'll find that in Chipmunk 5.x cpSpace.*Shapes were marked as private members of the cpSpace struct in the header. Then, in Chipmunk 6.x, private access was disabled by default and a cpSpaceEachShape() function appeared that almost exactly replaced cpSpaceHashEach() + cpSpace.activeShapes that you are trying to do.

Simple OpenCV problem

Why I try to run the following OpenCV program, it shows the following error :
ERROR:
test_1.exe - Application Error
The application failed to initialize properly (0x80000003).
Click on OK to terminate the application.
CODE:
#include "cv.h"
#include "highgui.h"
int main()
{
IplImage *img = cvLoadImage("C:\\face.bmp");
cvSetImageROI(img, cvRect(100,100, 100, 100));
cvAddS(img, cvScalar(50), img);
cvResetImageROI(img);
cvShowImage("Test", img);
cvWaitKey(0);
return 0;
}
When i press F5(im using vs2008express), the program encounters a break point...i have attached a picture...dont know, whether, it will help or not.
Error Snapshot Link
It is not that, only this program is producing this error, but also any kind of image manipulation funciton containing (OpenCV)program is resulting in this sitution.
Such as : cvSmooth
one last thing, it there any dedicated OpenCV forum or sth like that?
I am an administrator.So, yes, ive the permission.
a version mismatch.
sorry, i didn't get it?Version mismatch with what?
But, i have found the error using dependency walker.
Warning: At least one module has an unresolved import due to a missing export
function in a delay-load dependent module.
and also found that, it is a common problem, and found some info in the FAQ of DW...
Why am I seeing a lot of applications where MPR.DLL shows up in red under
SHLWAPI.DLL because it is missing a function named WNetRestoreConnectionA?
I also get a "Warning: At least one module has an unresolved import due to
a missing export function in a delay-load dependent module" message.
Function name : WNetRestoreConnectionA
But there is no guideline about how to solve it. Though, they say, it is not a problem.
i googled a little and found a suggestion.It says,
Turn off your compilers setting to assume you are programming for Win9x.
(I just lost which setting but it is not that difficult, use a #define...)
But i have no idea, how to do that in Visual Studio 2008 express.
Any suggestion how to solve it...
This usually indicates a problem with a dll; either you don't have permission, or a version is mismatched. Try running as Administrator to see if it is a permissions problem. If that doesn't help, try using the Dependency Walker.

Resources