OpenGL step1 開個視窗

2021-09-11 21:35:28 字數 2009 閱讀 7651

1:本菜鳥用的ide是visual studio 2019 rc,至於opengl的環境配置我就不多說了,網上有很多教程。

2:配置好opengl環境之後建立乙個c++project,然後貼上檢測**,執行看是否能出現視窗,如果有錯誤注意檢視include directories等是否正確。

3:以上沒有問題就可以考慮構建window類(往後可能還會調整)。

#pragma once

#include

#include

#include

#include

class

window

;

下面是具體實現過程

#include

"window.h"

void

processinput

(glfwwindow* window)

void

framebuffer_size_callback

(glfwwindow* window,

int width,

int height)

window::

window

(const

char

* title,

int width,

int height)

:m_width

(width)

,m_height

(height)

,m_title

(title)

window::

~window()

bool window::

closed()

const

bool window::

init()

glfwwindowhint

(glfw_context_version_major,3)

;glfwwindowhint

(glfw_context_version_minor,3)

;glfwwindowhint

(glfw_opengl_profile, glfw_opengl_core_profile)

;//建立乙個視窗和它opengl上下文

m_window =

glfwcreatewindow

(m_width, m_height, m_title,

nullptr

,nullptr);

if(!m_window)

glfwmakecontextcurrent

(m_window)

;//此函式設定指定視窗的使用者定義指標。保留當前值,直到視窗被銷毀。

glfwsetwindowuserpointer

(m_window,

this);

glfwsetframebuffersizecallback

(m_window, framebuffer_size_callback)

;//初始化gladif(

!gladloadglloader

(gladloadproc

(glfwgetprocaddress)))

return

true;}

void window::

clear()

const

void window::

update()

const

接下來是主函式

#include

"window.h"

intmain()

glfwterminate()

;return0;

}

這樣就可以創造乙個視窗。如果想讓視窗有顏色可以在迴圈前加入glclearcolor()函式,此函式有4個引數,對應rgba(紅,綠,藍,α值),α值指的是透明度。

幸甚至哉,歌以詠志。歡迎來噴。

本菜鳥github:

無視窗外掛程式1

mfc控制項的不建立視窗也允許啟用的選項查探 在atl無視窗activex控制項中響應timer訊息 uiflash.h ioleinplacesitewindowless duilib修復activexui控制項bug,以支援flash透明動態背景 cbitmap和hbitmap的區別及相互轉換方...

1, unicode,視窗,訊息

1,ansi編碼 unicode編碼的區別。要想程式根據是否定義unicode來自動編譯各個版本,則需要注意一下3點。tchar.h 1.1 字串,t ifdef unicode define t x l x else define t x x endif 1.2,字元型資料型別,用tchar if...

python pygame基礎1 定義視窗

import pygame 一 定義乙個視窗 screen pygame.display.set mode 400,300 pygame.display.set caption first create a window 視窗的標題 怎麼退出 running true while running e...