I recently upgraded Three.js from r131 to r132 and I am receiving the following error:
Program Info Log: Fragment shader is not compiled.
FRAGMENT
ERROR: 0:459: 'getDirectionalDirectLightIrradiance' : no matching overloaded function found
ERROR: 0:479: 'getPointDirectLightIrradiance' : no matching overloaded function found
The relevant parts of my fragment shader is below:
IncidentLight directLight;
// Directional Light
#if NUM_DIR_LIGHTS > 0
DirectionalLight directionalLight;
for (int i = 0; i < NUM_DIR_LIGHTS; i++) {
directionalLight = directionalLights[i];
getDirectionalDirectLightIrradiance(directionalLight, geometry, directLight);
#ifdef USE_SHADOWMAP
directLight.color *= all(bvec2(directionalLight.shadow, directLight.visible)) ? getShadow(directionalShadowMap[i], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[i]) : 1.0;
#endif
RE_Direct(directLight, geometry, material, reflectedLight);
}
#endif
// Point Light
#if (NUM_POINT_LIGHTS > 0)
PointLight pointLight;
for (int i = 0; i < NUM_POINT_LIGHTS; i++) {
pointLight = pointLights[i];
getPointDirectLightIrradiance(pointLight, geometry, directLight);
#ifdef USE_SHADOWMAP
directLight.color *= all(bvec2(pointLight.shadow, directLight.visible)) ? getPointShadow(pointShadowMap[i], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[i]) : 1.0;
#endif
RE_Direct(directLight, geometry, material, reflectedLight);
}
#endif
Looking into a recent commit, it seems they renamed getDirectionalDirectLightIrradiance to getDirectionalLightInfo and renamed getPointDirectLightIrradiance to getPointLightInfo among other things.
renaming these methods fixed the issue.
Related
Screenshot of the problem:
Here are the relevant bits of code - error handling etc. are omitted for clarity.
D2D1_BITMAP_PROPERTIES1 bp;
bp.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
bp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
bp.dpiX = 96.0f;
bp.dpiY = 96.0f;
bp.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW;
bp.colorContext = nullptr;
...
d2dDeviceContext->SetTarget(targetBitmap);
....
writeFactory->CreateTextFormat(L"Arial", nullptr, DWRITE_FONT_WEIGHT_LIGHT, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 32.0f, L"en-US", &textFormatAccountCreds);
textFormatAccountCreds->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
textFormatAccountCreds->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
std::wostringstream outAccountName;
outAccountName << "Account Name:";
writeFactory->CreateTextLayout(outAccountName.str().c_str(), (UINT32)outAccountName.str().size(), textFormatAccountCreds, (float)800,
(float)600, &textLayoutAccountName);
const float color[4] = { 1.0f, 0.5f, 0.3f, 1.0f };
immediateContext->ClearRenderTargetView(renderTargetView, color);
d2dDeviceContext->BeginDraw();
d2dDeviceContext->DrawTextLayout(D2D1::Point2F(2.0f, 5.0f), textLayoutAccountName, blackBrush);
d2dDeviceContext->EndDraw();
swapChain->Present(0, 0);
As you can see in the screenshot, the text is rendering very poorly - specifically, the first "n" seems to be cut off on the left, as well as the first "u", and the capital "N" has some weird aliasing going on. I can change the size/position of the text, and the rendering issues manifest differently, but they still persist.
What am I missing here? I've been through most of the DirectWrite docs on MSDN and it's not clear what my problem is. I do see some mention that I should specify the starting position of my text relative to the dpi scale, but the example is very vague.
It's also worth mentioning that I'm using Direct3D and DirectWrite with Direct2D all together, in a similar fashion as seen in this tutorial. Not sure if that's causing my problem.
I would be very grateful for any assistance. Thanks much.
I figured it out. Cheers to VTT for pointing me in the right direction.
HWND hWnd = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
NULL,
NULL,
hInstance,
NULL
);
...
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 1;
sd.BufferDesc.Width = 800;
sd.BufferDesc.Height = 600;
sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 4;
sd.SampleDesc.Quality = m4xMsaaQuality - 1;
sd.Windowed = TRUE;
sd.Flags = 0;
Apparently the dimensions you pass into CreateWindow INCLUDE space for the window's menu and borders, so the ACTUAL dimensions of the space you can draw within the window are smaller.
RECT rect;
GetClientRect(hWnd, &rect);
// Returns 784 x 561
So the solution was to:
-Omit specifying sd.BufferDesc.Width and sd.BufferDesc.Height in DXGI_SWAP_CHAIN_DESC, because when they're set to 0, they will inherit dimensions from the parent window.
-Get the actual dimensions using GetClientRect when actual window dimensions are needed later on.
I'm trying to load an obj file full of vertices and render it as a point cloud.
when I try to run my code it crashes and gives me the following error:
Unhandled exception at 0x66463E50 (nvwgf2um.dll) in Tutorial06.exe: 0xC0000005: Access violation reading location 0x00E9D000.
I followed the tutorial code Microsoft provide with DirectX and changed it to suite my layout and everything but I must have done something wrong and I'm not sure what it is.
This is how I try to initialize my buffer:
CloudLoader::getInstance().loadCloudData("cloud.obj");
std::vector<CloudVertex>* data = CloudLoader::getInstance().getCloudData();
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( CloudVertex ) * data->size();
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &InitData, sizeof(InitData) );
InitData.pSysMem = data;
hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
And this my cloud loading code:
void CloudLoader::loadCloudData(std::string fileName)
{
if (m_loaded == false){
m_loadedData = new std::vector<CloudVertex>();
std::wifstream fileIn(fileName.c_str()); //Open file
wchar_t checkChar;
if (fileIn){
while (fileIn){
checkChar = fileIn.get(); //Get next char
switch (checkChar){
case 'v':
checkChar = fileIn.get();
if (checkChar == ' ') //v - vert position
{
float vz, vy, vx;
fileIn >> vx >> vy >> vz; //Store the next three types
m_loadedData->push_back(CloudVertex(vx, vy, vz));
}
break;
}
}
}
}
m_loaded = true;
}
I guess its a C++ thing and not directX and its probably really simple but I've been stuck on this for a while now, I would really appreciate the help.
pSysMem cannot point at "data", as this is a pointer to the std::vector class and not actually the data contained within the vector.
Try:
InitData.pSysMem = data->data();
How I should enable debug draw with Cocos2d-x 3.0? There are some codes that do that with cocos2d-x 2.0 but they don't even compile on Cocos2d-x. Unfortunately I am new to both cocos2d-x and Box2d and I don't know how to port them. That would be great if you would share the method how you draw shapes.
EDIT:
I have found this:
http://blog.csdn.net/tian2kong/article/details/20386213
I have overridden the draw method of my applications main Layer like this:
void HelloWorld::draw()
{
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);
kmGLPushMatrix();
m_world->drawDebugData();
kmGLPopMatrix();
}
And also have done this:
GLESDebugDraw *debugDraw = new GLESDebugDraw(PTM_RATIO);
m_world.SetDebugDraw(debugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
/*
flags += b2Draw::e_jointBit;
flags += b2Draw::e_centerOfMassBit;
flags += b2Draw::e_aabbBit;
flags += b2Draw::e_pairBit;
*/
debugDraw->SetFlags(flags);
And it worked! But when I addChild a sprite, the shapes stay blow my sprites. How to bring them front?
Open spotlight and search for GLES-Render.cpp. This file will be there in a path in the cocos2dx folder. Open the enclosing folder and drag the files GLES-Render.h and GLES-Render.cpp to the project.
Then add the following code in the init method
b2Draw *m_debugDraw = new GLESDebugDraw(PTM_RATIO);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
flags += b2Draw::e_jointBit;
flags += b2Draw::e_aabbBit;
flags += b2Draw::e_pairBit;
flags += b2Draw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
H_world->SetDebugDraw(m_debugDraw);
Then add the draw method.
void HelloWorld::draw()
{
kmGLPushMatrix();
H_world->DrawDebugData();
kmGLPopMatrix();
}
Don't forget to include GLES-Render.h
You CANNOT bring bodies to front. if you want to see your bodies behind your sprites you can set their opacity as sprite->setOpacity(100).
i use the following code to draw
void GameLayer:: setPhysics() {
b2Vec2 gravity = b2Vec2(0.0f,0.0f);// Initializing World
world = new b2World(gravity);
m_debugDraw = new GLESDebugDraw( PTM_RATIO );
world->SetDebugDraw(m_debugDraw);
world->SetAllowSleeping(false);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
// flags += b2Draw::e_jointBit;
// flags += b2Draw::e_aabbBit;
// flags += b2Draw::e_pairBit;
// flags += b2Draw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
contactListener = new MyContactListener(this);
world->SetContactListener(contactListener);
}
which is same as yours.... can you please xplain your problem a bit more
For Debug Draw You Need Two File
File Download Link
After that
Inclue that file
and create a Vaiable in .h file
GLESDebugDraw *debugDraw;
and in .ccp file
b2Vec2 gravity;
gravity.Set(0.0f, -9.8f);
this->world = new b2World(gravity);
this->debugDraw = new GLESDebugDraw(PTM_RATIO);
this->world->SetDebugDraw(debugDraw);
uint32 flags = 0 ;
flags += b2Draw::e_shapeBit ;
flags += b2Draw::e_jointBit;
// flags + = b2Draw :: e_aabbBit;
// flags + = b2Draw :: e_pairBit;
flags += b2Draw::e_centerOfMassBit;
this->debugDraw->SetFlags (flags);
in . h file
void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags);
in .cpp
void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
Layer::draw(renderer, transform, flags);
Director* director = Director::getInstance();
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION );
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
world->DrawDebugData();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
NOW Enjoy Debug draw
You could simply add another layer above your current layer.
And you can add the code you post here in the up layer then everything should be working.
I need help with canvas because of one problem that Im trying to solve for about a day. Here is part of code that I am testing.
var imgpos = 0;
function drawshape(context, shape, fill, bb) {
context.beginPath();
context.save();
context.translate( 0, 130);
context.scale(1, 0.65);
context.shadowOffsetX = 0;
context.shadowOffsetY = 10;
context.shadowBlur = 9;
context.shadowColor = "black";
context.arc(shape.x, shape.y, shape.r, shape.sa, shape.ea, shape.cc);
context.lineWidth = shape.lw;
// line color
context.strokeStyle = fill;
context.stroke();
context.restore();
// not working :( ---------------
context.save();
for(var lg = 0; lg < shape.ic; lg++) { //
var imagesel = new Image();
imagesel.src = '/images/themes/default/capsules/'+imgpos+'.png';
imagesel.onload = function(){
if(imgpos==0){xx=70;yy=320;}
if(imgpos==1){xx=120;yy=260;}
if(imgpos==2){xx=140;yy=320;}
if(imgpos==3){xx=160;yy=320;}
if(imgpos==4){xx=180;yy=320;}
if(imgpos==5){xx=200;yy=320;}
if(imgpos==6){xx=220;yy=320;}
if(imgpos==7){xx=240;yy=320;}
if(imgpos==8){xx=260;yy=320;}
context.drawImage(imagesel, xx, yy);
}
if(imgpos != 8){imgpos++;} else {imgpos=0;}
}
context.restore();
// till here :( ---------------
if(shape.link != 'Limited'){
context.save();
context.scale(1, 0.65);
context.translate(500,660);
context.font = "bold 15pt Arial";
context.fillStyle = "WHITE";
if(bb <= 2){
context.textAlign="right";
context.rotate((((shape.sa+shape.ea)-0.1)/2)-Math.PI);
context.fillText(shape.link, -170, 0);
}
if(bb > 2){
context.textAlign="left";
context.rotate((((shape.sa+shape.ea)+0.1)/2)-2*Math.PI);
context.fillText(shape.link, +170, 0);
}
context.restore();
}else{
context.save();
context.scale(1, 0.65);
context.translate( 0, 130);
context.textAlign="center";
context.font = "bold 15pt Arial";
context.fillStyle = "WHITE";
context.fillText(shape.link, shape.x, shape.y-10);
context.restore();
}
}
So this code (except of part not working) draws arcs in style of halfcircle, but each of them is separated and shaded etc... My problem is that I want to put pictures in all of them BUT not the same number of pictures (thats the reason for cycle <- must be right, tested and working with alert!...). In first should be one picture, in second two, in third one ... and finaly in ninth two. But if i try this code, pictures are all drowe on one place and all of them are changing position if this function runs... I dont know what to do with that..
Firstly I wanted to add them to the path (each of paths have link, but thats another function, working properly too), than I tryied to do it separated from that function but nothing worked for me. Important part of code is only not working part, averything else is working perfectly.
Thanks for help.
It looks like you're fooled by the infamous loop variable issue. JavaScript variables live per function, not per block. So, your imagesel / imgpos variables only exist once in fact, which means you only have one image at one location. The variable is overwritten each loop iteration.
You should wrap the appropriate loop code in a function to actually create separate variables. Also, you haven't declared xx / yy anywhere with var.
for(var lg = 0; lg < shape.ic; lg++) {
(function(imgpos) {
var imagesel = new Image();
imagesel.src = '/images/themes/default/capsules/'+imgpos+'.png';
imagesel.onload = function(){
if(imgpos==0){xx=70;yy=320;}
if(imgpos==1){xx=120;yy=260;}
if(imgpos==2){xx=140;yy=320;}
if(imgpos==3){xx=160;yy=320;}
if(imgpos==4){xx=180;yy=320;}
if(imgpos==5){xx=200;yy=320;}
if(imgpos==6){xx=220;yy=320;}
if(imgpos==7){xx=240;yy=320;}
if(imgpos==8){xx=260;yy=320;}
context.drawImage(imagesel, xx, yy);
}
})(imgpos);
if(imgpos != 8){imgpos++;} else {imgpos=0;}
}
I googled as hard as I can, but I found nothing.
What I want to do:
create a window with X11 (Xlib) and show it
fill the window with color using OpenGL ES 2.0
For OpenGL ES 2.0 support on my ArchLinux, I use MESA. I know how to create a simple X window using Xlib, I have a basic knowledge of EGL and OpenGL ES, but I can't understand how to use all them (X11 + EGL + OpenGL ES 2.0) in conjuction.
I would be very thakful if someone wrote at least a short code example on how to prepare a X window and connect it with OpenGL ES 2.0 correctly and start rendering.
Create Window:
Window root;
XSetWindowAttributes swa;
XSetWindowAttributes xattr;
Atom wm_state;
XWMHints hints;
XEvent xev;
EGLConfig ecfg;
EGLint num_config;
Window win;
/*
* X11 native display initialization
*/
x_display = XOpenDisplay(NULL);
if ( x_display == NULL )
{
return EGL_FALSE;
}
root = DefaultRootWindow(x_display);
swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask;
win = XCreateWindow(
x_display, root,
0, 0, esContext->width, esContext->height, 0,
CopyFromParent, InputOutput,
CopyFromParent, CWEventMask,
&swa );
xattr.override_redirect = FALSE;
XChangeWindowAttributes ( x_display, win, CWOverrideRedirect, &xattr );
hints.input = TRUE;
hints.flags = InputHint;
XSetWMHints(x_display, win, &hints);
// make the window visible on the screen
XMapWindow (x_display, win);
XStoreName (x_display, win, title);
// get identifiers for the provided atom name strings
wm_state = XInternAtom (x_display, "_NET_WM_STATE", FALSE);
memset ( &xev, 0, sizeof(xev) );
xev.type = ClientMessage;
xev.xclient.window = win;
xev.xclient.message_type = wm_state;
xev.xclient.format = 32;
xev.xclient.data.l[0] = 1;
xev.xclient.data.l[1] = FALSE;
XSendEvent (
x_display,
DefaultRootWindow ( x_display ),
FALSE,
SubstructureNotifyMask,
&xev );
Set color:
glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
// Set the viewport
glViewport ( 0, 0, esContext->width, esContext->height );
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT );
Sources:
https://github.com/danginsburg/opengles-book-samples/blob/master/LinuxX11/Chapter_2/Hello_Triangle/Hello_Triangle.c
https://github.com/danginsburg/opengles-book-samples/blob/master/LinuxX11/Common/esUtil.c
https://github.com/danginsburg/opengles-book-samples/blob/master/LinuxX11/Common/esUtil.h
The opengles-book-samples code actually fails for me. If you see the same init failures, a call to eglBindAPI(EGL_OPENGL_ES_API) seemed to fix it.