Programming/openGL2025. 4. 28. 19:06

Open Asset Import Library(assimp) 를 이용해서 blender를 읽어오고 openGL로 그릴수 있는 것으로 보인다.

 

Features

  • Reads more than 30 3D file formats, including Collada, X, 3DS, Blend, Obj
  • Converts them to a hierarchical in-memory data structure
  • Provides 'post-processing steps' to improve the input data, i.e. generate normals and tangents or fix import issues.
  • Provides APIs for both C and C++
  • Imports skeleton animations and skinning weights
  • Supports complex multi-layer materials
  • www.open3mod.com/ is an Open-Source viewer that is based off assimp to view models (Windows only)

[링크 : https://sourceforge.net/projects/assimp/]

 

Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(filename,aiProcessPreset_TargetRealtime_Fast);
aiMesh *mesh = scene->mMeshes[0]; //assuming you only want the first mesh

float *vertexArray;
float *normalArray;
float *uvArray;

int numVerts;
next extract the data

numVerts = mesh->mNumFaces*3;

vertexArray = new float[mesh->mNumFaces*3*3];
normalArray = new float[mesh->mNumFaces*3*3];
uvArray = new float[mesh->mNumFaces*3*2];

for(unsigned int i=0;i<mesh->mNumFaces;i++)
{
    const aiFace& face = mesh->mFaces[i];

    for(int j=0;j<3;j++)
    {
        aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
        memcpy(uvArray,&uv,sizeof(float)*2);
        uvArray+=2;

        aiVector3D normal = mesh->mNormals[face.mIndices[j]];
        memcpy(normalArray,&normal,sizeof(float)*3);
        normalArray+=3;

        aiVector3D pos = mesh->mVertices[face.mIndices[j]];
        memcpy(vertexArray,&pos,sizeof(float)*3);
        vertexArray+=3;
    }
}

uvArray-=mesh->mNumFaces*3*2;
normalArray-=mesh->mNumFaces*3*3;
vertexArray-=mesh->mNumFaces*3*3;

[링크 : https://nickthecoder.wordpress.com/2013/01/20/mesh-loading-with-assimp/]

    [링크 : https://stackoverflow.com/questions/35111681/make-a-model-in-blender-and-load-in-opengl]

 

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

opengl glortho gluperspective  (0) 2023.08.28
glReadPixels() 와 glUseProgram()  (0) 2022.11.17
openCV + openGL  (0) 2022.02.08
glMatrixMode()  (0) 2020.04.14
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
Posted by 구차니
Programming/openGL2023. 8. 28. 19:28

orthogonal(직교)

perspective(원근)

 

-1.0 ~ 1.0 사이로 정규화 해야 한다는데, 그래서 이전에 막 잘리고 난리였던 듯..

[링크 : https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix.html]

[링크 : https://heinleinsgame.tistory.com/m/11]

 

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

blender in openGL  (0) 2025.04.28
glReadPixels() 와 glUseProgram()  (0) 2022.11.17
openCV + openGL  (0) 2022.02.08
glMatrixMode()  (0) 2020.04.14
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
Posted by 구차니
Programming/openGL2022. 11. 17. 17:49

wayland / weston 에서 glReadPixels를 통해 읽어 오는게 실패해서 찾아보니

glUserProgram()을 하면 된다는데.. 문제는 어떤 컨텍스트의 정보를 어떻게 받아오냐 일 듯..

 

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, output->width, output->height, GL_RGBA, GL_UNSIGNED_BYTE, data);

[링크 : https://github.com/ereslibre/wayland/blob/master/compositor/screenshooter.c]

 

It's an error to call anything but a very limited set of functions between glBegin and glEnd. That list is mostly composed of functions related to specifying attributes of a vertex (e.g., glVertex, glNormal, glColor, glTexCoord, etc.).

So, if your OpenGL implementation is following the OpenGL specification, glReadPixels should return immediately without executing because of being called within a glBegin/glEnd group. Remove those from around your calls, and glReadPixels should work as expected.

[링크 : https://stackoverflow.com/questions/19351568/glreadpixels-doesnt-work]

 

I figured it out. All I had to do was add glUseProgram(0) at the very end of the draw cylinder function. After more than 3 weeks of looking into this.

[링크 : https://computergraphics.stackexchange.com/questions/8354/why-is-glreadpixels-only-working-in-certain-cases]

 

glUseProgram — Installs a program object as part of current rendering state

[링크 : https://registry.khronos.org/OpenGL-Refpages/gl4/html/glUseProgram.xhtml]

[링크 : https://stackoverflow.com/questions/13546461/what-does-gluseprogram0-do]

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

blender in openGL  (0) 2025.04.28
opengl glortho gluperspective  (0) 2023.08.28
openCV + openGL  (0) 2022.02.08
glMatrixMode()  (0) 2020.04.14
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
Posted by 구차니
Programming/openGL2022. 2. 8. 12:47

mat 변수가 나오는걸 봐서는 구버전이라.. 요즘꺼에 돌려보려면 조금 고생할 듯.

openGL은 텍스쳐까진 보질 못해서 코드를 이해 못하겠네..

 

[링크 : https://webnautes.tistory.com/1098]

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

opengl glortho gluperspective  (0) 2023.08.28
glReadPixels() 와 glUseProgram()  (0) 2022.11.17
glMatrixMode()  (0) 2020.04.14
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
opengl super bible 3rd - 4,5 chapter  (0) 2020.04.06
Posted by 구차니
Programming/openGL2020. 4. 14. 21:49

GL_MODELVIEW와 GL_PROJECTION만 예제로 많이 보았는데

GL_COLOR와 GL_TEXTURE도 가능한 옵션(?)이다.

 

void glMatrixMode(GLenum mode);

GL_MODELVIEW
Applies subsequent matrix operations to the modelview matrix stack.

GL_PROJECTION
Applies subsequent matrix operations to the projection matrix stack.

GL_TEXTURE
Applies subsequent matrix operations to the texture matrix stack.

GL_COLOR
Applies subsequent matrix operations to the color matrix stack.

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

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

glReadPixels() 와 glUseProgram()  (0) 2022.11.17
openCV + openGL  (0) 2022.02.08
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
opengl super bible 3rd - 4,5 chapter  (0) 2020.04.06
openGL 책 보면서 정리중 - 챕터3  (0) 2020.04.05
Posted by 구차니
Programming/openGL2020. 4. 8. 21:05

2004년 책이라 안될줄 알았는데 다행이 몇개 패키지 설치하니 정상적으로 빌드되도 잘 작동된다.

 

$ sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev
[링크 : http://www.codebind.com/linux-tutorials/install-opengl-ubuntu-linux/]

 

$ sudo apt-get install libxmu-dev libxi-dev
[링크 : https://ubuntuforums.org/showthread.php?t=1703770]



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

openCV + openGL  (0) 2022.02.08
glMatrixMode()  (0) 2020.04.14
opengl super bible 3rd - 4,5 chapter  (0) 2020.04.06
openGL 책 보면서 정리중 - 챕터3  (0) 2020.04.05
glEnable(), glPushAttrib()  (0) 2020.04.04
Posted by 구차니
Programming/openGL2020. 4. 6. 21:51

아 정리하기 귀찮다 -ㅁ-

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

glMatrixMode()  (0) 2020.04.14
opengl superbible 3rd 리눅스 빌드 패키지  (0) 2020.04.08
openGL 책 보면서 정리중 - 챕터3  (0) 2020.04.05
glEnable(), glPushAttrib()  (0) 2020.04.04
openGL superbible 3rd ed. 읽기 시작  (0) 2020.04.03
Posted by 구차니
Programming/openGL2020. 4. 5. 22:11

이건 블로그 보다 위키에 정리 하는게 나으려나?

 

glBegin(GL_POINTS)

    glPointSize()

    glGetFloatv(GL_POINT_SIZE_RANGE,..)

    glGetFloatv(GL_POINT_SIZE_GRANULARITY,..) // 낱알 모양, 입자의 형상

glEnd()

 

 

glBegin(GL_LINES)

    glLineWidth(GLFloat value)

    glGetFloatv(GL_LINE_WIDTH_RANGE,..)

    glGetFloatv(GL_LINE_WIDTH_GRANULARITY,..) // 낱알 모양, 입자의 형상

glEnd()

 

glBegin(GL_LINE_STRIP)

 

glBegin(GL_LINE_STIPPLE)

    glLineStipple(GLint factor, GLushort pattern) // factor : 픽셀 단위 길이, pattern : 선의 형상

glEnd()

 

glBegin(GL_LINE_LOOP)

 

 

삼각형

glEnable(GL_CULL_FACE)

glDisable(GL_CULL_FACE)

glShadeModel(GL_FLAT) // GL_SMOOTH

glBegin(GL_TRIANGLES)

glBegin(GL_TRIANGLE_STRIP)

glBegin(GL_TRIANGLE_FAN)

    glFrontFace(GL_CW)

    glFrontFace(GL_CCW)

glEnd()

 

glEnable(GL_DEPTH_TEST)

    glDepthMask(GL_FALSE) // GL_TRUE

    glClearDepth(GLclampd value)

 

stipple (점묘법)

1bit color bitmap으로 선에 패턴을 그리거나 폴리곤에 32x32 사이즈의 패턴을 입힐 수 있으나

텍스쳐와는 다르게 rotate 되지 않는 특성을 지님(반대로 생각하면 선에 패턴을 그어 두면 줌 배율 상관없이 선 크기가 고정된다?)

 

scissor

win32api에서 갱신영역 지정해서 cpu 조금 먹게 하는 것과 비슷한 기법

직사각형 식으로 x,y,w,h 로만 지정이 가능

 

stencil

스텐실 마스크를 통해서 원하는 위치만을 렌더링 할 수 있다고 하는데 좀 많이 복잡함

glutInitDisplayMode(GLUT_STENCIL)

glEnable(GL_STENCIL_TEST)

glStencilFunc()

glClear(GL_STENCIL_BUFFER_BIT)

glClearStencil(GLint s)

glStencilOp(fail, z-fail, z-succes)

/*

GL_KEEP - 보존

GL_ZERO - 0으로

GL_REPLACE - glStencilFunc() 지정값으로 대체

GL_INCR - 증가

GL_DECR - 감소

GL_INVERT - 반전

GL_INCR_WRAP - 조건에 의해 증가

GL_DECR_WRAP - 조건에 의해 감소

*/

Posted by 구차니
Programming/openGL2020. 4. 4. 10:15

두 함수가 다루는 내용이 비슷한 느낌이라 일단 스크랩

 

glEnable()은 GL_FOG 이런걸 쓰다면

glPushAttrib()는 GL_FOG_BIT 이런걸 쓴다. 접미가 다른게 붙는걸 보니

다른 enum을 쓰는 함수이긴 한데 내부 구조가 어떻게 짜여있는지가 궁금해지는 함수

 

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

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

Posted by 구차니
Programming/openGL2020. 4. 3. 23:21

예전에 줄을 그어가면서 열심히 읽었구나...

그런데 놓친게 왜이리 많았지? 그래서 이해를 못했던 건가? 이런 생각이 많이 드네

 

아무튼 다시 공부 시작해보자.. 틈틈히

Posted by 구차니