Playwright's page.evaluate always return undefined - playwright

this is my code.
very simple, I want to know if an element is in viewport.
for some reason I can't understand I keep getting undefined.
the element exists but nothing happens
in the I see the x but the q is never seen.
async function isItemInViewport( page ) {
console.log( 'x' );
await page.evaluate( () => {
console.log( 'q' );
const lastMenuItem = document.querySelectorAll( '.nav-menu--dropdown.nav-menu__container .lastitem-class-for-playwright-test' )[ 0 ].getBoundingClientRect();
console.log(lastMenuItem );
let isInViewport = false;
if (
lastMenuItem.top >= 0 &&
lastMenuItem.left >= 0 &&
lastMenuItem.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) &&
lastMenuItem.right <= ( window.innerWidth || document.documentElement.clientWidth )
) {
isInViewport = true;
}
return isInViewport;
} );
}

This is what I end up doing:
async function isItemInViewport( page, item ) {
return await page.evaluate( ( item ) => {
let isVisible = false;
const element = document.querySelector( item );
if ( element ) {
const rect = element.getBoundingClientRect();
if ( rect.top >= 0 && rect.left >= 0 ) {
const vw = Math.max( document.documentElement.clientWidth || 0, window.innerWidth || 0 );
const vh = Math.max( document.documentElement.clientHeight || 0, window.innerHeight || 0 );
if ( rect.right <= vw && rect.bottom <= vh ) {
isVisible = true;
}
}
}
return isVisible;
}, item );
}
And this is the function call:
// Assertion
const item = '.item-css-class';
await expect( await isItemInViewport( page, item ) ).toBeTruthy();

Related

How to get a profit of Nth open position MQL4 / MT4?

I want to create a function that can get random profit open position.
For example :
a profit of the Last 2 Open Position of overall Total Position
a profit of the First 3 Open Position of overall Total Position
Below function seems it only gets the First Open Position Profit :
double BuyProfit()
{
Price = 0;
datetime EarliestOrder = TimeCurrent();
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS))
{
if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
if(EarliestOrder > OrderOpenTime())
{
EarliestOrder = OrderOpenTime();
Price = OrderProfit()+OrderSwap()+OrderCommission();
}
}
}
}
return Price;
}
Q : "How to get a profit of Nth open position MQL4/MT4?I want to create a function that can get random profit open position."
You may take this rapid-prototype to complete your actual logic code:
double nthNetPROFIT( const int Nth ) {
if ( Nth > OrdersTotal() ) return( EMPTY );
int softCount = 0;
double nthNetProfit = EMPTY;,
for( int ii = 0; ii < OrdersTotal(); ii++ ) {
if ( OrderSelect( ii, SELECT_BY_POS ) ) {
if ( OrderType() == OP_BUY // DEPENDS ON ACTUAL LOGIC
&& OrderSymbol() == Symbol() // DEPENDS ON ACTUAL LOGIC
&& OrderMagicNumber() == MagicNumber // DEPENDS ON ACTUAL LOGIC
) {
... // DEPENDS ON ACTUAL LOGIC
if ( ++softCount == Nth ){
nthNetProfit = OrderProfit()
+ OrderSwap()
+ OrderCommission();
break;
}
}
}
return( NormalizeDouble( nthNetProfit, 2 ) );
}

mql4 check if order exists executed multiple times

I'm using this code to check if orders are existing for the price buy1 and sell1 in my code.
Somehow some orders get executed twice.
Shouldn't happen because i'm checking if there is any open order with the same takeprofit.
Anyone able to see whats wrong?
bool CheckBuyOrder1(double buy1_tp){
for( int i = 0 ; i < OrdersTotal() - 1 ; i++ ) {
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if( OrderTakeProfit() == buy1_tp && OrderComment() == "buy" )
return(true);
}
return(false);
}
bool CheckSellOrder1(double sell1_tp){
for( int i = 0 ; i < OrdersTotal() - 1 ; i++ ) {
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if( OrderTakeProfit() == sell1_tp && OrderComment() == "sell" )
return(true);
}
return(false);
}
int totalOrders = OrdersTotal();
void OnTick()
{
if(totalOrders != OrdersTotal()){
double vbid = MarketInfo("EURUSD",MODE_BID);
double bid = NormalizeDouble(vbid, 3);
double market_buy_tp = bid;
double buy1= bid + 0.002;
double buy1_tp= bid + 0.003;
if(CheckOpenOrders1(market_buy_tp)==false && CheckBuyOrder1(buy1_tp)==false){
int ticket9=OrderSend(Symbol(),OP_BUYSTOP,Lots,buy1,MaxSlippage,0,buy1_tp,"buy",16380,0,clrGreen);
}
double market_sell_tp = bid;
double sell1 = bid - 0.003;
double sell1_tp= bid - 0.004;
if(CheckOpenOrdersSell1(market_sell_tp)==false && CheckSellOrder1(sell1_tp)==false ){
int ticket19=OrderSend(Symbol(),OP_SELLSTOP,Lots,sell1,MaxSlippage,0,sell1_tp,"sell",16380,0,clrGreen);
}
totalOrders = OrdersTotal();
}}
Whenever you try to compare an OrderTakeProfit() value with some other double - keep in mind rounding and float representation.
E.g. if you need to compare 0.10 with another double that you believe is 0.10 - you might be surprised that 0.10 is 0.09(9)6 or 0.10(0)4
That is why sometimes you might not find such an order.
double o = Point / 2; // initialize in OnInit(), declare in global vars
...
bool CheckOrderBuy( double tp ){
for ( int i = OrdersTotal() - 1; i >= 0; i-- ){
if ( !OrderSelect( i, SELECT_BY_POS ) )continue;
if ( fabs( OrderTakeProfit() - tp ) < o
&& OrderType() == OP_BUY
) return true;
}
return false;
}

My First MQL4 EA does not generate any Orders. Why?

I'm trying to build a first EA, code below, but it doesn't execute any trades.
I know it is very simple, but logically, I think this should Buy and Sell.
I'm trying to only use a code that I understand.
I'd appreciate it if anyone had any feedback!
//
extern int sma_short = 10;
extern int sma_long = 20;
extern double fakeout = 0.0005 ;
extern double stoploss = 150;
extern double risk = 1;
extern int slippage = 5;
extern int magicnumber = 12345;
extern bool SignalMail = false;
extern bool UseTrailingStop = true;
extern int TrailingStop = 150;
double sma_short_t3;
double sma_short_t0;
double sma_long_t3;
double sma_long_t0;
double sma_diff_t3;
double sma_diff_t0;
double lots;
double stoplosslevel;
int P = 1;
int ticket, ticket2;
int total = OrdersTotal();
bool OpenLong = false;
bool OpenShort = false;
bool CloseLong = false;
bool CloseShort = false;
bool isYenPair = false;
bool OpenOrder = false;
int OnInit()
{
if ( Digits == 5 || Digits == 3 || Digits == 1 ) P = 10; else P = 1; // To account for 5 digit brokers
if ( Digits == 3 || Digits == 2 ) isYenPair = true; // Adjust for YenPair
return( INIT_SUCCEEDED );
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit( const int reason )
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void Start()
{
sma_short_t3 = iMA( NULL, 0, sma_short, 0, MODE_SMA, PRICE_CLOSE, 3 );
sma_short_t0 = iMA( NULL, 0, sma_short, 0, MODE_SMA, PRICE_CLOSE, 0 );
sma_long_t3 = iMA( NULL, 0, sma_long, 0, MODE_SMA, PRICE_CLOSE, 3 );
sma_long_t0 = iMA( NULL, 0, sma_long, 0, MODE_SMA, PRICE_CLOSE, 0 );
sma_diff_t3 = sma_long_t3 - sma_short_t3;
sma_diff_t0 = sma_long_t0 - sma_short_t0;
if ( OpenOrder )
{
if ( CloseLong || CloseShort )
{
OrderClose( OrderTicket(), OrderLots(), Bid, slippage, MediumSeaGreen );
OpenOrder = False;
CloseLong = False;
CloseShort = False;
}
}
if ( sma_diff_t3 < 0 && sma_diff_t0 > fakeout )
{
OpenLong = True ;
CloseShort = True;
}
if ( sma_diff_t3 > 0 && sma_diff_t0 < -fakeout )
{
OpenShort = True;
CloseLong = True;
}
lots = risk * 0.01 * AccountBalance() / ( MarketInfo( Symbol(), MODE_LOTSIZE ) * stoploss * P * Point ); // Sizing Algo based on account size
if ( isYenPair == true ) lots = lots * 100; // Adjust for Yen Pairs
lots = NormalizeDouble( lots, 2 );
if ( OpenLong )
{
stoplosslevel = Ask - stoploss * Point * P;
OrderSend( Symbol(), OP_BUY, lots, Ask, slippage, stoplosslevel, 0, "Buy(#" + magicnumber + ")", magicnumber, 0, DodgerBlue );
OpenOrder = True;
}
if ( OpenShort )
{
stoplosslevel = Bid + stoploss * Point * P;
OrderSend( Symbol(), OP_SELL, lots, Ask, slippage, stoplosslevel, 0, "Buy(#" + magicnumber + ")", magicnumber, 0, DodgerBlue );
OpenOrder = True ;
}
}
//+------------------------------------------------------------------+
and why do you use (MarketInfo(Symbol(),MODE_LOTSIZE)? what is the idea of that? first try with double lots = 1.00; and if problem still exists - please add a line telling about the reason why ea failed to send. sth like int ticket = OrderSend(***); if(ticket<0)Print("error=",GetLastError()); or more complex telling about the actual prices, lots, stoploss etc.
Few things in MQL4 to rather get used to:
All PriceDOMAIN data has to be NormalizeDouble() before sending to MetaTrader 4 Server.
All EquityDOMAIN data has to follow a set of discrete values,having MathMin( aMinLOT_SIZE + N * aMinLOT_STEP, aMaxLOT_SIZE ). Normalisation of EquityDOMAIN data is broker-specificand instrument-specific, so need not be always 2.
For XTO, OrderSend(), OrderMOdify(), OrderClose(), one ought follow something like this:
if ( OpenLong )
{ stoplosslevel = NormalizeDouble( Ask - stoploss * Point * P, _Digits ); // ALWAYS NormalizeDouble()
int RetCODE = OrderSend( _Symbol,
OP_BUY,
lots,
Ask,
slippage,
stoplosslevel,
0,
"Buy(#" + magicnumber + ")",
magicnumber,
0,
DodgerBlue
);
if ( RetCODE < 0 )
{ Print( "EXC: Tried to go LONG, OrderSend() failed to get confirmed ( Errno: ", GetLastError(), " )" );
}
else
{ OpenOrder = True;
...
}
...
}

PlotText result is overlapped in amibroker

I use below code
![priceatbuy=0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 && Buy\[ i \] )
priceatbuy = BuyPrice\[ i \];
PlotText("P" + priceatbuy, SelectedValue(BarIndex()), L\[SelectedValue(BarIndex())\] - ist\[SelectedValue(BarIndex())\], colorWhite);
if( priceatbuy > 0 && SellPrice\[ i \] < (priceatbuy - (0.027 * priceatbuy/100)) )
{
Sell\[ i \] = 1;
SellPrice\[ i \] = (priceatbuy - (0.027 * priceatbuy/100)) ;
plotShapes(shapeDownArrow*sell, colorpink );
priceatbuy = 0;
}
else
Sell\[ i \] = 0;
}][1]
With above plotText, when i print the variable "priceatBuy", i see the text is overlapped and I am not able to see the value correctly. Is it because that SellPrice[i] and BuyPrice[i] returning some other value that Plottext doesnt understand? If I print Sell[i] or Buy[i], it prints correctly. May I know how to get this value correctly.
PFA image
Your code is wrong.
Below is a correct code sample (The loop contains SL exit only! So you need to add some profit exit condition too otherwise you always exit at loss.)
percent = 2.0; // percent SL
delay = 1; // buy entry bar delay
Buycond = Cross( MACD(), Signal() ); // buy when macd crosses above of signal line
Buy = Ref( Buycond, -delay );
BuyPrice = Open;
Sell = 0;
SLlong = Null;
SLLineLong = Null; // array
for( i = delay; i < BarCount; i++ ) {
// setting long SL line
if( IsNull( SLlong ) && Buy[ i ] )
SLlong = BuyPrice[ i ] * ( 1 - percent / 100 );
else {
Buy[ i ] = 0;
}
// no shape buy signal if SL not hit
if( NOT IsNull( SLlong ) && BuyCond[ i ] )
Buycond[ i ] = 0;
// if SL is reached exit and reset
Sellsignal = L[ i ] < SLlong;
if( NOT IsNull( SLlong ) && Sellsignal ) {
Sell[ i ] = 1;
SellPrice[ i ] = Min( O[ i ], SLlong );
SLlong = Null;
} else
Sell[ i ] = 0;
//
// for plotting SL line array is required
SLLineLong[i] = SLlong;
}
// Chart pane section
if( Status( "action" ) == actionIndicator ) {
SetBarsRequired( 10000, 10000 );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
// Plot price
Plot( C, "", colorDefault, GetPriceStyle() );
// Plot SL line
Plot( SLLineLong, "\nSL long", colorRed, styleLine | styleNoRescale );
//
// Plot Shapes
dist = -12;
PlotShapes( shapeUpArrow * Buycond, colorGreen, 0, L, dist );
PlotShapes( shapeSmallCircle * Buy, colorGreen, 0, BuyPrice, 0 );
PlotShapes( shapeDownArrow * Sell, colorPink, 0, H, dist );
PlotShapes( shapeSmallCircle * Sell, colorPink, 0, SellPrice, 0 );
//
// Plot signal text
fnt = "Arial";
fntsize = 8;
txtdist = 25 - dist;
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
PlotTextSetFont( "", fnt, fntsize, 0, 0, -1 );
for( i = fvb; i <= lvb; i++ ) { // iterate through visible chart area only
if( Buy[i] ) // plot text at signal occurences only
PlotText( StrFormat( "BP#\n%g", BuyPrice[ i ] ), i, L[ i ], colorGreen, colorDefault, -txtdist + fntsize );
if( Sell[i] )
PlotText( StrFormat( "SP#\n%g", SellPrice[ i ] ), i, H[ i ], colorPink, colorDefault, txtdist );
}
//
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}",
O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
}

Seems like my Pixel Shader is not being called

I ve been messing around with DirectX and I ve been working on this weird idea of mine for some time now. It seems as if my pixel shader is not being invoked for some odd reason. I dont know if thats even possible or that its some stupid mistake of mine. The Code is as follows (I have copied most of it from the Tutorials.)
Shader (HLSL) Code as follows:
/*
********************************************************************************************************
* Constant Buffers (Can only change per render call).
********************************************************************************************************
*/
cbuffer SConstantBuffer : register( b0 )
{
float3 origin;
float3 direction;
float planeDistance;
int screenWidth;
int screenHeight;
};
/*
********************************************************************************************************
* Input and Output Structures
********************************************************************************************************
*/
struct VS_INPUT
{
float3 position : POSITION;
float4 color : COLOR;
};
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
/*
********************************************************************************************************
* Vertex Shader main
********************************************************************************************************
*/
VS_OUTPUT VS( VS_INPUT input )
{
VS_OUTPUT output = (VS_OUTPUT)0;
float param_d;
float3 pixelPoint;
float3 zAxis = { 0.0, 0.0, 1.0 };
float3 planeOrigin = origin + (direction * planeDistance);
float3 pointDirection = (input.position - origin) / length( (input.position - origin) );
param_d = dot( (planeOrigin - origin), direction ) / dot( pointDirection, direction );
pixelPoint = ( pointDirection * param_d ) + origin;
output.position.xyz = cross ( pixelPoint, direction );
output.position.x = output.position.x * 5.0;
output.position.y = output.position.y * 5.0;
output.position.z = 20.0;
output.position.w = output.position.z;
output.color = input.color;
return output;
}
/*
********************************************************************************************************
* Pixel Shader main
********************************************************************************************************
*/
float4 PS( VS_OUTPUT input ) : SV_Target
{
return float4( 1.0, 1.0, 1.0, 1.0); //input.color;
}
DirectX Init and Rendering code as Follows:
#include "Renderer.h"
CRenderer::CRenderer ( )
{
this->m_dxDevice = NULL;
this->m_dxDeviceContext = NULL;
this->m_dxRenderTargetView = NULL;
this->m_dxSwapChain = NULL;
this->m_dxBackBuffer = NULL;
this->m_dxVertexLayout = NULL;
this->m_dxVertexBuffer = NULL;
this->m_dxPixelShader = NULL;
this->m_dxConstantBuffer = NULL;
}
HRESULT CompileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut )
{
HRESULT hr = S_OK;
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
// Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders.
// Setting this flag improves the shader debugging experience, but still allows
// the shaders to be optimized and to run exactly the way they will run in
// the release configuration of this program.
dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
ID3DBlob* pErrorBlob;
hr = D3DX11CompileFromFile( szFileName, NULL, NULL, szEntryPoint, szShaderModel,
dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );
if( FAILED(hr) )
{
if( pErrorBlob != NULL )
OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
if( pErrorBlob ) pErrorBlob->Release();
return hr;
}
if( pErrorBlob ) pErrorBlob->Release();
return S_OK;
}
HRESULT CRenderer::InitDevice ( HWND arg_hWnd )
{
HRESULT status = S_OK;
this->m_hWnd = arg_hWnd;
RECT rctWindowSize;
GetClientRect( arg_hWnd, &rctWindowSize );
UINT dWidth = rctWindowSize.right - rctWindowSize.left;
UINT dHeight = rctWindowSize.bottom - rctWindowSize.top;
UINT dCreateDeviceFlag = 0;
#ifdef _DEBUG
dCreateDeviceFlag |= D3D11_CREATE_DEVICE_DEBUG;
#endif _DEBUG
D3D_DRIVER_TYPE pDriverType [] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE
};
UINT numDriverType = ARRAYSIZE(pDriverType);
D3D_FEATURE_LEVEL pFeatureLevel [] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0
};
UINT numFeatureLevel = ARRAYSIZE(pFeatureLevel);
//Fillout Device Descriptor
DXGI_SWAP_CHAIN_DESC objSwapChainDesc;
ZeroMemory(&objSwapChainDesc, sizeof(objSwapChainDesc));
objSwapChainDesc.BufferCount = 1;
objSwapChainDesc.BufferDesc.Width = dWidth;
objSwapChainDesc.BufferDesc.Height = dHeight;
objSwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
objSwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
objSwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
objSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
objSwapChainDesc.OutputWindow = this->m_hWnd;
objSwapChainDesc.SampleDesc.Count = 1;
objSwapChainDesc.SampleDesc.Quality = 0;
objSwapChainDesc.Windowed = true;
//Parse and create the appropriate type of device
for ( UINT driverTypeIndex = 0; driverTypeIndex < numDriverType; driverTypeIndex++ )
{
this->m_objDriverType = pDriverType[driverTypeIndex];
status = D3D11CreateDeviceAndSwapChain ( NULL,
this->m_objDriverType,
NULL,
dCreateDeviceFlag,
pFeatureLevel,
numFeatureLevel,
D3D11_SDK_VERSION,
&objSwapChainDesc,
&(this->m_dxSwapChain),
&(this->m_dxDevice),
&(this->m_objFeatureLevel),
&(this->m_dxDeviceContext) );
if ( SUCCEEDED(status) )
break;
}
if ( FAILED(status) )
return status;
//Create a render traget
this->m_dxBackBuffer = NULL;
status = this->m_dxSwapChain->GetBuffer ( 0, __uuidof(ID3D11Texture2D), (LPVOID*)(&this->m_dxBackBuffer) );
if ( FAILED(status) )
return status;
status = this->m_dxDevice->CreateRenderTargetView ( this->m_dxBackBuffer, NULL, &(this->m_dxRenderTargetView) );
if ( FAILED(status) )
return status;
//CreatDepth Stencil
D3D11_TEXTURE2D_DESC objDepthStencilDesc;
ZeroMemory(&objDepthStencilDesc, sizeof(objDepthStencilDesc));
D3D11_DEPTH_STENCIL_VIEW_DESC objDepthStencilViewDesc;
ZeroMemory(&objDepthStencilViewDesc, sizeof(objDepthStencilViewDesc));
objDepthStencilDesc.Width = dWidth;
objDepthStencilDesc.Height = dHeight;
objDepthStencilDesc.MipLevels = 1;
objDepthStencilDesc.ArraySize = 1;
objDepthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
objDepthStencilDesc.SampleDesc.Count = 1;
objDepthStencilDesc.SampleDesc.Quality = 0;
objDepthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
objDepthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
objDepthStencilDesc.MiscFlags = 0;
objDepthStencilDesc.CPUAccessFlags = 0;
status = this->m_dxDevice->CreateTexture2D (
&objDepthStencilDesc,
NULL,
&(this->m_dxDepthStencilBuffer)
);
if ( FAILED(status) )
return status;
objDepthStencilViewDesc.Format = objDepthStencilDesc.Format;
objDepthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
objDepthStencilViewDesc.Texture2D.MipSlice = 0;
status = this->m_dxDevice->CreateDepthStencilView (
this->m_dxDepthStencilBuffer,
&objDepthStencilViewDesc,
&(this->m_dxDepthStencilView)
);
if ( FAILED(status) )
return status;
this->m_dxDeviceContext->OMSetRenderTargets ( 1, &(this->m_dxRenderTargetView), this->m_dxDepthStencilView );
//Set View Port (Can be commented out;
this->m_objViewport.Width = (FLOAT)dWidth;
this->m_objViewport.Height = (FLOAT)dHeight;
this->m_objViewport.MinDepth = 0.0;
this->m_objViewport.MaxDepth = 1.0;
this->m_objViewport.TopLeftX = 0;
this->m_objViewport.TopLeftY = 0;
this->m_dxDeviceContext->RSSetViewports ( 1, &(this->m_objViewport) );
//Setting up Shaders
//Compiling Vertex Shader file
ID3DBlob * dxVSBlob = NULL;
status = CompileShaderFromFile ( L"RTShaders.fx", "VS", "vs_4_0", &dxVSBlob );
if (FAILED (status))
{
dxVSBlob->Release ( );
return status;
}
//Creating Compiled Shader
status = this->m_dxDevice->CreateVertexShader ( dxVSBlob->GetBufferPointer ( ),
dxVSBlob->GetBufferSize ( ),
NULL,
&(this->m_dxVertexShader) );
if( FAILED(status) )
{
dxVSBlob->Release ( );
return status;
}
//Describe Layout
D3D11_INPUT_ELEMENT_DESC layout [] =
{
{
"POSITION",
0,
DXGI_FORMAT_R32G32B32_FLOAT,
0,
0,
D3D11_INPUT_PER_VERTEX_DATA,
0
},
/* {
"NORMAL",
0,
DXGI_FORMAT_R32G32B32A32_FLOAT,
0,
16,
D3D11_INPUT_PER_VERTEX_DATA,
0
},
*/ {
"COLOR",
0,
DXGI_FORMAT_R32G32B32_FLOAT,
0,
12, //NEED TO CHANGE THIS TO 32 WHEN UNCOMMENTING THE ABOVE BLOCK
D3D11_INPUT_PER_VERTEX_DATA,
0
},
};
UINT numElements = ARRAYSIZE(layout);
//Create Layout
status = this->m_dxDevice->CreateInputLayout ( layout,
numElements,
dxVSBlob->GetBufferPointer ( ),
dxVSBlob->GetBufferSize ( ),
&(this->m_dxVertexLayout) );
dxVSBlob->Release ( );
dxVSBlob = NULL;
if ( FAILED(status) )
{
return status;
}
//Set Vertex Layout to the pipeline
this->m_dxDeviceContext->IASetInputLayout ( this->m_dxVertexLayout );
//Compiling Pixel Shader File
ID3DBlob * dxPSBlob = NULL;
status = CompileShaderFromFile ( L"RTShaders.fx", "PS", "ps_4_0", &dxPSBlob );
if ( FAILED(status) )
{
if ( dxPSBlob )
dxPSBlob->Release ( );
return status;
}
//Creating Compiled Pixel Shader
status = this->m_dxDevice->CreatePixelShader (
dxPSBlob->GetBufferPointer ( ),
dxPSBlob->GetBufferSize ( ),
NULL,
&(this->m_dxPixelShader)
);
dxPSBlob->Release ( );
dxPSBlob = NULL;
if ( FAILED(status) )
{
return status;
}
return S_OK;
}
HRESULT CRenderer::CreateVertexBuffer ( )
{
HRESULT status = S_OK;
D3D11_BUFFER_DESC objBufferDesc;
D3D11_SUBRESOURCE_DATA objSubresData;
UINT dStride = sizeof (SVertex);
UINT dOffset = 0;
ZeroMemory(&objBufferDesc, sizeof(objBufferDesc));
ZeroMemory(&objSubresData, sizeof(objSubresData));
objBufferDesc.ByteWidth = sizeof(SVertex) * 1681;
objBufferDesc.Usage = D3D11_USAGE_DEFAULT;
objBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
objBufferDesc.CPUAccessFlags = 0;
objSubresData.pSysMem = pVertexData;
status = this->m_dxDevice->CreateBuffer (
&objBufferDesc,
&objSubresData,
&(this->m_dxVertexBuffer)
);
if ( FAILED(status) )
return status;
this->m_dxDeviceContext->IASetVertexBuffers ( 0, 1, &(this->m_dxVertexBuffer), &dStride, &dOffset );
this->m_dxDeviceContext->IASetPrimitiveTopology ( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
return S_OK;
}
HRESULT CRenderer::CreateConstantBuffer ( )
{
HRESULT status = S_OK;
D3D11_BUFFER_DESC objBufferDesc;
ZeroMemory(&objBufferDesc, sizeof(objBufferDesc));
objBufferDesc.ByteWidth = sizeof(SConstantBuffer) + (16 - sizeof(SConstantBuffer)%16);
objBufferDesc.Usage = D3D11_USAGE_DEFAULT;
objBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
objBufferDesc.CPUAccessFlags = 0;
status = this->m_dxDevice->CreateBuffer (
&objBufferDesc,
NULL,
&(this->m_dxConstantBuffer)
);
return status;
}
HRESULT CRenderer::Render ( )
{
HRESULT status = S_OK;
RECT screenRect;
SConstantBuffer objConstBuffer;
float pClearColor [4] = { 0.0f, 0.125f, 0.5f, 1.0f };
this->m_dxDeviceContext->ClearRenderTargetView ( this->m_dxRenderTargetView, pClearColor );
this->m_dxDeviceContext->ClearDepthStencilView ( this->m_dxDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );
GetClientRect ( this->m_hWnd, &screenRect );
objConstBuffer.f4Origin = XMFLOAT3 ( 0.0f, 0.0f, 0.0f );
objConstBuffer.f4Direction = XMFLOAT3 ( 0.0f, 0.0f, 1.0f );
objConstBuffer.fDistanceFromPlane = 2.0f;
objConstBuffer.dScreenWidth = screenRect.right - screenRect.left;
objConstBuffer.dScreenHeight = screenRect.bottom - screenRect.top;
this->m_dxDeviceContext->UpdateSubresource ( this->m_dxConstantBuffer, 0, NULL, &objConstBuffer, 0, 0 );
this->m_dxDeviceContext->VSSetShader ( this->m_dxVertexShader, NULL, 0 );
this->m_dxDeviceContext->VSSetConstantBuffers ( 0, 1, &(this->m_dxConstantBuffer) );
this->m_dxDeviceContext->PSSetShader ( this->m_dxPixelShader, NULL, 0 );
this->m_dxDeviceContext->Draw ( 1680, 0 );
this->m_dxSwapChain->Present ( 0, 0 );
return status;
}
CRenderer::~CRenderer ( )
{
if ( this->m_dxDeviceContext )
this->m_dxDeviceContext->ClearState ( );
if ( this->m_dxPixelShader )
this->m_dxPixelShader->Release ( );
this->m_dxPixelShader = NULL;
if ( this->m_dxVertexLayout )
this->m_dxVertexLayout->Release ( );
this->m_dxVertexLayout = NULL;
if ( this->m_dxVertexBuffer )
this->m_dxVertexBuffer->Release ( );
this->m_dxVertexBuffer = NULL;
if ( this->m_dxDepthStencilBuffer )
this->m_dxDepthStencilBuffer->Release ( );
this->m_dxDepthStencilBuffer = NULL;
if ( this->m_dxDepthStencilView )
this->m_dxDepthStencilView->Release ( );
this->m_dxDepthStencilView = NULL;
if ( this->m_dxRenderTargetView )
this->m_dxRenderTargetView->Release ( );
this->m_dxRenderTargetView = NULL;
if ( this->m_dxBackBuffer->Release ( ) )
this->m_dxBackBuffer->Release ( );
this->m_dxBackBuffer = NULL;
if ( this->m_dxSwapChain )
this->m_dxSwapChain->Release ( );
this->m_dxSwapChain = NULL;
if ( this->m_dxDeviceContext )
this->m_dxDeviceContext->Release ( );
this->m_dxDeviceContext = NULL;
if ( this->m_dxDevice )
this->m_dxDevice->Release ( );
this->m_dxDevice = NULL;
}
Nothing Gets rendered on the screen, I should see while dots or a big white patch but all I see is the Render Target only Cleared. I ve been running Pix and the PreVS and PostVS transformations seem fine.
Please Help!

Resources