PIXNET Logo登入

阿勇的blog

跳到主文

歡迎光臨阿勇在痞客邦的小天地

部落格全站分類:不設分類

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 3月 11 週一 201323:07
  • immediate mode? display list? vertex array?

immediate mode
  • The easiest way to do drawing in OpenGL is using the Immediate Mode. For this, you use the glBegin() function which takes as one parameter the “mode” or type of object you want to draw.
  • glBegin(GL_LINE_LOOP);//start drawing a line loop
        glVertex3f(-1.0f,0.0f,0.0f);//left of window
        glVertex3f(0.0f,-1.0f,0.0f);//bottom of window
        glVertex3f(1.0f,0.0f,0.0f);//right of window
        glVertex3f(0.0f,1.0f,0.0f);//top of window
    glEnd();//end drawing of line loop
  • display list
  • Display list is a group of OpenGL commands that have been stored (compiled) for later execution. Once a display list is created, all vertex and pixel data are evaluated and copied into the display list memory on the server machine. It is only one time process. After the display list has been prepared (compiled), you can reuse it repeatedly without re-evaluating and re-transmitting data over and over again to draw each frame.
  • // create one display list
    GLuint index = glGenLists(1);
    // compile the display list, store a triangle in it
    glNewList(index, GL_COMPILE);
        glBegin(GL_TRIANGLES);
            glVertex3fv(v0);
            glVertex3fv(v1);
            glVertex3fv(v2);
        glEnd();
    glEndList();
    ...
    // draw the display list
    glCallList(index);
  • vertex array
  • This means that your vertices and vertex attributes and indices are in RAM.
  • glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(3, GL_FLOAT, 0, Colors);
    glVertexPointer(3, GL_FLOAT, 0, Vertices);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
  • (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(13)

    • 個人分類:opengl
    ▲top
    • 3月 10 週日 201320:55
    • OpenGL Blend



    glBlendFunc — specify pixel arithmetic
    void glBlendFunc(GLenum sfactor, GLenum dfactor);void glBlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor);Parameters
    bufFor glBlendFunci, specifies the index of the draw buffer for which to set the blend function.sfactor
    (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(37)

    • 個人分類:opengl
    ▲top
    • 11月 07 週日 201016:53
    • opengl 視窗置中

    其實視窗置中和openGL一點關係都沒有
    問題在你的視窗是誰建立的
    是用glfw? glut? or ??
    至於置中,就還簡單了
    視窗的左上角位置 = 0.5 X( 桌面大小 - 視窗大小 )
    (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(113)

    • 個人分類:opengl
    ▲top
    • 8月 11 週三 201011:46
    • 使用glut時,不顯示控制台視窗

    prevent opening a console window in addition to your GLUT window when it is run
    in vc
    menu option ( Project → Properties )
    From the Configuration: list box, select All Configurations.
    select the Linker subtree and then Command Line option in the left pane. Then add the following code to the Additional Options: text box
    (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(6)

    • 個人分類:opengl
    ▲top
    • 2月 13 週五 200911:48
    • Embedded Python + wxPython + OpenGL

    先看一下wxPython官網關於opengl的教學try:
    import wx
    from wx import glcanvas
    except ImportError:
    raise ImportError, "Required dependency wx.glcanvas not present"
    try:
    from OpenGL.GL import *
    except ImportError:
    raise ImportError, "Required dependency OpenGL not present"
    class GLFrame(wx.Frame):
    """A simple class for using OpenGL with wxPython."""
    def __init__(self, parent, id, title, pos=wx.DefaultPosition,
    size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
    name='frame'):
    #
    # Forcing a specific style on the window.
    # Should this include styles passed?
    style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
    super(GLFrame, self).__init__(parent, id, title, pos, size, style, name)
    self.GLinitialized = False
    attribList = (glcanvas.WX_GL_RGBA, # RGBA
    glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
    glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
    #
    # Create the canvas
    self.canvas = glcanvas.GLCanvas(self, attribList=attribList)
    #
    # Set the event handlers.
    self.canvas.Bind(wx.EVT_ERASE_BACKGROUND, self.processEraseBackgroundEvent)
    self.canvas.Bind(wx.EVT_SIZE, self.processSizeEvent)
    self.canvas.Bind(wx.EVT_PAINT, self.processPaintEvent)
    #
    # Canvas Proxy Methods
    def GetGLExtents(self):
    """Get the extents of the OpenGL canvas."""
    return self.canvas.GetClientSize()
    def SwapBuffers(self):
    """Swap the OpenGL buffers."""
    self.canvas.SwapBuffers()
    #
    # wxPython Window Handlers
    def processEraseBackgroundEvent(self, event):
    """Process the erase background event."""
    pass # Do nothing, to avoid flashing on MSWin
    def processSizeEvent(self, event):
    """Process the resize event."""
    if self.canvas.GetContext():
    # Make sure the frame is shown before calling SetCurrent.
    self.Show()
    self.canvas.SetCurrent()
    size = self.GetGLExtents()
    self.OnReshape(size.width, size.height)
    self.canvas.Refresh(False)
    event.Skip()
    def processPaintEvent(self, event):
    """Process the drawing event."""
    self.canvas.SetCurrent()
    # This is a 'perfect' time to initialize OpenGL ... only if we need to
    if not self.GLinitialized:
    self.OnInitGL()
    self.GLinitialized = True
    self.OnDraw()
    event.Skip()
    #
    # GLFrame OpenGL Event Handlers
    def OnInitGL(self):
    """Initialize OpenGL for use in the window."""
    glClearColor(1, 1, 1, 1)
    def OnReshape(self, width, height):
    """Reshape the OpenGL viewport based on the dimensions of the window."""
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(-0.5, 0.5, -0.5, 0.5, -1, 1)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    def OnDraw(self, *args, **kwargs):
    "Draw the window."
    glClear(GL_COLOR_BUFFER_BIT)
    # Drawing an example triangle in the middle of the screen
    glBegin(GL_TRIANGLES)
    glColor(0, 0, 0)
    glVertex(-.25, -.25)
    glVertex(.25, -.25)
    glVertex(0, .25)
    glEnd()
    self.SwapBuffers()
    app = wx.PySimpleApp()
    frame = GLFrame(None, -1, 'GL Window')
    frame.Show()
    app.MainLoop()
    app.Destroy()
    (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(112)

    • 個人分類:opengl
    ▲top
    • 2月 13 週五 200909:54
    • 在mac中,編譯opengl注意事項

    發生問題
    error: GL/gl.h: No such file or directory
    error: GL/glu.h: No such file or directory
    解決辦法
    將
    #include <GL/gl.h>
    #include <GL/glu.h>
    改成
    #include <OpenGL/gl.h>
    #include <OpenGL/glu.h>
    編譯時注意-lGLU -lGL -framework OpenGL
    (繼續閱讀...)
    文章標籤

    阿勇 發表在 痞客邦 留言(0) 人氣(5)

    • 個人分類:opengl
    ▲top
    1

    個人資訊

    阿勇
    暱稱:
    阿勇
    分類:
    不設分類
    好友:
    累積中
    地區:

    熱門文章

    • (0)Cordova速記
    • (0)Cordova run simulation
    • (5)swift速記
    • (1)cordova發布到andriod
    • (4)迷香
    • (11)notification results in “unrecognized selector sent to instance…”
    • (0)分開設定xcode的configureration
    • (10)關於doesNotRecognizeSelector引起的exception crash
    • (1)在SQL中,當二個鍵同時相等時,唯一鍵成立。
    • (56)防止繼承的delegate跟原本的衝突(how to extend a protocol for a delegate in objective C)

    文章分類

    • 替代役的日子 (5)
    • 黑色鈣片 (4)
    • java (3)
    • picasa (1)
    • lua (1)
    • mingw (1)
    • nsis (1)
    • squirrel (1)
    • freetype (1)
    • bitmap font (7)
    • windows (5)
    • c (1)
    • NetBeans (2)
    • uml (1)
    • html5 (1)
    • Wheel Light (4)
    • Qt (26)
    • opengl (6)
    • chrome (2)
    • hg (2)
    • mac (4)
    • apns (1)
    • python (4)
    • php (2)
    • SQL (4)
    • iOS (3)
    • xcode (4)
    • Objective-C (8)
    • phonegap (1)
    • swift (1)
    • cordova (2)
    • 未分類文章 (1)

    最新文章

    • Cordova速記
    • Cordova run simulation
    • swift速記
    • cordova發布到andriod
    • 迷香
    • notification results in “unrecognized selector sent to instance…”
    • 分開設定xcode的configureration
    • 關於doesNotRecognizeSelector引起的exception crash
    • 在SQL中,當二個鍵同時相等時,唯一鍵成立。
    • 防止繼承的delegate跟原本的衝突(how to extend a protocol for a delegate in objective C)

    動態訂閱

    文章精選

    文章搜尋

    誰來我家

    參觀人氣

    • 本日人氣:
    • 累積人氣: