3,881
社区成员
发帖
与我相关
我的任务
分享
#include<glut.h>
#include<stdio.h>
#include<stdlib.h>
#include <Windows.h>
#include<time.h>
#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace std;
#define FileName "lena.bmp"
static GLint imagewidth=512;
static GLint imageheight=512;
static GLint pixellength;
static GLubyte* pixeldata;
static GLubyte* pixeldata1;
int cnt=0;
void idleCB()
{
glutPostRedisplay();
}
void timerCB(int millisec)
{
glutPostRedisplay();
glutTimerFunc(10, timerCB, 1);
}
void display(void)
{
double runtime = (double)clock();
if(cnt%2==0)
glDrawPixels(imagewidth,imageheight,GL_BGR_EXT,GL_UNSIGNED_BYTE,pixeldata);
else
glDrawPixels(imagewidth,imageheight,GL_BGR_EXT,GL_UNSIGNED_BYTE,pixeldata1);
//---------------------------------
cnt++;
runtime=(double)clock()-runtime;
cout<< runtime << " ms"<<endl;
//cout<<cnt<<endl;
glFlush();
glutSwapBuffers();
}
int main(int argc,char* argv[])
{
//打开文件
FILE* pfile=fopen("D:\\lena.bmp","rb");
if(pfile == 0) exit(0);
//计算像素数据长度
pixellength=imagewidth*3;
while(pixellength%4 != 0)pixellength++;
pixellength *= imageheight;
//读取像素数据
pixeldata = (GLubyte*)malloc(pixellength);
if(pixeldata == 0) exit(0);
fseek(pfile,54,SEEK_SET);
fread(pixeldata,pixellength,1,pfile);
FILE* pfile1=fopen("D:\\pug.bmp","rb");
pixeldata1 = (GLubyte*)malloc(pixellength);
if(pixeldata1 == 0) exit(0);
fseek(pfile1,54,SEEK_SET);
fread(pixeldata1,pixellength,1,pfile1);
//关闭文件
fclose(pfile);
//初始化glut运行
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); //双缓存
glutInitWindowPosition(0,0);
glutInitWindowSize(imagewidth,imageheight);
glutCreateWindow(FileName);
glutDisplayFunc(&display);
LONG style;HWND hWnd;
//////////////////////////////////////
hWnd = FindWindow(NULL,FileName);
if(!hWnd)
cout<<"NO!"<<endl;
style = GetWindowLong(hWnd, GWL_STYLE);
style = style & (~WS_CAPTION) & ~(WS_BORDER) & ~WS_THICKFRAME ;
SetWindowLong( hWnd, GWL_STYLE, style); //无边框无标题
//////////////////////////////////////////////////////////////////////
//glutTimerFunc(10, timerCB, 1);
glutIdleFunc(idleCB);
glutMainLoop();
//-------------------------------------
// free(pixeldata);
return 0;
}
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
HFONT hfont,ohfont;
RECT r;
COLORREF oc;
switch(message) {
case WM_CLOSE://按Alt+F4退出
PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
hdc = ps.hdc; // the device context to draw in
GetClientRect(hWnd, &r); // Obtain the window's client rectangle
hfont = CreateFont(240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");
ohfont=SelectObject(hdc,hfont);
oc=SetTextColor(hdc,0x00C080FF);
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc,r.left+r.right/2-720, r.top+r.bottom/2-120,"最短画图程序",12);
SelectObject(hdc,ohfont);
SetTextColor(hdc,oc);
DeleteObject(hfont);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
WNDCLASS wc = {0};
HBRUSH hbrh;
hbrh=CreateSolidBrush(0x00000000);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = hbrh;
wc.lpszClassName = "minwindowsapp";
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
if( FAILED(RegisterClass(&wc)) ) return 1;
if(FAILED(CreateWindow(wc.lpszClassName,
"Minimal Windows Application",
WS_POPUP|WS_VISIBLE,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
0,
0,
hInstance,
NULL)))
return 2;
while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
DispatchMessage( &msg );
}
DeleteObject(hbrh);
return 0;
}