标题:大家新年好!
取消只看楼主
pycansi
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:418
专家分:1060
注 册:2012-7-26
结帖率:100%
已结贴  问题点数:100 回复次数:2 
大家新年好!
刚学OpenGL,过年了,拼凑个小玩意向大家拜年!祝大家新春快乐,吉祥如意!
程序代码:
#include "windows.h"
#include "GL/glut.h"
#include "stdlib.h"
#include "stdio.h"

void myDisplay (void);
void ChangeSize (int w, int h);
void SelectFont (int size, int charset,char* face);
void myString (char* str);
void myPlay (void);

int WINAPI WinMain (HINSTANCE h1, HINSTANCE h2, LPTSTR cmdline, int cmdshow){        /* 用 "main" 用不了 SelectFont ()中的3个函数 */
    int argc = 1;
    char* argv[] = {"OpenGL"};        /* ? char** 报错 */

    glutInit (&argc, argv);                                /* 初始化 */
    glutInitDisplayMode (GLUT_RGB | GLUT_SINGLE);
    
    glutInitWindowPosition (0, 0);
    glutInitWindowSize (800, 600);
    glutCreateWindow ("2013");

    glutDisplayFunc (&myDisplay);
    glutMainLoop ();    }

void myDisplay (void){
    glClearColor (0, 0, 0, 1);
    glClear (GL_COLOR_BUFFER_BIT);
    
    myPlay ();
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (1, 0, 0);
    SelectFont(72, ANSI_CHARSET, "Comic Sans MS");
    glRasterPos2f (-0.3, 0);
    myString ("Happy New Year");
    glFlush ();        }

void ChangeSize (int w, int h){                                                                    
    float aspectRatio = 0;

    if (h == 0){
        h = 1;    }
    glViewport (0, 0, w, h);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();

    aspectRatio = (float)w / (float)h;
    if (w <= h) { 
        glOrtho (-100, 100, -100 / aspectRatio, 100 / aspectRatio, 1, -1);    }
    else 
        glOrtho (-100 * aspectRatio, 100 * aspectRatio, -100, 100, 1, -1);

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();    }

void SelectFont (int size, int charset,char* face){        
    HFONT hFont = CreateFontA (size, 0, 0, 0, FW_MEDIUM, 0, 0, 0, charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, face);
    HFONT hOldFont = (HFONT)SelectObject (wglGetCurrentDC (), hFont);
    DeleteObject (hOldFont);    }

void myString (char* str){    
    static int isFirstCall = 1;
    static GLuint lists = 0;

    if (isFirstCall){              
        isFirstCall = 0;

        lists = glGenLists (128);

        wglUseFontBitmaps (wglGetCurrentDC (), 0, 128, lists);    }

    for (; *str != '\0'; str++){
        glCallList (lists + *str);    }    }

void myPlay (void){
    glColor3f (1, 1, 1);
    glRasterPos2f (-0.3, 0);
    SelectFont(48, ANSI_CHARSET, "Comic Sans MS");
    myString ("Wait");    
    for (int i = 1; i <= 5; i++){
        myString (".");
        glFlush ();
        Sleep (500);        }    }

虽然有些地方还不太明白,不过我相信,
PS:Win API 的函数名真是不漂亮...

参考:http://
      https://bbs.bccn.net/thread-67741-1-1.html
      http://blog.

[ 本帖最后由 pycansi 于 2013-2-10 00:48 编辑 ]
搜索更多相关主题的帖子: 新年 
2013-02-10 00:46
pycansi
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:418
专家分:1060
注 册:2012-7-26
得分:0 
回复 14楼 洫魇
14, 18, 20, 21 楼的童鞋回答得真整齐,赞一个
请看 "参考" 的 第一个网址

[ 本帖最后由 pycansi 于 2013-2-12 21:28 编辑 ]


莫问前尘有愧,但求今生无悔
2013-02-11 21:37
pycansi
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:5
帖 子:418
专家分:1060
注 册:2012-7-26
得分:0 
奇怪...为嘛13楼没分?


莫问前尘有愧,但求今生无悔
2013-02-11 21:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-398491-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069774 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved