Stefan,
Here is my current program: with my own node, window and channel:
The windows are NOT updating properly. I obviously do not understand
what I am doing. Perhaps somebody can take a look? The problem has
nothing to do with RapidMind. It occurs when plotting the original display
from hello.cpp . I am not getting correct screen refresh, and somehow,
there is interference between the display window and the window
(terminal) from which I launch the appNode (./hello) . Strange.
Gordon
#include "life.h"
// Copyright (c) 2007 RapidMind Inc. All Rights Reserved
// All copies of this file must include the preceding copyright notice.
//
// Usage of this software requires acceptance and compliance with the
RAPIDMIND
// SAMPLE LICENSE, which is included in the LICENSE.TXT file. Any further
// distribution of this file must include this license agreement.
//////////////////////////////////////////////////////////////////////////////
using namespace rapidmind;
using namespace rapidmind::graphics;
using namespace std;
Life::Life(int size) : m_board(size, size)
{
m_update = RM_BEGIN {
InOut<Value1i> RM_DECL(value);
In<Value1i> neighbours[8];
Value1i RM_DECL(count) = 0;
for(int i = 0; i < 8; i++) {
count += neighbours[i];
}
RM_IF(count < 2 || count > 3) {
value = 0;
} RM_ENDIF;
RM_IF(count == 3) {
value = 1;
} RM_ENDIF;
} RM_END;
// initialize the board
reset();
}
//----------------------------------------------------------------------
void Life::reset()
{
int* data = m_board.write_data();
for(unsigned int i = 0; i < product(m_board.size())[0]; i++) {
data[i] = (rand() % 3) == 0;
}
}
//----------------------------------------------------------------------
void Life::update()
{
// use shifts to pass in the 8 surrounding neighbours of each cell
m_board = m_update(m_board)
(shift(m_board, -1, -1), shift(m_board, 0, -1), shift(m_board, 1, -1))
(shift(m_board, -1, 0), shift(m_board, 1, 0))
(shift(m_board, -1, 1), shift(m_board, 0, 1), shift(m_board, 1, 1));
}
//----------------------------------------------------------------------
rapidmind::Array<2, rapidmind::Value1i>& Life::board()
{
return m_board;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
void Life_GLSL::init_shaders()
{
// This is a simple pass through vertex program.
Program vsh = RM_BEGIN_VERTEX_PROGRAM("semantic") {
InOut<Position<Value2f> > pos; // from glVertex2f
InOut<TexCoord<Value2f> > tex; // from glTexCoord2f
} RM_END;
Program fsh = RM_BEGIN_FRAGMENT_PROGRAM {
In<TexCoord<Value2f> > tex;
Value1i a = life.board()(tex);
Out<Color<Value3f> > color = a*Value3f(1.0f);
} RM_END;
shaders = new ProgramSet(vsh, fsh);
}
//----------------------------------------------------------------------
void Life_GLSL::display()
{
glClear(GL_COLOR_BUFFER_BIT);
rapidmind::graphics::bind(*shaders);
// Draw a rectangle over the entire window
glBegin(GL_QUADS);
// top left
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f, 1.0f);
// top right
glTexCoord2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
// bottom right
glTexCoord2f(1.0f, 1.0f);
glVertex2f(1.0f, -1.0f);
// bottom left
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-1.0f, -1.0f);
glEnd();
rapidmind::graphics::unbind();
// glutSwapBuffers();
}
//----------------------------------------------------------------------
void Life_GLSL::update()
{
static Timer last = Timer::now();
Timer now = Timer::now();
// update every 50ms (~20fps)
if (!limit_fps || (now-last).value() > 50.0f) {
// execute the Game of Life stream program
life.update();
last = now;
//glutPostRedisplay();
}
}
//----------------------------------------------------------------------
[EMAIL PROTECTED] eqHelloGE]$ cat hello.cpp
/* Copyright (c) 2007, Stefan Eilemann <[EMAIL PROTECTED]>
* All rights reserved.
*
* Equalizer 'Hello, World!' example. Shows the minimum Equalizer
program which
* renders spinning quads around the origin.
*/
#include <eq/eq.h>
#include <stdlib.h>
#include "life.h"
using namespace eqBase;
using namespace std;
Life* glife;
Life_GLSL* glife_glsl;
//----------------------------------------------------------------------
//Added by GE
class MyWindow : public eq::Window
{
public:
Life* life;
Life_GLSL* life_glsl;
public:
MyWindow(eq::Pipe* pipe) : eq::Window(pipe) {
printf("MyWindow::constructor\n");
}
//bool configInit( const uint32_t initID);
bool configInitGL( const uint32_t initID)
{
if( !eq::Window::configInit( initID )) {
printf("MyWindow did not inialize properly\n");
return false;
}
printf("MyWindow::configInit\n");
life = new Life(512);
life_glsl = new Life_GLSL(*life);
life_init();
printf("glife= %d\n", glife);
glife = life;
printf("glife= %d\n", glife);
glife_glsl = life_glsl;
}
void life_init() {
rm::init();
life = new Life(512);
life_glsl = new Life_GLSL(*life);
life_glsl->init_shaders();
life_glsl->bind();
}
bool configExit()
{
printf("MyWindow::configExit\n");
delete life;
delete life_glsl;
return eq::Window::configExit();
}
};
//----------------------------------------------------------------------
//ADDED by GE
class MyNode : public eq::Node
{
public:
Life* life;
Life_GLSL* life_glsl;
public:
MyNode(eq::Config* parent) : eq::Node(parent) {
printf("MyNode constructor\n");
}
bool configInit(const uint32_t initID) {
if( !eq::Node::configInit( initID )) {
printf("MyNode did not inialize properly\n");
return false;
}
printf("MyNode:;configInit: initID= %d\n", initID);
return true;
}
bool configExit()
{
printf("MyNode::configExit");
return eq::Node::configExit();
}
#if 0
void life_init() {
//rm::init();
life = new Life(512);
life_glsl = new Life_GLSL(*life);
life_glsl->init_shaders();
life_glsl->bind();
}
#endif
};
//----------------------------------------------------------------------
class Channel : public eq::Channel
{
public:
rm::ProgramSetPtr shaders;
rm::Program vsh, fsh;
public:
Channel( eq::Window* parent ) : eq::Channel( parent ) { }
bool configInit(const uint32_t initID) {
printf("inside channel constructor\n");
printf("glife= %d\n", glife);
vsh = RM_BEGIN_VERTEX_PROGRAM("semantic") {
rm::InOut<rmg::Position<rm::Value2f> > pos; // from glVertex2f
rm::InOut<rmg::TexCoord<rm::Value2f> > tex; // from
glTexCoord2f
} RM_END;
fsh = RM_BEGIN_FRAGMENT_PROGRAM {
rm::In<rmg::TexCoord<rm::Value2f> > tex;
rm::Value1i a = glife->board()(tex);
rm::Out<rmg::Color<rm::Value3f> > color = a*rm::Value3f(1.0f);
} RM_END;
shaders = new rm::ProgramSet(vsh, fsh);
}
protected:
virtual void frameDraw( const uint32_t spin );
};
//----------------------------------------------------------------------
class NodeFactory : public eq::NodeFactory
{
public:
virtual eq::Window* createWindow(eq::Pipe* pipe)
{ return new MyWindow(pipe); }
// channel needs glife, defined in MyWindow
virtual eq::Node* createNode(eq::Config* parent)
{ return new MyNode(parent); }
virtual eq::Channel* createChannel( eq::Window* parent )
{ return new Channel( parent ); }
};
//----------------------------------------------------------------------
// This is a simple pass through vertex program.
//----------------------------------------------------------------------
// initialize this on the appropriate node or channel
int main( const int argc, char** argv )
{
// 1. Equalizer initialization
NodeFactory nodeFactory;
if( !eq::init( argc, argv, &nodeFactory ))
{
EQERROR << "Equalizer init failed" << endl;
return EXIT_FAILURE;
}
// 2. get a configuration
bool error = false;
eq::Config* config = eq::getConfig( argc, argv );
if( config )
{
// 3. init config
if( config->init( 0 )) {
// 4. run main loop
uint32_t spin = 0;
while( config->isRunning( ))
{
config->startFrame( ++spin );
config->finishFrame();
}
// 5. exit config
config->exit();
} else {
EQERROR << "Config initialization failed: "
<< config->getErrorMessage() << endl;
error = true;
}
// 6. release config
eq::releaseConfig( config );
}
else
{
EQERROR << "Cannot get config" << endl;
error = true;
}
// 7. exit
eq::exit();
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}
/** The rendering routine, a.k.a., glutDisplayFunc() */
void Channel::frameDraw( const uint32_t spin )
{
// setup OpenGL State
eq::Channel::frameDraw( spin );
#if 0
glife_glsl->update(); // need better method than glife
glife_glsl->display();
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(0);
rapidmind::graphics::bind(*shaders);
glOrtho(-2.,2.,-2.,2., 2.,-2.);
// Draw a rectangle over the entire window
glBegin(GL_QUADS);
// top left
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f, 1.0f);
// top right
glTexCoord2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
// bottom right
glTexCoord2f(1.0f, 1.0f);
glVertex2f(1.0f, -1.0f);
// bottom left
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-1.0f, -1.0f);
glEnd();
rapidmind::graphics::unbind();
#endif
#if 1
const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
// rotate scene around the origin
glRotatef( static_cast< float >( spin ) * 0.1f, 1.0f, 0.5f, 0.25f );
// render six axis-aligned colored quads around the origin
// front
glColor3f( 1.0f, 0.5f, 0.5f );
glNormal3f( 0.0f, 0.0f, 1.0f );
glBegin( GL_TRIANGLE_STRIP );
glVertex3f( .7f, .7f, -1.0f );
glVertex3f( .7f, -.7f, -1.0f );
glVertex3f( -.7f, .7f, -1.0f );
glVertex3f( -.7f, -.7f, -1.0f );
glEnd();
// bottom
glColor3f( 0.5f, 1.0f, 0.5f );
glNormal3f( 0.0f, 1.0f, 0.0f );
glBegin( GL_TRIANGLE_STRIP );
glVertex3f( .7f, -1.0f, .7f );
glVertex3f( .7f, -1.0f, -.7f );
glVertex3f( -.7f, -1.0f, .7f );
glVertex3f( -.7f, -1.0f, -.7f );
glEnd();
// back
glColor3f( 0.5f, 0.5f, 1.0f );
glNormal3f( 0.0f, 0.0f, -1.0f );
glBegin( GL_TRIANGLE_STRIP );
glVertex3f( .7f, .7f, 1.0f );
glVertex3f( .7f, -.7f, 1.0f );
glVertex3f( -.7f, .7f, 1.0f );
glVertex3f( -.7f, -.7f, 1.0f );
glEnd();
// top
glColor3f( 1.0f, 1.0f, 0.5f );
glNormal3f( 0.f, -1.f, 0.f );
glBegin( GL_TRIANGLE_STRIP );
glVertex3f( .7f, 1.0f, .7f );
glVertex3f( .7f, 1.0f, -.7f );
glVertex3f( -.7f, 1.0f, .7f );
glVertex3f( -.7f, 1.0f, -.7f );
glEnd();
// right
glColor3f( 1.0f, 0.5f, 1.0f );
glNormal3f( -1.f, 0.f, 0.f );
glBegin( GL_TRIANGLE_STRIP );
glVertex3f( 1.0f, .7f, .7f );
glVertex3f( 1.0f, .7f, -.7f );
glVertex3f( 1.0f, -.7f, .7f );
glVertex3f( 1.0f, -.7f, -.7f );
glEnd();
// left
glColor3f( 0.5f, 1.0f, 1.0f );
glNormal3f( 1.f, 0.f, 0.f );
glBegin( GL_TRIANGLE_STRIP );
glVertex3f( -1.0f, .7f, .7f );
glVertex3f( -1.0f, .7f, -.7f );
glVertex3f( -1.0f, -.7f, .7f );
glVertex3f( -1.0f, -.7f, -.7f );
glEnd();
#endif
}
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
_______________________________________________
eq-dev mailing list
[email protected]
https://in-zueri.ch/cgi-bin/mailman/listinfo/eq-dev
http://www.equalizergraphics.com