Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 Strange behavior

Go down 
2 posters
AuthorMessage
jubei

jubei


Messages : 7
Date d'inscription : 2011-08-13

Strange behavior Empty
PostSubject: Strange behavior   Strange behavior Icon_minitimeSun Aug 14, 2011 1:22 am

I've compiled a project by following the tutorial pdf and I get rather strange behaviour:

Video: flickr.com/photos/jubeigr/6040508594/lightbox/

That box has an intel graphics board that supports openGL up to 2.1.

On another box (Nvidia GT220 - Cuda) the exact same code produces absolutely no output (although I can tell something's happening because when I press space to launch a firework the mouse has a big delay)

Any tips would be appreciated.

Code:


#include <GL/glew.h>

#include <iostream>
#include <SPK.h>
#include <SPK_GL.h>
#include <time.h>
#include <deque>
#define WIN32_LEAN_AND_MEAN
#include <GL/glfw.h>

using namespace SPK;
using namespace SPK::GL;

SPK_ID BaseSystemID = NO_ID;
std::deque<SPK::System*> particleSystems;

System* createParticleSystem(const Vector3D& pos,const Vector3D& color)
{
System* system = SPK_Copy(System,BaseSystemID);
Model* model = system->getGroup(0)->getModel();
model->setParam(PARAM_RED,max(0.0f,color.x - 0.25f),min(1.0f,color.x + 0.25f));
model->setParam(PARAM_GREEN,max(0.0f,color.y - 0.25f),min(1.0f,color.y + 0.25f));
model->setParam(PARAM_BLUE,max(0.0f,color.z - 0.25f),min(1.0f,color.z + 0.25f));
Zone* zone = system->getGroup(0)->getEmitter(0)->getZone();
zone->setPosition(pos);
return system;
}

int main() {

   GLuint textureIndex;

   int screenWidth = 800;
   int screenHeight = 600;

   randomSeed = static_cast<unsigned int>(time(NULL));

   int running = GL_TRUE;

    if (!glfwInit()) { std::cout << "Initialization of GLFW Failed"; }

    if (!glfwOpenWindow(screenWidth,screenHeight,0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { std::cout << "Window init failed"; }
    glewInit();
    glfwSetWindowPos( 500, 200 );


   Model* model = Model::create
      (
      FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA,
      FLAG_ALPHA,
      FLAG_RED | FLAG_GREEN | FLAG_BLUE
      );

   model->setParam(PARAM_ALPHA,1.0f,0.0f);
model->setLifeTime(1.0f,2.0f);

// Creates the zone
Point* source = Point::create();
// Creates the emitter
RandomEmitter* emitter = RandomEmitter::create();
emitter->setZone(source);
emitter->setForce(2.8f,3.2f);
emitter->setTank(500);
emitter->setFlow(-1);

GLPointRenderer* renderer = GLPointRenderer::create();
renderer->setType(POINT_SPRITE);
renderer->enableWorldSize(true);
GLPointRenderer::setPixelPerUnit(45.0f * 3.14159f / 180.f,screenHeight);
renderer->setSize(0.1f);

glGenTextures(1,&textureIndex);
renderer->setTexture(textureIndex);

//**************????????????????
renderer->setBlendingFunctions(BLENDING_ADD,BLENDING_ADD);  //**************????????????????
//**************????????????????

renderer->setTextureBlending(GL_MODULATE);
renderer->enableRenderingHint(DEPTH_WRITE,false);

Group* group = Group::create(model,500);

group->addEmitter(emitter);
group->setRenderer(renderer);

group->setGravity(Vector3D(0.0f,-1.0f,0.0f));
group->setFriction(1.0f);

System* system = System::create();
system->addGroup(group);

model->setShared(true);
renderer->setShared(true);


BaseSystemID = system->getID();

std::deque<System*>::const_iterator it;


    while( running )
    {
        glClearColor(0.0f,0.0f,0.0f,0.0f);
        glClear( GL_COLOR_BUFFER_BIT );

      if (glfwGetKey(GLFW_KEY_SPACE)) {
         particleSystems.push_back(createParticleSystem(Vector3D(0.5,0.5,0.5),Vector3D(0.6f,0.5f,0.4f)));
      }

      it = particleSystems.begin();
      while(it != particleSystems.end())
      {if (!(*it)->update(/*deltaTime */ 0.005f))
      {
         /*destroyParticleSystem(*it);*/
         it = particleSystems.erase(it);
      }
      else
         ++it;
      }


      
      for (it = particleSystems.begin(); it != particleSystems.end(); ++it)
         (*it)->render();


        glfwSwapBuffers();

        running = !glfwGetKey( GLFW_KEY_ESC ) &&
                glfwGetWindowParam( GLFW_OPENED );

      
    }

   //for (it = particleSystems.begin(); it != particleSystems.end(); ++it)
      //   destroyParticleSystem(&it);
    SPKFactory::getInstance().destroyAll();
    glfwTerminate();

   return 0;
}

void destroyParticleSystem(System*& system)
{
SPK_Destroy(system);
system = NULL;
}

pastebin.com/vM8en9q7
Back to top Go down
jubei

jubei


Messages : 7
Date d'inscription : 2011-08-13

Strange behavior Empty
PostSubject: Re: Strange behavior   Strange behavior Icon_minitimeSun Aug 14, 2011 6:09 am

I just realized that the tutorial is not standalone and that it's part of the source code package. I am wondering if I can make it work without SDL (glfw or glut).

Jubei
Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

Strange behavior Empty
PostSubject: Re: Strange behavior   Strange behavior Icon_minitimeSun Aug 14, 2011 9:12 am

Hi, I took a look at your code and there are some mistakes in it :

Code:
//**************????????????????
renderer->setBlendingFunctions(BLENDING_ADD,BLENDING_ADD);  //**************????????????????
//**************????????????????

This should not be used this way. To set the blend mode of a renderer, you should use setBlending. setBlendingFunctions allows to use directly OpenGL interface to have more possibilities than common ones for the blending. Here you re passing a spark enum while the methods needs opengl defines. So you need to replace this call by :

Code:
renderer->setBlending(BLENDING_ADD)

When creating your model, you set the color flags to random so that the color will be randomly generated for each particles but you didnt define the boundaries. You should call :

Code:

model->setParam(PARAM_RED,0.0f,1.0f);
model->setParam(PARAM_GREEN,0.0f,1.0f);
model->setParam(PARAM_BLUE,0.0f,1.0f);

with the values you want as boundaries (In my example it is a completely random color for each particles)

You can also consider using a GLQuadRenderer instead of a GLPointRenderer, as it may be supported better by hardware.

Finally, by looking at the video, you're creating lots of big particles on screen, that can lead to performance issues to to the fill rate of your gpu. Try reducing the size of your particles to get better performance.

Hope this helps
Back to top Go down
http://spark.developpez.com
jubei

jubei


Messages : 7
Date d'inscription : 2011-08-13

Strange behavior Empty
PostSubject: Re: Strange behavior   Strange behavior Icon_minitimeSun Aug 14, 2011 9:52 am

Juff,

First of all congratulations for the amazing library you have created and thank you for taking time to answer my post!

I will try your suggestions first thing tomorrow morning. Today I tried very hard to get your tutorial1.cpp to run but SDL didn't seem to want to cooperate since I got blank output.

Perhaps you will allow me to contribute a tutorial with another context library (like glfw) in the near future.

Anyway great work and thank you for the support.

Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

Strange behavior Empty
PostSubject: Re: Strange behavior   Strange behavior Icon_minitimeFri Aug 19, 2011 2:08 pm

Are you using the same SDL.dll to compile and run ?
Back to top Go down
http://spark.developpez.com
jubei

jubei


Messages : 7
Date d'inscription : 2011-08-13

Strange behavior Empty
PostSubject: Re: Strange behavior   Strange behavior Icon_minitimeFri Aug 19, 2011 10:34 pm

Juff, thank you for the reply. I couldn't get the texture to load properly with SDL so I resorted to DevIL for loading it and it worked fine. Thank you for all the help. Keep up the great work on spark!

Jubei
Back to top Go down
Sponsored content





Strange behavior Empty
PostSubject: Re: Strange behavior   Strange behavior Icon_minitime

Back to top Go down
 
Strange behavior
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Questions (en)-
Jump to: