nrobi
01-23-2009, 03:19 AM
I had this very simple idea. I'm not sure if anyone has ever seen a candle stick chart but essentially it's a 1px line from the high to low and a (1*n)px line from open to close in whatever time period. I'm building a program to test different trading systems and wanted to use these candlestick charts in the app.
This is something probably really simple (but its many years since I tinkered with OGL). My problem is this I had 1 loop. I set the line width to a certain level and draw the line from open to close.. then set the width to 1px and draw another from high to low.
The result is one set of lines... from high to low.
Then I put it in two loops... 1 for GL_LINES and one for GL_QUADS. Same result, only 1px lines from high to low. If I comment out the code to draw the lines from high to low I see the wider lines from open to close "underneath."
I changed z-depth, enabled depth testing, etc... no difference
What am I doing wrong? I'd like to use GL_LINES to write everything and not use QUADS if possible. My code is as follows (kinda simple as I'm just testing things atm):
void COpenGLWnd::OnPaint()
{
//CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
int iSize = theApp.ts.data.size();
int iZoom = 1;
int width = (1 << iZoom) + 1;
int unit = width + iZoom;
int i,offset = 0;
this->GetClientRect(&rect);
int nCandles = rect.right/unit;
float top = ::hilo(theApp.ts.data,nCandles,nCandles,HL_HIGH),
bottom = ::hilo(theApp.ts.data,nCandles,nCandles,HL_LOW);
this->EnableOpenGL();
::glClearColor(0.0f,0.0f,0.0f,0.0f);
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
::glEnable(GL_DEPTH_TEST);
::glMatrixMode(GL_PROJECTION);
::glLoadIdentity();
::glOrtho(0,rect.right,bottom,top,0,1);
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
glBegin(GL_LINES);
for(i=0;i<nCandles;++i) {
if(theApp.ts.data[i].fPrice[OPEN] < theApp.ts.data[i].fPrice[CLOSE])
glColor3f(0.0f,0.0f,1.0f);
else if(theApp.ts.data[i].fPrice[OPEN] > theApp.ts.data[i].fPrice[CLOSE])
glColor3f(1.0f,0.0f,0.0f);
else
glColor3f(0.0f,1.0f,1.0f);
offset += unit; //(unit-1) >> 1;
/* glLineWidth((float)width);
glVertex3f(offset,theApp.ts.data[i].fPrice[OPEN],0.0f);
glVertex3f(offset,theApp.ts.data[i].fPrice[CLOSE],0.0f);
*/
glLineWidth(1.0f);
glVertex3f(offset,theApp.ts.data[i].fPrice[HIGH],0.0f);
glVertex3f(offset,theApp.ts.data[i].fPrice[LOW],0.0f);
}
glEnd();
glBegin(GL_QUADS);
for(i=0;i<nCandles;++i) {
if(theApp.ts.data[i].fPrice[OPEN] < theApp.ts.data[i].fPrice[CLOSE])
glColor3f(0.0f,0.0f,1.0f);
else if(theApp.ts.data[i].fPrice[OPEN] > theApp.ts.data[i].fPrice[CLOSE])
glColor3f(1.0f,0.0f,0.0f);
else
glColor3f(0.0f,1.0f,1.0f);
offset += unit; //(unit-1) >> 1;
glVertex3f(offset-iZoom,theApp.ts.data[i].fPrice[OPEN],0.1f);
glVertex3f(offset+iZoom,theApp.ts.data[i].fPrice[OPEN],0.1f);
glVertex3f(offset+iZoom,theApp.ts.data[i].fPrice[CLOSE],0.1f);
glVertex3f(offset-iZoom,theApp.ts.data[i].fPrice[CLOSE],0.1f);
}
glEnd();
::SwapBuffers(hDC);
this->DisableOpenGL();
// Do not call CWnd::OnPaint() for painting messages
}
This is something probably really simple (but its many years since I tinkered with OGL). My problem is this I had 1 loop. I set the line width to a certain level and draw the line from open to close.. then set the width to 1px and draw another from high to low.
The result is one set of lines... from high to low.
Then I put it in two loops... 1 for GL_LINES and one for GL_QUADS. Same result, only 1px lines from high to low. If I comment out the code to draw the lines from high to low I see the wider lines from open to close "underneath."
I changed z-depth, enabled depth testing, etc... no difference
What am I doing wrong? I'd like to use GL_LINES to write everything and not use QUADS if possible. My code is as follows (kinda simple as I'm just testing things atm):
void COpenGLWnd::OnPaint()
{
//CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
int iSize = theApp.ts.data.size();
int iZoom = 1;
int width = (1 << iZoom) + 1;
int unit = width + iZoom;
int i,offset = 0;
this->GetClientRect(&rect);
int nCandles = rect.right/unit;
float top = ::hilo(theApp.ts.data,nCandles,nCandles,HL_HIGH),
bottom = ::hilo(theApp.ts.data,nCandles,nCandles,HL_LOW);
this->EnableOpenGL();
::glClearColor(0.0f,0.0f,0.0f,0.0f);
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
::glEnable(GL_DEPTH_TEST);
::glMatrixMode(GL_PROJECTION);
::glLoadIdentity();
::glOrtho(0,rect.right,bottom,top,0,1);
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
glBegin(GL_LINES);
for(i=0;i<nCandles;++i) {
if(theApp.ts.data[i].fPrice[OPEN] < theApp.ts.data[i].fPrice[CLOSE])
glColor3f(0.0f,0.0f,1.0f);
else if(theApp.ts.data[i].fPrice[OPEN] > theApp.ts.data[i].fPrice[CLOSE])
glColor3f(1.0f,0.0f,0.0f);
else
glColor3f(0.0f,1.0f,1.0f);
offset += unit; //(unit-1) >> 1;
/* glLineWidth((float)width);
glVertex3f(offset,theApp.ts.data[i].fPrice[OPEN],0.0f);
glVertex3f(offset,theApp.ts.data[i].fPrice[CLOSE],0.0f);
*/
glLineWidth(1.0f);
glVertex3f(offset,theApp.ts.data[i].fPrice[HIGH],0.0f);
glVertex3f(offset,theApp.ts.data[i].fPrice[LOW],0.0f);
}
glEnd();
glBegin(GL_QUADS);
for(i=0;i<nCandles;++i) {
if(theApp.ts.data[i].fPrice[OPEN] < theApp.ts.data[i].fPrice[CLOSE])
glColor3f(0.0f,0.0f,1.0f);
else if(theApp.ts.data[i].fPrice[OPEN] > theApp.ts.data[i].fPrice[CLOSE])
glColor3f(1.0f,0.0f,0.0f);
else
glColor3f(0.0f,1.0f,1.0f);
offset += unit; //(unit-1) >> 1;
glVertex3f(offset-iZoom,theApp.ts.data[i].fPrice[OPEN],0.1f);
glVertex3f(offset+iZoom,theApp.ts.data[i].fPrice[OPEN],0.1f);
glVertex3f(offset+iZoom,theApp.ts.data[i].fPrice[CLOSE],0.1f);
glVertex3f(offset-iZoom,theApp.ts.data[i].fPrice[CLOSE],0.1f);
}
glEnd();
::SwapBuffers(hDC);
this->DisableOpenGL();
// Do not call CWnd::OnPaint() for painting messages
}