effekseer / Effekseer

MIT License
1.48k stars 219 forks source link

I create a sdl2 example for effeckseer ,but cannot display ,please help #1020

Closed jcy1001 closed 2 months ago

jcy1001 commented 2 months ago

int main(int argc, char** argv) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { printf("Error: %s\n", SDL_GetError()); return -1; }

// Decide GL+GLSL versions

// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
// Create window with graphics context
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_DisplayMode mode;
if (SDL_GetCurrentDisplayMode(0, &mode))
{
    return false;
} 
int minWidth = 640;
int minHeight = 480;
int maxWidth = mode.w;
int maxHeight = mode.h;
if (maxWidth < minWidth || maxHeight < minHeight)
{ 
    return false;
}

int windowWidth = maxWidth - 200;
int windowHeight = maxHeight - 200;
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window* window = SDL_CreateWindow("SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, window_flags);
if (window == nullptr)
{
    printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
    return -1;
}

SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1);  
auto efkManager = ::Effekseer::Manager::Create(8000); 
auto graphicsDevice = ::EffekseerRendererGL::CreateGraphicsDevice(::EffekseerRendererGL::OpenGLDeviceType::OpenGL3);

::EffekseerRendererGL::RendererRef  efkRenderer = ::EffekseerRendererGL::Renderer::Create(graphicsDevice, 8000);

efkManager->SetSpriteRenderer(efkRenderer->CreateSpriteRenderer());
efkManager->SetRibbonRenderer(efkRenderer->CreateRibbonRenderer());
efkManager->SetRingRenderer(efkRenderer->CreateRingRenderer());
efkManager->SetTrackRenderer(efkRenderer->CreateTrackRenderer());
efkManager->SetModelRenderer(efkRenderer->CreateModelRenderer()); 
efkManager->SetTextureLoader(efkRenderer->CreateTextureLoader());
efkManager->SetModelLoader(efkRenderer->CreateModelLoader());
efkManager->SetMaterialLoader(efkRenderer->CreateMaterialLoader());
efkManager->SetCurveLoader(Effekseer::MakeRefPtr<Effekseer::CurveLoader>());

auto viewerPosition = ::Effekseer::Vector3D(10.0f, 5.0f, 20.0f);

::Effekseer::Matrix44 projectionMatrix;
projectionMatrix.PerspectiveFovRH(90.0f / 180.0f * 3.14f, (float)windowWidth / (float)windowHeight, 1.0f, 500.0f);

::Effekseer::Matrix44 cameraMatrix;
cameraMatrix.LookAtRH(viewerPosition, ::Effekseer::Vector3D(0.0f, 0.0f, 0.0f), ::Effekseer::Vector3D(0.0f, 1.0f, 0.0f));

auto effect = Effekseer::Effect::Create(efkManager, EFK_EXAMPLE_ASSETS_DIR_U16 "Laser01.efkefc"); 
int32_t time = 0;
Effekseer::Handle efkHandle = 0; 
bool done = false;
while (!done)
{ 
    SDL_Event event;
    while (SDL_PollEvent(&event))
    { 
        if (event.type == SDL_QUIT)
            done = true;
        if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
            done = true;
    }
    if (time % 120 == 0)
    { 
        efkHandle = efkManager->Play(effect, 0, 0, 0);
    }

    if (time % 120 == 119)
    { 
        efkManager->StopEffect(efkHandle);
    } 
    efkManager->AddLocation(efkHandle, ::Effekseer::Vector3D(0.2f, 0.0f, 0.0f)); 
    Effekseer::Manager::LayerParameter layerParameter;
    layerParameter.ViewerPosition = viewerPosition;
    efkManager->SetLayerParameter(0, layerParameter); 
    Effekseer::Manager::UpdateParameter updateParameter;
    efkManager->Update(updateParameter); 
    glViewport(0, 0, windowWidth, windowHeight);
    glClearColor(0, 0,0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT); 
    efkRenderer->SetTime(time / 60.0f); 
    efkRenderer->SetProjectionMatrix(projectionMatrix); 
    efkRenderer->SetCameraMatrix(cameraMatrix); 
    efkRenderer->BeginRendering(); 
    Effekseer::Manager::DrawParameter drawParameter;
    drawParameter.ZNear = 0.0f;
    drawParameter.ZFar = 1.0f;
    drawParameter.ViewProjectionMatrix = efkRenderer->GetCameraProjectionMatrix();
    efkManager->Draw(drawParameter); 
    efkRenderer->EndRendering(); 
    time++; 
    SDL_GL_SwapWindow(window);
} 
efkRenderer.Reset();
efkManager.Reset();
SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();  
return 0;

}

jcy1001 commented 2 months ago

51e5d7ce630e05231de037097aabe081

durswd commented 2 months ago

It seems that there is no mistakes. Is not effect null?

jcy1001 commented 2 months ago

effect is ok image

durswd commented 2 months ago

please use PerspectiveFovRH_OpenGL

jcy1001 commented 2 months ago

please use PerspectiveFovRH_OpenGL

::Effekseer::Matrix44 projectionMatrix; projectionMatrix.PerspectiveFovRH_OpenGL(90.0f / 180.0f * 3.14f, (float)windowWidth / (float)windowHeight, 1.0f, 500.0f); I try PerspectiveFovRH_OpenGL,but still cannot display

durswd commented 2 months ago

glClear(GL_COLOR_BUFFER_BIT); -> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

jcy1001 commented 2 months ago

success, Thanks bro

jcy1001 commented 2 months ago

@durswd demo use sdl is ok,i put these code to my game ,it can not display,i try debug effekseer to see why, i see it step into m_renderer->DrawSprites(bufferSize / stride / 4, vbOffset / stride); is excuted , i have no idea ,why it display no effect ,can you help me to debug this problem? ee0c4ae04182b6aee58f533b9d5e01a4

image