當前位置:首頁 » 編程語言 » c語言opengl代碼

c語言opengl代碼

發布時間: 2023-08-05 15:57:12

⑴ C語言如何用OpenGL

OpenGL就是基於C語言的,只需要下載OpenGL的SDK庫安裝即可,在編寫源碼時:
1、添加頭文件glut.h。
注意glut.h文件中已經包含gl.h,glu.h在實際編譯中可以只加入頭文件glut.h,很多相關的例子都是這樣的,但是在mingwstudio上編譯發現,在glut.h前還是需要加入glu.h, gl.h.如:
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
2、在工程中添加OpenGL的庫,有關命令行加入,glu32 opengl32 glut32庫就可以編譯了。

⑵ 利用C語言實現二維圖形的變換

你先看看吧,思路大概就是這樣,不懂的問我。
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
struct point
{
float x;
float y;
};
void translation(point*pt, float xp,float yp,int num)//num代表點的個數
{
for(int i=0;i<num;i++)
{
(pt+i)->x+=xp;
(pt+i)->y+=yp;
}
}
void scale(point *pt,float xs,float ys,int num)
{
for(int i=0;i<num;i++)
{
(pt+i)->x*=xs;
(pt+i)->y*=ys;
}
}
void rotation(point *pt,float angle,int num)
{
int a[2][2];
angle=angle/180*3.141592657;
a[0][0]=cos(angle);
a[0][1]=-sin(angle);
a[1][0]=sin(angle);
a[1][1]=cos(angle);
point* temp;
for(int i=0;i<num;i++)
{
temp->x=(pt+i)->x;
temp->y=(pt+i)->y;
(pt+i)->x=temp->x*a[0][0]+a[0][1]*temp->y;
(pt+i)->y*=temp->x*a[1][0]+a[1][1]*temp->y;
}
}
int main()
{
int i=0,N,mode,angle,xp,yp,xk,yk,num;
cout<<"please input the number of point "<<endl;
scanf("%d",&N);
num=N;
point pt[10];
while(N--)
{
printf("please input points(x,y):\n");
scanf("%f%f",&pt[i].x,&pt[i].y);
i++;
}
printf("please input motions\n");
printf("0 stand for translation:\n");
printf("1 stand for scale:\n");
printf("2 stand for rotation:\n");
scanf("%d",&mode);
switch(mode)
{
case 0:
printf("please input the translation in x and y direction respectivly:\n");
cin>>xp>>yp;
translation(pt, xp,yp,num);
break;
case 1:
printf("please input the scale in x and y direction respectivly:\n");
scanf("%f%f",&xk,&yk);
scale(pt, xk,yk,num);
break;
case 2:
printf("please input the angle:\n");
scanf("%f",&angle);
rotation(pt, angle,num);
break;
}
printf("after translatiton or scale or rotation:\n");
for(int i=0;i<num;i++)
printf("%f %f\n",pt[i].x,pt[i].y);
}

⑶ C語言windows,OpenGL編程

  1. 查找 MSDN 可以得知,MSG 裡面的 pt 坐標是相對於窗口的左上角的;

2. 至於聲音控制和播放,可以使用 Windows 自帶的 MCI API,或者使用 DirectSound 來播放,我推薦你使用 un4seen 的 BASS,簡單實用強大,一兩個函數就可以播放音效了;

3. 你要使用 alpha blend 與桌面進行鏤空運算,就必須首先獲得桌面的窗體句柄,OpenGL 的 alppha 運算我不是很懂,不過 Direct3D 的話就簡單多了;

4. 屏幕常亮,其實就是阻止系統進入休眠狀態,每當系統要進入休眠狀態之前,都會向系統的所有窗口發送一條消息,你攔截這條消息,進行特別的處理就可以防止系統進入休眠了,至於是什麼消息,請查看 MSDN,我也好久沒用過這條消息了;

5.bmp 文件可以保存 alpha 通道,使用 32bit 色深的 bmp 文件就可以了,RGB 分別 8bit,alpha 通道 8bit,不過說到 alpha 通道,tga 或者 png 圖片更加合適,因為他們可以進行無損壓縮

6.用GetPocAddress導出函數,只能用類型強制轉換,這個是 windows 的原則,我們只能去迎合它了 ...

7. 執行 NULL 指針的話,不同的系統會有不同的反應,XP 是直接程序崩潰,Vista 或者以上的系統,就會提示無響應

8. 如果你建立的工程是 Win32 窗口程序,那麼就不會有 DOS 窗口,如果你建立的是 Win32 控制台程序,那麼就會有 DOS 窗口;如果你使用 OpenGL 實用庫來創建 OpenGL 程序,那個 DOS 窗口是無法消除的,它可以幫助你進行錯誤排查

9. 不要用 Dev C++ 了,用 VS2010 吧,這是行業規范


最後,祝樓主學習愉快

熱點內容
python多線程map 發布:2025-02-07 01:04:37 瀏覽:461
python線程時間 發布:2025-02-07 01:04:26 瀏覽:793
精易編程 發布:2025-02-07 00:49:10 瀏覽:464
訪問桂綸鎂 發布:2025-02-07 00:49:00 瀏覽:938
安卓免費掃描哪個好 發布:2025-02-07 00:47:40 瀏覽:90
金蝶修改伺服器地址 發布:2025-02-07 00:41:08 瀏覽:867
安卓手機版的蒸汽平台在哪裡下載 發布:2025-02-07 00:29:04 瀏覽:454
php自學中心 發布:2025-02-07 00:28:50 瀏覽:270
手機卡在哪裡設置密碼 發布:2025-02-07 00:21:25 瀏覽:707
解壓哄睡音頻 發布:2025-02-07 00:19:56 瀏覽:159