Új hozzászólás Aktív témák

  • Karma

    félisten

    válasz Denzelii #4 üzenetére

    [link]

    Bedobod a forráskódot, és ide csak egy linket másolsz róla.
    Tud syntax highlightingot is.

  • Denzelii

    csendes tag

    Lenne egy kérdésem is: opengl ES 1.1, 2D (teszt jelleggel, egy mozgatási sebességet szeretnék kipróbálni). De nem jelenik meg a háromszögem, és nem értem miért nem.

    (projektet nem tudok csatolni sajna, kell emailben elküldöm)

    #include "Form1.h"

    using namespace Osp::Base;
    using namespace Osp::Ui;
    using namespace Osp::Ui::Controls;
    using namespace Osp::Graphics;
    using namespace Osp::Graphics::Opengl;
    using namespace Osp::App;

    #define USE_PBUFFER
    //#define DISPLAY_FPS
    //#define USE_GLFIXED
    //#define USE_PIXMAP

    int GetPowerOf2(int value)
    {
    int result = 1;

    while (result < value)
    result <<= 1;

    return result;
    }

    Form1::Form1(void)
    {
    __eglDisplay = EGL_DEFAULT_DISPLAY;
    __eglConfig = null;
    __eglSurface = EGL_NO_SURFACE;
    __eglContext = EGL_NO_CONTEXT;
    __pbuffer_surface = EGL_NO_SURFACE;
    }

    Form1::~Form1(void)
    {
    }

    bool
    Form1::Initialize()
    {
    result r;
    // Construct an XML form
    //Construct(L"IDF_FORM1");
    r = Form::Construct(FORM_STYLE_NORMAL|FORM_STYLE_INDICATOR);
    if (r != E_SUCCESS) {
    AppLog("#Error# Error while constructing Form1 [%S].\n", GetErrorMessage(r));
    return false;
    }
    SetName(L"IDF_FORM1");
    SetOrientation(ORIENTATION_LANDSCAPE);
    SetBackgroundColor(Color(0,0,0,0));
    return true;
    }

    result
    Form1::OnInitializing(void)
    {
    result r = E_SUCCESS;
    bool b;

    // TODO: Add your initialization code here
    b = InitEGL();
    if (b == false) {
    AppLog("InitEgl error: %s", GetErrorMessage(r));
    return E_FAILURE;
    }
    b = InitGL();
    if (b == false) {
    AppLog("InitGl error: %s", GetErrorMessage(r));
    return E_FAILURE;
    }

    return r;
    }

    result
    Form1::OnTerminating(void)
    {
    result r = E_SUCCESS;

    // TODO: Add your termination code here

    return r;
    }

    result
    Form1::OnDraw(void)
    {
    AppLog("draw");
    GLDraw();
    return E_SUCCESS;
    }

    bool
    Form1::InitEGL()
    {
    EGLint numConfigs = 1;
    EGLint eglConfigList[] = {
    EGL_RED_SIZE, 5,
    EGL_GREEN_SIZE, 6,
    EGL_BLUE_SIZE, 5,
    EGL_ALPHA_SIZE, 0,
    EGL_DEPTH_SIZE, 8,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
    EGL_NONE
    };
    EGLint eglContextList[] = {
    EGL_CONTEXT_CLIENT_VERSION, 1,
    EGL_NONE
    };
    AppLog("1");
    eglBindAPI(EGL_OPENGL_ES_API);

    if (__eglDisplay)
    {
    DestroyGL();
    }
    AppLog("2");
    __eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
    if (EGL_NO_DISPLAY == __eglDisplay)
    {
    AppLog("[GlesCube11] eglGetDisplay() is failed. [0x%x]\n", eglGetError());
    goto CATCH;
    }
    AppLog("3");
    if (EGL_FALSE == eglInitialize(__eglDisplay, null, null) ||
    EGL_SUCCESS != eglGetError())
    {
    AppLog("[GlesCube11] eglInitialize() is failed. [0x%x]\n", eglGetError());
    goto CATCH;
    }
    AppLog("4");
    if (EGL_FALSE == eglChooseConfig(__eglDisplay, eglConfigList, &__eglConfig, 1, &numConfigs) ||
    EGL_SUCCESS != eglGetError())
    {
    AppLog("[GlesCube11] eglChooseConfig() is failed. [0x%x]\n", eglGetError());
    goto CATCH;
    }
    AppLog("5");
    if (!numConfigs)
    {
    AppLog("[GlesCube11] eglChooseConfig() has been failed. because of matching config doesn't exist \n");
    goto CATCH;
    }
    AppLog("6");
    __eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, (EGLNativeWindowType)this, null);

    if (EGL_NO_SURFACE == __eglSurface ||
    EGL_SUCCESS != eglGetError())
    {
    AppLog("[GlesCube11] eglCreateWindowSurface() has been failed. EGL_NO_SURFACE [0x%x]\n", eglGetError());
    goto CATCH;
    }
    AppLog("7");
    __eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextList);
    if (EGL_NO_CONTEXT == __eglContext ||
    EGL_SUCCESS != eglGetError())
    {
    AppLog("[GlesCube11] eglCreateContext() has been failed. [0x%x]\n", eglGetError());
    goto CATCH;
    }
    AppLog("8");
    if (false == eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) ||
    EGL_SUCCESS != eglGetError())
    {
    AppLog("[GlesCube11] eglMakeCurrent() has been failed. [0x%x]\n", eglGetError());
    goto CATCH;
    }
    AppLog("9");
    return true;

    CATCH:
    AppLog("initegl error");
    return false;
    }

    bool
    Form1::InitGL()
    {
    int x, y, width, height;

    Application::GetInstance()->GetAppFrame()->GetFrame()->GetBounds(x, y, width, height);

    EGLint surfaceType;

    eglGetConfigAttrib(__eglDisplay, __eglConfig, EGL_SURFACE_TYPE, &surfaceType);
    AppLog("a");
    #if defined(USE_PBUFFER)
    if ((surfaceType & EGL_PBUFFER_BIT) > 0)
    {
    EGLint pbuffer_attribs[] =
    {
    EGL_WIDTH, GetPowerOf2(width),
    EGL_HEIGHT, GetPowerOf2(height),
    EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
    EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
    EGL_NONE
    };

    __pbuffer_surface = eglCreatePbufferSurface(__eglDisplay, __eglConfig, pbuffer_attribs);

    if (__pbuffer_surface != EGL_NO_SURFACE)
    {
    eglQuerySurface(__eglDisplay, __pbuffer_surface, EGL_WIDTH, &__pbuffer_width);
    eglQuerySurface(__eglDisplay, __pbuffer_surface, EGL_HEIGHT, &__pbuffer_height);

    /*glGenTextures(1, &__pbuffer_texture);
    glBindTexture(GL_TEXTURE_2D, __pbuffer_texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);*/
    }
    }
    #endif

    #if defined(USE_PIXMAP)
    if ((surfaceType & EGL_PIXMAP_BIT) > 0)
    {
    __pBitmap = new Bitmap;
    result r = __pBitmap->Construct(Osp::Graphics::Rectangle(0, 0, 480, 800));

    EGLint pixmap_attribs[] = {
    EGL_WIDTH, 480,
    EGL_HEIGHT, 800,
    EGL_NONE
    };

    __pixmap_surface = eglCreatePixmapSurface(__eglDisplay, __eglConfig, (NativePixmapType)__pBitmap, pixmap_attribs);

    if (__pixmap_surface == EGL_NO_SURFACE)
    {
    delete __pBitmap;
    __pBitmap = null;
    }
    }
    #endif

    /* {
    glGenTextures(2, __texture);

    glBindTexture(GL_TEXTURE_2D, __texture[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, image4444_128_128_1);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glBindTexture(GL_TEXTURE_2D, __texture[1]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, image565_128_128_1);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    }*/
    AppLog("b");
    glShadeModel(GL_SMOOTH);

    glViewport(0, 0, width, height);

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    //glEnable(GL_DEPTH_TEST);
    glDisable(GL_DEPTH_TEST);
    //glDepthFunc(GL_LESS);

    glLoadIdentity();
    glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

    //glMatrixMode(GL_PROJECTION);
    glMatrixMode(GL_MODELVIEW);

    AppLog("c");

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    AppLog("d");
    return true;
    }

    void
    Form1::DestroyGL()
    {
    /*glDeleteTextures(2, __texture);

    if (__pbuffer_texture)
    {
    glDeleteTextures(1, &__pbuffer_texture);
    __pbuffer_texture = 0;
    }*/

    if (EGL_NO_DISPLAY != __eglDisplay)
    {
    eglMakeCurrent(__eglDisplay, null, null, null);

    if (__pbuffer_surface != EGL_NO_SURFACE)
    {
    eglDestroySurface(__eglDisplay, __pbuffer_surface);
    __pbuffer_surface = EGL_NO_SURFACE;
    }

    {
    eglDestroySurface(__eglDisplay, __pixmap_surface);
    __pixmap_surface = EGL_NO_SURFACE;
    }

    if (__eglContext != EGL_NO_CONTEXT)
    {
    eglDestroyContext(__eglDisplay, __eglContext);
    __eglContext = EGL_NO_CONTEXT;
    }

    if (__eglSurface != EGL_NO_SURFACE)
    {
    eglDestroySurface(__eglDisplay, __eglSurface);
    __eglSurface = EGL_NO_SURFACE;
    }

    eglTerminate(__eglDisplay);
    __eglDisplay = EGL_NO_DISPLAY;
    }

    __eglConfig = null;
    /* __texture_index = 0;
    __texture[0] = 0;
    __texture[1] = 0;*/

    return;
    }

    result
    Form1::GLDraw()
    {
    if (GL_FALSE == eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) ||
    EGL_SUCCESS != eglGetError())
    {
    return false;
    }

    glClear(GL_COLOR_BUFFER_BIT);

    const GLfloat quadVertices[] = {
    -1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, -1.0f, 0.0f,
    -1.0f, -1.0f, 0.0f

    };

    glColor4f(1,0,0,0);
    if (EGL_SUCCESS != eglGetError()) {AppLog("EGL error: glColor\n");}
    glVertexPointer(3, GL_FLOAT, 0, quadVertices);
    if (EGL_SUCCESS != eglGetError()) {AppLog("EGL error: glVertexPointer\n");}
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    if (EGL_SUCCESS != eglGetError()) {AppLog("EGL error: glDrawArrays\n");}

    glFinish();
    if (EGL_SUCCESS != eglGetError()) {AppLog("EGL error: glFinish\n");}

    eglSwapBuffers(__eglDisplay, __eglSurface);


    /*int x, y, width, height;
    Application::GetInstance()->GetAppFrame()->GetFrame()->GetBounds(x, y, width, height);
    glViewport(0, 0, width, height);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    const GLfloat quadVertices[] = {
    -1.0f, 1.0f, 0.0f,
    1.0f, 1.0f, 0.0f,
    1.0f, -1.0f, 0.0f,
    -1.0f, -1.0f, 0.0f

    };

    //glVertexPointer(3, GL_FLOAT, 0, quadVertices);
    //glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    glFinish();

    eglSwapBuffers(__eglDisplay, __eglSurface);*/

    /*#ifdef DISPLAY_FPS
    static float fps = 0.0f;
    static float updateInterval = 1000.0f;
    static float timeSinceLastUpdate = 0.0f;
    static float frameCount = 0;
    static long long currentTick;
    static long long lastTick;
    static bool isFirst = true;

    if (isFirst)
    {
    SystemTime::GetTicks(currentTick);
    lastTick = currentTick;
    isFirst = false;
    }

    frameCount++;
    SystemTime::GetTicks(currentTick);

    float elapsed = currentTick - lastTick;

    lastTick = currentTick;
    timeSinceLastUpdate += elapsed;

    if (timeSinceLastUpdate > updateInterval)
    {
    if (timeSinceLastUpdate)
    {
    fps = (frameCount / timeSinceLastUpdate) * 1000.f;
    AppLog("[GlesCube] FPS: %f frames/sec\n", fps);

    frameCount = 0;
    timeSinceLastUpdate -= updateInterval;
    }
    }
    #endif*/

    return true;
    }

  • Denzelii

    csendes tag

    Köszönöm :)

    Jó látni, hogy más is használ ilyen debugokat: AppLog("anyad"); :D

    /*mondjuk ma már nem, mert volt hogy bennmaradt termékben, és az nemszép, de régen nekem is ez volt a leggyakoribb*/

Új hozzászólás Aktív témák