顯示具有 OpenGL 標籤的文章。 顯示所有文章
顯示具有 OpenGL 標籤的文章。 顯示所有文章

03 1月 2011

steps to use "texture3d.c"

Platform I used: VC++ 2010 Express.

In order to use this source example of Programming Guide,
I did a few modifications then I can run the example correctly.

1. Solution of the undefined macro:
#ifdef GL_VERSION_1_2
My computer didn't have this definition, so I need to include OpenGL extension library as below:
#include < GL/glext.h >;
And the same time, download the header files from Official Website.

2. The solution of "glTexImage3D not defined":
a. declare a global function pointer:
PFNGLTEXIMAGE3DPROC glTexImage3D;
b. After correctly initializing OpenGL, execute the codes:
glTexImage3D = reinterpret_cast( ::wglGetProcAddress( "glTexImage3D") );
Original post is from here.

3. If you got a error like: "reinterpret_cast : undeclared identifier",
please rename the source "C" code from texture3d.c to texture3d.cpp.
Because this macro is dedicated to C++ language.
Original post is from here.

Result should be:

Record just avoid forgetting. :D

23 11月 2010

Big Step, the Phong Shading.

事隔多年, 終於完成當初未完的作業 Homework #02.
也太弱, 之前設定的5天一篇的目標, 一下子又到了月底,
日子過很快, 繼續把握時間!


Results: 
Flat Shading

Gouraud Shading

Phong Shading


當初一直看課本的內容, 在想要怎麼implement "自行內插出每個pixel的normal vector", 
然後就一直做不出來...
可能是當時做影像處理的職業病吧, 壓根沒想到原來是在vertex shader按照最一般的example codes即可 = ="
這個作業真的可以學到很多東西 (假設在過程中跟我犯了一樣多的錯 >.< )

1. 第一個, 也是最久的一個問題, 為什麼Shader objects的result通通只有一個顏色?
The answer is the "color tracking" skill ( glEnable(GL_COLOR_MATERIAL), glColorMaterial() ).
因為 Enable Color Tracking, we have to assign new color before each glBegin().
經實驗證明, color tracking在每個glBegin and glEnd中, 不會發生效用. It should be:
for(int i=0;i< int(TRIobj->triangleList.size());i++)
{
  glColor3fv(TRIobj->triangleList[i].color);
  glBegin(GL_TRIANGLES);

  for(int j=0;j<3;j++){    
    glNormal3dv( TRIobj->triangleList[i].normal[j] );
    glVertex3dv( TRIobj->triangleList[i].vertex[j] );  // assign array form 
  }
  glEnd();
}

2. 過程中, 因為想要對shader objects debug, 所以卡在glUniformLocation()一段時間, 最後才發現, 一直get不到location的原因是:The value of input uniform variables can't be changed during the shader objects.

3. 惰性慫恿我不需三個Lights都Implement, 反正搞懂GLSL了阿!...幸好, 在coding 後方的Light時, 光線一直"透到前方平面"來, 讓我這門外漢以為還有Polygon的透明屬性沒有設定好, 又K了一陣子書, 結論是:因為座標轉換的觀念還不夠熟, 所以透光的效果其實是因為在打光前, 座標已經被轉換到前方平面來了.

回頭想想寫這份作業的過程, 以及手邊記錄著思考過程的手稿, 這些那些, 都是永遠的回憶.
不只跨越了當年的失落, 更在過程中, 發現了大量的網路資源, 高手們的Blog...
最後, 更被前輩們的網頁所感動, 既然要留下這些學習過程, 網頁編輯的功夫怎麼能省,
於是, 花了幾天靜下心來, 學習一些基本的HTML and CSS語法, 東湊西湊, 就是你所看的這些 :D

22 10月 2010

Let's get the show on the road.

The course is still there...
The homework is still there... 
Some years went past, and I'm ready to try it again.


When fell over on graduate school, 
I didn't even know what "runtime", "callback function", and "instance" is..
So rookie on programming, that's my second year to the software world.


I believe I CAN.
----------------------------------------------------------------------------------------------------


The homework: You are required to do the following things in homework #1: 



  • Load a 3D model file of TRI format.
    Draw it in wireframe mode and view it in perspective view.
     
  • You should provide object rotation mode and camera rotation mode, and implement basic transformations such as rotation, translation, scaling and shear. 
  • The camera (eye) can be moved around and into the model. 
  • Clipping is required. Try to show the difference between clipping and non-clipping. 
  • ** You can not use functions gluPerspective and glFrustum !!  
And the course website is here, Interactive Computer Graphics in National Taiwan University.   


Final, I complete the homework again. This time I did that after reading some chapters of several books, instead of just copy one example code content of some Chinese book.


------------------------------------------------------------------------------------------------
Post this article after the due date of the homework this year may be more appropriate. 
Hope this helps some people that hesitate to or shy of asking questions to TAs.

05 10月 2010

[Extract] set up environment for OpenGL and GLUT on VC++ 2010 Express

Those steps are extracted from the good blog Here! and Here!, written by Nafee M Sadh's.
Write records here just for fear that if the original blog is removed someday.


Key Steps to create Win32 console application:

  • Select "Empty Project" in the wizard dialog.
  • In the Project Property, Configuration Properties  Linker  Input, Type “opengl32.lib;glu32.lib” in Additional Dependencies.
  • For above step, remember to select the "All configurations" to set the debug and release environment at the same time.

Key Step to set up GLUT environment:


  • Download the original GLUT library from Nate Robins’ site. (for my case, the zip package will generate one .h file, two .lib files, two .dll files after upzipped.) 
  • put the files as below: (VS2010) ( I copy these three lines form the original blog..)
    glut.h to the folder C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl\
    glut32.lib to the folder C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\
    glut32.dll to the folder C:\Windows\System32\
Try it, and don't forget to visit the original blog for more useful information. :P

07 7月 2010

little practice of two viewports

Practice of "Try this" in Red-Book chapter 3.

Target: 
Modify an existing program so that an object is drawn twice, in different Viewports.

Answer:
void reshape (int w, int h)
{
   glClear (GL_COLOR_BUFFER_BIT);
   glColor3f (1.0, 1.0, 1.0);
   
   glViewport (0, 0, (GLsizei) w/2, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity (); 
   gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   glScalef (1.0, 2.0, 1.0);      /* modeling transformation */ 
   glutWireCube (1.0);

   glViewport ((GLsizei) w/2, 0, (GLsizei) w/2, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity (); 
   gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   glScalef (1.0, 2.0, 1.0);      /* modeling transformation */ 
   glutWireCube (1.0);

    glFlush ();
}

Another amazing OpenGL project.

Again, after a hard and tired study, an amazing project will appear on my monitor, let me stick here and can't speak out how shock I felt.


This OpenGL project is made by Nate Robins. I knew this project from the so-called Red-book of OpenGL programming, OpenGL programming guide 7th edition.


How beautiful tool to demo some basic theories of OpenGL APIs, like transformation and lighting.



If you like OpenGL, just go to download and try it.
maybe you'll pronounce a voice of "WoW"..like I did few minutes ago.  :P

25 5月 2010

SOP to Create Sample Programs of ICG

照著自己規劃的進度, 緩慢的進行ICG Study...
一段時間只唸內容文字,剛剛要Create Appendix A的Sample Program to Trace Code,
竟忘了最簡單的SOP, 有點Shock, 果然生疏不得
為避免將時間浪費在重複的錯誤中 寫一篇簡單的SOP給將來的自己

Target: Interactive Computer Graphics, A top-down approach with OpenGL (Forth Edition)
  1. Pre-set VS2005 Environment for GLUT.
  2. Create a Win32 Console App.
  3. In Wizard:
    Application Type-->Console Application
    Additional Options-->"Precompiled Header"
  4. After generating a buildable project, 將project_name.cpp的內容, 除了最上方的
    #include "stdafx.h"外,
    都用
    Angel's source codes to override.
  5. 最後視情況加上一些function需要include的library,
    例如:rand()需要額外增加 "#include <>stdlib.h
    "在#include "stdafx.h"下方
  6. If no error when you build the solution, the sample program is Ready.
Let's trace codes.

[補充] : 要use Angel's c file直接取代default的"int _tmain(int argc, _TCHAR* argv[])", 要記得在Project Setting裡面, 指定Unicode Character Set.