OpenGL 學習筆記(1)初始化窗體

? 前言

????? 學習OpenGL只是興趣愛好,因為對圖形比較感興趣.將以OpenGl的紅寶書(7)和藍寶石書(4)為基礎,雖然手頭有紅寶書書,但感覺沒藍寶石書寫的好

準備工作

首先要下載一個工具庫(GLUT)

http://www.opengl.org/resources/libraries/glut/

只要把相應文件放在system32和lib目錄下就可以了

第一個OpenGL程序

#include <GL/glut.h>
#include <stdlib.h>void display(void)
{/* clear all pixels  */glClear (GL_COLOR_BUFFER_BIT);glFlush ();
}int main(int argc, char** argv)
{glutInit(&argc, argv);glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100);glutCreateWindow ("hello");glClearColor (0.0, 0.0, 1.0, 0.0);glutDisplayFunc(display); glutMainLoop();return 0;
}


顯示效果是顯示一個藍色背景的一個窗體

image

以下對上述代碼進行介紹

窗體管理(Window Management)


Several routines perform tasks necessary for initializing a window:
? glutInit(int *argc, char **argv) initializes GLUT and processes any command
line arguments (for X, this would be options such as -display and
-geometry). glutInit() should be called before any other GLUT routine.
? glutInitDisplayMode(unsigned int mode) specifies whether to use an
RGBA or color-index color model. You can also specify whether you
want a single- or double-buffered window. (If you’re working in colorindex
mode, you’ll want to load certain colors into the color map; use
glutSetColor() to do this.) Finally, you can use this routine to indicate
that you want the window to have an associated depth, stencil,
multisampling, and/or accumulation buffer. For example, if you want
a window with double buffering, the RGBA color model, and a depth
buffer, you might call glutInitDisplayMode(GLUT_DOUBLE |
GLUT_RGBA | GLUT_DEPTH).
? glutInitWindowPosition(int x, int y) specifies the screen location for
the upper-left corner of your window.
? glutInitWindowSize(int width, int height) specifies the size, in pixels,
of your window.
? glutInitContextVersion(int majorVersion, int minorVersion) specifies
which version of OpenGL you want to use. (This is a new addition
available only when using Freeglut, and was introduced with OpenGL

Version 3.0. See “OpenGL Contexts” on page 27 for more details on
OpenGL contexts and versions.)
? glutInitContextFlags(int flags) specifes the type of OpenGL context
you want to use. For normal OpenGL operation, you can omit this call
from your program. However, if you want to use a forward-compatible
OpenGL context, you will need to call this routine. (This is also a new
addition available only in Freeglut, and was introduced with OpenGL
Version 3.0. See “OpenGL Contexts” on page 27 for more details on
the types of OpenGL contexts.)
? int glutCreateWindow(char *string) creates a window with an OpenGL
context. It returns a unique identifier for the new window. Be warned:
until glutMainLoop() is called, the window is not yet displayed.

我們知道低級win32 api初始化一個窗體是比較復雜的,glut庫簡化了這個過程

回調函數

即win32的消息循環系統,

glutDisplayFunc調用一個函數,該函數會不斷的被調用

glutMainLoop用于啟動程序,并使程序不斷在運行不退出,即進入消息循環

glClearColor 用于清除緩沖區顏色,并重新設置新的顏色

guFlush 刷新OpenGl命令隊列,如果不調用此方法,那么重新繪制的圖形將無法顯示

?

本節目的在于建立OpenGL環境,并建立一個初始窗體

轉載于:https://www.cnblogs.com/Clingingboy/archive/2010/10/16/1852940.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378945.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378945.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378945.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

基于云平臺的家居綜合監測管理系統的設計與實現

時間過得飛快&#xff0c;轉眼間大四即將畢業&#xff0c;有點留戀和不舍。可能是越是到了離別的時候&#xff0c;越開始珍惜吧。大一開始&#xff0c;通過考核進入了學校院系實驗室開始學習&#xff0c;這期間自學了很多東西&#xff0c;很充實&#xff0c;也參加過很多比賽&a…

小白學數據分析-----留存率分析_I[次日留存率突然下降了50%?]

最近在做留存分析時&#xff0c;遇到了不少的情況&#xff0c;也經常會有人問我&#xff0c;為什么我的游戲突然次日留存率降了一半。如果留存率是單單作為一個簡單的指標的話&#xff0c;那對你價值還是蠻有限的&#xff0c;今天就和大家說說一個case&#xff0c;這是不久前解…

mysql映射mapper_SQL映射器Mapper接口(MyBatis)

SQL映射器Mapper接口MyBatis基于代理機制&#xff0c;可以讓我們無需再寫Dao的實現。直接把以前的dao接口定義成符合規則的Mapper。注意事項&#xff1a;1&#xff0e;接口必須以Mapper結尾,名字是DomainMapper2&#xff0e;mapper.xml文件要和Mapper接口建立關系,通過namespac…

計算機圖形學畫線_在計算機圖形學中直接使用線方程

計算機圖形學畫線計算機圖形學| 直接使用線方程 (Computer Graphics | Direct Use of Line Equation) The standard line equation, as we all know is used for drawing a line. It is given by: y mx c. 眾所周知&#xff0c;標準線方程式用于繪制線。 由下式給出&#xff…

Request.ServerVariables (server environment variable)

參數 服務器環境變量指定要檢索的服務器環境變量名。可以使用下面列出的值。 變量說明ALL_HTTP客戶端發送的所有 HTTP 標題文件。ALL_RAW檢索未處理表格中所有的標題。ALL_RAW 和 ALL_HTTP 不同&#xff0c;ALL_HTTP 在標題文件名前面放置 HTTP_ prefix&#xff0c;并且標題名稱…

c/c++ 編程試題

c/c 編程試題 帶*號為選作題&#xff0c;給出代碼截屏和編譯運算結果截屏 1.編程:選取M個最大的數 編程實現從N個無序數中選取M個最大的數(0 < M < N ) 思路&#xff1a;通過冒泡排序或者選擇排序對N個數進行遞減排序&#xff0c;然后輸入前M個數即可。這里我想到的是通…

Java String startsWith()方法與示例

字符串startsWith()方法 (String startsWith() Method) startsWith() method is a String class method, it is used to check whether a given string starts with specific character sequences or not. startsWith()方法是一個String類方法&#xff0c;用于檢查給定的字符串…

mysql inception web_基于Inception搭建MySQL SQL審核平臺Yearing

Inception1. Inceptionj簡介Inception是一款針對MySQL的SQL語句審核自動化運維工具。使用Inception&#xff0c;將會給DBA帶來更大的便利性&#xff0c;將DBA從繁冗的工作中解放出來&#xff0c;做更多的自動化工作&#xff0c;或者從架構方面研究如何更大程度地保證數據庫的高…

C---日常練習

若有以下定義語句&#xff1a;int a5;printf("%d\n",a);則輸出結果是&#xff08;&#xff09; 解析&#xff1a;a 即先使用再自增&#xff0c;a的初始值即為5&#xff0c;則先使用&#xff0c;輸出結果為5 舉個例子&#xff1a; int a5,b; ba;//等價于 ba;aa1 prin…

VS2010 運行庫設置

如下圖所示&#xff0c;當在一個EXE工程中調用lib或dll時&#xff0c;2個工程的下面選項一定要一致&#xff0c;否則會導致exe工程編譯不過。 原則&#xff1a; Debug下&#xff0c;默認是MTd&#xff1b; Release下&#xff0c;默認是MT。 轉載于:https://www.cnblogs.com/lgh…

算法中的Strassen矩陣乘法

Introduction 介紹 Strassen in 1969 which gives an overview that how we can find the multiplication of two 2*2 dimension matrix by the brute-force algorithm. But by using divide and conquer technique the overall complexity for multiplication two matrices i…

零拷貝、mmap、sendfile

目錄零拷貝mmapsendFile總結零拷貝 要了解零拷貝&#xff0c;首先得先了解一下傳統 IO 的執行流程&#xff0c;這里舉個例子&#xff0c;通過傳統的 IO 進行網絡傳輸來傳輸一個文件。 先上一張圖&#xff0c;這張圖就代表了傳統 IO 傳輸文件的流程。 讀取文件的時候&#xf…

網頁服務器和mysql服務器_實現Web服務器之間使用同一個MYSQL和相同的網頁配置文件的方法...

實現Web服務器之間使用同一個MYSQL和相同的網頁配置文件的方法發布時間&#xff1a;2020-04-15 16:42:41來源&#xff1a;億速云閱讀&#xff1a;133作者&#xff1a;三月欄目&#xff1a;數據庫億速云負載均衡(Cloud Load Balancer)是對多臺云服務器進行流量分發的服務。億速云…

傳128GB版iPad4售價為799/929美元

外媒9to5mac報道&#xff0c;蘋果將推出一款升級版iPad4&#xff0c;外觀和iPad 4相同&#xff0c;還是黑白兩色的&#xff0c;只加入了新的SKU。 據報道&#xff0c;這款升級版iPad4還有128GB版&#xff0c;隨著這條消息傳出&#xff0c;不久關于128GB版iPad4的售價信息也傳出…

(西工程-金花)小米路由器連接哆點設置WiFi保姆式教程

小米路由器連接電源,用根網線一端插入寢室的網口處,另一端插入小米路由器的WAN口手機或者電腦連接WiFi,我這里是通過手機瀏覽器打開192.168.31.1進入無線路由器管理頁面進行配置小米路由器&#xff0c;配置WiFi的一些基本參數,例如:WiFi名稱,密碼之類的信息 進入無線路由器管理…

基于MINA框架快速開發網絡應用程序

1&#xff0e;MINA框架簡介 Netty、Mina、Cindy都是不錯的NIO開源框架&#xff0c;后兩者都是在Netty的基礎上演化出來的。MINA(Multipurpose Infrastructure for Network Applications)是用于開發高性能和高可用性的網絡應用程序的基礎框架。通過使用MINA框架可以可以省下處理…

Python中@staticmethod和@classmethod之間的區別

classmethod裝飾器 (The classmethod Decorator) The classmethod decorator is an inbuilt function decorator that gets evaluated after the function is defined. The result of the evaluation shadows the function definition. The classmethods first argument is alw…

go 聲明二維數組_一篇文章了解Go語言中數組Arrays的使用內幕

概述與其他編程語言類似&#xff0c;Go語言也有數組array。Go語言中&#xff0c;數組的行為和其他語言沒有什么不同.Go語言中還有一個叫做切片slice的東西&#xff0c;它就像是對數組的引用。在本文中&#xff0c;我們將只研究數組。定義數組是同一類型元素的連續集合&#xff…

ffmpeg 使用ffplay 進行 hls 拉流 分析 1

ffmpeg 使用 ffplay 進行 hls 拉流 分析 1 從使用ffplay 調用 http://192.168.1.100:8080/live/livestream.m3u8 開始&#xff0c;進入到ffmpeg 的分析使用的協議選擇相應的解復用器的步驟。 其他協議或者文件方式的使用ffplay也是這個步驟流程的。 目錄&#xff1a;一、流程圖…

搜狗輸入法輸出特殊符號快捷鍵

https://www.petefreitag.com/cheatsheets/ascii-codes/ 參考上個編碼網站大全 詳細步驟為&#xff1a;alt長按 &#xff0b; 編碼數字 例如&#xff1a;平方的編碼為178-----長按alt178 即可&#xff0c;178是數字一個一個挨個按即可 常用的特殊符號如下&#xff1a; 平方&…