'Programming/openGL'에 해당되는 글 91건

  1. 2019.05.28 gluPerspective()
  2. 2019.05.10 glfw3 in ubuntu 19.04
  3. 2019.05.07 openGL vao(Vertex Array Object)
  4. 2019.05.07 glfw - gl framework
  5. 2019.05.07 openGL 3.0 tutorial
  6. 2018.04.25 openGL Stereoscopic
  7. 2018.04.25 openGL cardboard lens distortion
  8. 2016.09.07 glxgears 소스
  9. 2016.02.26 opencv opengl
  10. 2016.02.02 opengl camera의 이해
Programming/openGL2019. 5. 28. 19:04

오랫만에 다시 공부하게 되네 후..

일단 위의 함수는 z값에 대한 Near와 Far 값이 존재하는데

둘다 양수여야 하고 0 이상의 값을 가져야 한다.

(그걸 모르고 예전엔 0을 넣고 왜 안되는 거야! 하고 있었으니..)

zNear

Specifies the distance from the viewer to the near clipping plane (always positive).

zFar

Specifies the distance from the viewer to the far clipping plane (always positive).

Notes

Depth buffer precision is affected by the values specified for zNear and zFar. The greater the ratio of zFar to zNear is, the less effective the depth buffer will be at distinguishing between surfaces that are near each other. If

r = zFar zNear

roughly log 2  r bits of depth buffer precision are lost. Because r approaches infinity as zNear approaches 0, zNear must never be set to 0.

[링크 : https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml]

 

실제코드인진 모르겠지만

znear가 0 이면, ymax xmax가 다 0이 되네

// Matrix will receive the calculated perspective matrix.
// You would have to upload to your shader
// or use glLoadMatrixf if you aren't using shaders.
void glhPerspectivef2(float *matrix, float fovyInDegrees, float aspectRatio,
                      float znear, float zfar)
{
    float ymax, xmax;
    float temp, temp2, temp3, temp4;
    ymax = znear * tanf(fovyInDegrees * M_PI / 360.0);
    // ymin = -ymax;
    // xmin = -ymax * aspectRatio;
    xmax = ymax * aspectRatio;
    glhFrustumf2(matrix, -xmax, xmax, -ymax, ymax, znear, zfar);
}

 

DIV/0의 향연이니.. 아마 입력 단계에서 zNear / nFar가 0이면 계산을 하지 않도록 할지도?

void glhFrustumf2(float *matrix, float left, float right, float bottom, float top,
                  float znear, float zfar)
{
    float temp, temp2, temp3, temp4;
    temp = 2.0 * znear;
    temp2 = right - left;
    temp3 = top - bottom;
    temp4 = zfar - znear;
    matrix[0] = temp / temp2;
    matrix[1] = 0.0;
    matrix[2] = 0.0;
    matrix[3] = 0.0;
    matrix[4] = 0.0;
    matrix[5] = temp / temp3;
    matrix[6] = 0.0;
    matrix[7] = 0.0;
    matrix[8] = (right + left) / temp2;
    matrix[9] = (top + bottom) / temp3;
    matrix[10] = (-zfar - znear) / temp4;
    matrix[11] = -1.0;
    matrix[12] = 0.0;
    matrix[13] = 0.0;
    matrix[14] = (-temp * zfar) / temp4;
    matrix[15] = 0.0;
}

[링크 : https://www.khronos.org/opengl/wiki/GluPerspective_code]

'Programming > openGL' 카테고리의 다른 글

glulookat / gluperspective / glfrustrum / glortho  (0) 2019.05.30
gl model view projection mat  (0) 2019.05.29
glfw3 in ubuntu 19.04  (0) 2019.05.10
openGL vao(Vertex Array Object)  (0) 2019.05.07
glfw - gl framework  (0) 2019.05.07
Posted by 구차니
Programming/openGL2019. 5. 10. 08:34

원인은 모르겠는데.. 링크할때 파일명이랑 순서가 영향을 주네? 머지?

 

$ sudo apt-get install libglfw3-dev libglfw3

$ vi glfw.c

#include <GLFW/glfw3.h>
#include 
#include 
static void error_callback(int error, const char* description)
{
    fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
    GLFWwindow* window;
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(EXIT_FAILURE);
    window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);
    while (!glfwWindowShouldClose(window))
    {
        float ratio;
        int width, height;
        glfwGetFramebufferSize(window, &width, &height);
        ratio = width / (float) height;
        glViewport(0, 0, width, height);
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
        glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-0.6f, -0.4f, 0.f);
        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(0.6f, -0.4f, 0.f);
        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(0.f, 0.6f, 0.f);
        glEnd();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

$ gcc glfw.c -lglfw -lGL

 

[링크 : https://www.glfw.org/docs/3.0/quick.html]

'Programming > openGL' 카테고리의 다른 글

gl model view projection mat  (0) 2019.05.29
gluPerspective()  (0) 2019.05.28
openGL vao(Vertex Array Object)  (0) 2019.05.07
glfw - gl framework  (0) 2019.05.07
openGL 3.0 tutorial  (0) 2019.05.07
Posted by 구차니
Programming/openGL2019. 5. 7. 08:17

gl3.0 버전 이후 부터 추가된 내용

기존에 버전에서는 Vertex Array Object가 아니라

Vertex Array나 List로 무언가 등록해서 쓰는게 있던거 같은데 기억이 가물가물 하네

 

[링크 : https://www.khronos.org/opengl/wiki/Vertex_Specification]

 

 

'Programming > openGL' 카테고리의 다른 글

gluPerspective()  (0) 2019.05.28
glfw3 in ubuntu 19.04  (0) 2019.05.10
glfw - gl framework  (0) 2019.05.07
openGL 3.0 tutorial  (0) 2019.05.07
openGL Stereoscopic  (0) 2018.04.25
Posted by 구차니
Programming/openGL2019. 5. 7. 08:14

openGL 3.0 하는데 glfw 라는 새로운 라이브러리가 보여서 검색.

glut나 glu 등을 대체하는 녀석인가?

 

[링크 : https://www.glfw.org]

[링크 : https://en.wikipedia.org/wiki/GLFW]

'Programming > openGL' 카테고리의 다른 글

glfw3 in ubuntu 19.04  (0) 2019.05.10
openGL vao(Vertex Array Object)  (0) 2019.05.07
openGL 3.0 tutorial  (0) 2019.05.07
openGL Stereoscopic  (0) 2018.04.25
openGL cardboard lens distortion  (0) 2018.04.25
Posted by 구차니
Programming/openGL2019. 5. 7. 08:07

언제 또 버전이 이렇게 올랐냐...

기존에 공부하던건 잊고 새로운 glfw라는걸 써야 할 듯

 

[링크 : http://www.opengl-tutorial.org/kr/beginners-tutorials/tutorial-2-the-first-triangle/]

'Programming > openGL' 카테고리의 다른 글

openGL vao(Vertex Array Object)  (0) 2019.05.07
glfw - gl framework  (0) 2019.05.07
openGL Stereoscopic  (0) 2018.04.25
openGL cardboard lens distortion  (0) 2018.04.25
glxgears 소스  (0) 2016.09.07
Posted by 구차니
Programming/openGL2018. 4. 25. 09:56

어디였나.. 뷰포트로 두개 하면 된다고 하는데

예전에 내가 스테레오 비전 만든것도 뷰포트였나? 기억이 안나네..


GLvoid display(GLvoid)

{

  glDrawBuffer(GL_BACK);                                   //draw into both back buffers

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);      //clear color and depth buffers


  glDrawBuffer(GL_BACK_LEFT);                              //draw into back left buffer

  glMatrixMode(GL_MODELVIEW);

  glLoadIdentity();                                        //reset modelview matrix

  gluLookAt(-IOD/2,                                        //set camera position  x=-IOD/2

            0.0,                                           //                     y=0.0

            0.0,                                           //                     z=0.0

            0.0,                                           //set camera "look at" x=0.0

            0.0,                                           //                     y=0.0

            screenZ,                                       //                     z=screenplane

            0.0,                                           //set camera up vector x=0.0

            1.0,                                           //                     y=1.0

            0.0);                                          //                     z=0.0

  

  glPushMatrix();

  {

    glTranslatef(0.0, 0.0, depthZ);                        //translate to screenplane

    drawscene();

  }

  glPopMatrix();


  glDrawBuffer(GL_BACK_RIGHT);                             //draw into back right buffer

  glMatrixMode(GL_MODELVIEW);

  glLoadIdentity();                                        //reset modelview matrix

  gluLookAt(IOD/2, 0.0, 0.0, 0.0, 0.0, screenZ,            //as for left buffer with camera position at:

            0.0, 1.0, 0.0);                                //                     (IOD/2, 0.0, 0.0)


  glPushMatrix();

  {

    glTranslatef(0.0, 0.0, depthZ);                        //translate to screenplane

    drawscene();

  }

  glPopMatrix();

  

  glutSwapBuffers();

[링크 : http://www.orthostereo.com/geometryopengl.html]


The default framebuffer contains up to 4 color buffers, named GL_FRONT_LEFT, GL_BACK_LEFT, GL_FRONT_RIGHT, and GL_BACK_RIGHT. The left and right buffers are used for stereoscopic rendering

[링크 : https://www.khronos.org/opengl/wiki/Default_Framebuffer]



glulookat 쓴거 보면 맞는 듯?

기본 컨셉은 비슷한데 위에 예제는 openGL에서 스테레오 스코픽 지원 기능을 쓰고 있는 거군

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT);


glMatrixMode(GL_MODELVIEW); //GL_PROJECTION

glPushMatrix();

glViewport(0, 0, 250, 250); 

gluLookAt(0.10, 0.0, 0.2, 0.0, 0.0, -2.0, 0.0, 1.0, 0.0);

draw_sin();

glPopMatrix();


glPushMatrix();

glViewport(250, 0, 250, 250); 

gluLookAt(0.2, 0.0, 0.2, 0.0, 0.0, -2.0, 0.0, 1.0, 0.0);

draw_sin();

glPopMatrix();


glutSwapBuffers();

2011/10/08 - [Programming/openGL] - openGL의 미스테리...

'Programming > openGL' 카테고리의 다른 글

glfw - gl framework  (0) 2019.05.07
openGL 3.0 tutorial  (0) 2019.05.07
openGL cardboard lens distortion  (0) 2018.04.25
glxgears 소스  (0) 2016.09.07
opencv opengl  (0) 2016.02.26
Posted by 구차니
Programming/openGL2018. 4. 25. 09:52

구글 카드보드 같은거 써서 보려면

영상을 왜곡해야 하는데(왜곡이란 단어부터 생각이 안남... ㅠㅠ)



[링크 : https://stackoverflow.com/questions/44489686/camera-lens-distortion-in-opengl]

[링크 : http://smus.com/vr-lens-distortion/]

[링크 : https://www.opengl.org/discussion_boards/showthread.php/197596-Pincushion-Distortion-with-a-Camera]


+

[링크 : https://github.com/googlevr/gvr-android-sdk/.../videoplayer/VideoScene.java]

[링크 : https://github.com/googlevr/gvr-android-sdk/.../videoplayer/VideoSceneRenderer.java]

[링크 : http://www.freevr.org/downloads.html]

[링크 : https://arm-software.github.io/vr-sdk-for-android/IntroductionToStereoRendering.html] <<<

https://support.google.com/cardboard/manufacturers/answer/6324808?hl=en

'Programming > openGL' 카테고리의 다른 글

openGL 3.0 tutorial  (0) 2019.05.07
openGL Stereoscopic  (0) 2018.04.25
glxgears 소스  (0) 2016.09.07
opencv opengl  (0) 2016.02.26
opengl camera의 이해  (0) 2016.02.02
Posted by 구차니
Programming/openGL2016. 9. 7. 14:46

웬지 벤치마크 용으로 쓰이는 예제

카메라 위치 라던가 애니메이션이라던가

기어 크기라던가 중심으로 분석해봐야지


[링크 : https://fossies.org/dox/mesa-demos-8.3.0/glxgears_8c_source.html]

'Programming > openGL' 카테고리의 다른 글

openGL Stereoscopic  (0) 2018.04.25
openGL cardboard lens distortion  (0) 2018.04.25
opencv opengl  (0) 2016.02.26
opengl camera의 이해  (0) 2016.02.02
myAHRS cube 예제  (0) 2016.02.02
Posted by 구차니
Programming/openGL2016. 2. 26. 18:39


[링크 : http://babytiger.tistory.com/entry/OpenCV로-생성한-영상을-OpenGL-윈도우에-표시]

[링크 : http://docs.opencv.org/2.4/modules/core/doc/opengl_interop.html#]

'Programming > openGL' 카테고리의 다른 글

openGL cardboard lens distortion  (0) 2018.04.25
glxgears 소스  (0) 2016.09.07
opengl camera의 이해  (0) 2016.02.02
myAHRS cube 예제  (0) 2016.02.02
openCV <-> openGL  (0) 2015.09.24
Posted by 구차니
Programming/openGL2016. 2. 2. 19:24


8.010 How does the camera work in OpenGL?


As far as OpenGL is concerned, there is no camera. More specifically, the camera is always located at the eye space coordinate (0., 0., 0.). To give the appearance of moving the camera, your OpenGL application must move the scene with the inverse of the camera transformation.


8.020 How can I move my eye, or camera, in my scene?


OpenGL doesn't provide an interface to do this using a camera model. However, the GLU library provides the gluLookAt() function, which takes an eye position, a position to look at, and an up vector, all in object space coordinates. This function computes the inverse camera transform according to its parameters and multiplies it onto the current matrix stack.


[링크 : https://www.opengl.org/archives/resources/faq/technical/viewing.htm]

    [링크 : http://gamedev.stackexchange.com/.../why-do-we-move-the-world-instead-of-the-camera] 


[링크 : http://blog.secmem.org/132]

[링크 : http://darkpgmr.tistory.com/84]

[링크 : http://gcland.tistory.com/189]


[링크 : https://www.opengl.org/archives/resources/code/samples/redbook/]

'Programming > openGL' 카테고리의 다른 글

glxgears 소스  (0) 2016.09.07
opencv opengl  (0) 2016.02.26
myAHRS cube 예제  (0) 2016.02.02
openCV <-> openGL  (0) 2015.09.24
openGL triangle winding  (0) 2015.07.22
Posted by 구차니