23.06.2011, 22:41 | #1 (permalink) |
Новичок
Регистрация: 23.06.2011
Сообщений: 1
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 10
|
Open GL, пожалуйста, помогите исправить ошибки в программе
CLr1View::CLr1View() { wAngle = 60.0f; //задаем начальные значения констант pox=0.0f; poy=0.0f; poz=-2.5f; } CLr1View::~CLr1View() { } BOOL CLr1View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.style|=(WS_CLIPCHILDREN| WS_CLIPSIBLINGS); return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CLr1View drawing void CLr1View::OnDraw(CDC* pDC) { CLr1Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); usr_RenderScene(); } ///////////////////////////////////////////////////////////////////////////// // CLr1View printing BOOL CLr1View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CLr1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CLr1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CLr1View diagnostics #ifdef _DEBUG void CLr1View::AssertValid() const { CView::AssertValid(); } void CLr1View:: Dump(CDumpContext& dc) const { CView:: Dump(dc); } CLr1Doc* CLr1View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLr1Doc))); return (CLr1Doc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CLr1View message handlers BOOL CLr1View::usr_bSetupPixelFormat() { int iPixelType = PFD_TYPE_RGBA; DWORD dwFlags = PFD_DOUBLEBUFFER| PFD_SUPPORT_OPENGL| PFD_DRAW_TO_WINDOW; PIXELFORMATDESCRIPTOR pfd = {0}; pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = dwFlags; pfd.iPixelType = iPixelType; pfd.cColorBits = 64; pfd.cAlphaBits = 64; pfd.cAccumBits = 64; pfd.cDepthBits = 64; pfd.cStencilBits = 64; pfd.cAuxBuffers = 64; pfd.iLayerType = PFD_MAIN_PLANE; CClientDC * lDC = new CClientDC(this); int pixelformat; if ( (pixelformat = ChoosePixelFormat(lDC->GetSafeHdc(), &pfd)) == 0 ) { MessageBox("usr_bSetupPixelFormat:SetPixelFormat failed"); lDC->DeleteDC(); return FALSE; } if (SetPixelFormat(lDC->GetSafeHdc(), pixelformat, &pfd) ==FALSE) { MessageBox("usr_bSetupPixelFormat: SetPixelFormat failed"); lDC->DeleteDC(); return FALSE; } lDC->DeleteDC(); return TRUE; } BOOL CLr1View::usr_bInitOpenGL() { HGLRC hrc; tmpDC = new CClientDC(this); if (!usr_bSetupPixelFormat()) return FALSE; hrc = wglCreateContext(tmpDC->GetSafeHdc()); if(!wglMakeCurrent(tmpDC->GetSafeHdc(), hrc)) return FALSE; return TRUE; } void CLr1View::usr_DestroyOpenGL() { HGLRC hrc; hrc = ::wglGetCurrentContext(); ::wglMakeCurrent(NULL, NULL); if (hrc) ::wglDeleteContext(hrc); if (tmpDC) tmpDC->DeleteDC(); } int CLr1View::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; if (!this->usr_bInitOpenGL()) { AfxMessageBox("Error !!!"); return -1; } return 0; } void CLr1View::OnDestroy() { CView::OnDestroy(); this->usr_DestroyOpenGL(); } void CLr1View::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); usr_ReSize(0, 0, cx, cy); } void CLr1View::usr_ReSize(int x, int y, int width, int height) { glViewport((GLint)((GLint)width-(GLint)height)/2, 0, (GLint)height, (GLint)height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -1, 1); glMatrixMode(GL_MODELVIEW); } void CLr1View::usr_RenderScene() { usr_PreInit(); float mat_dif[]={0.8,0.8,0.8}; float mat_amb[] = {0.2, 0.2, 0.2}; float mat_spec[] = {0.6, 0.6, 0.6}; float shininess = 0.7*128; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, mat_amb); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, mat_dif); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_spec); glMaterialf (GL_FRONT, GL_SHININESS, shininess); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glPushMatrix(); glTranslatef(pox, poy, poz); glRotatef(wAngle,0.0, 1, 0); //звезда glPushMatrix(); glTranslatef(0.0f, 0.0f, 0.0f); glColor3f(2.25f, 2.25f, 1.06f); auxSolidSphere( 0.19f); //оси glPushMatrix(); auxSolidTorus(0.005, 0.8); glPopMatrix(); glPushMatrix(); auxSolidTorus(0.005, 0.3); glPopMatrix(); glPushMatrix(); auxSolidTorus(0.005, 0.5); glPopMatrix(); glPushMatrix(); auxSolidTorus(0.005, 1.0); glPopMatrix(); //планета 1 красная glPushMatrix(); glTranslatef(0.3f, 0.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f); auxSolidSphere( 0.05f); glPopMatrix(); //планета 2 зеленая glPushMatrix(); glTranslatef(0.5f, 0.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f); auxSolidSphere( 0.05f); glPopMatrix(); //планета 3 желтая glPushMatrix(); glTranslatef(0.8f, 0.0f, 0.0f); glColor3f(1.0f, 1.0f, 0.0f); auxSolidSphere( 0.05f); glPopMatrix(); //планета 4 синяя glPushMatrix(); glTranslatef(1.0f, 0.0f, 0.0f); glColor3f(0.0f, 0.0f, 1.0f); auxSolidSphere( 0.1f); //планета 8 glPushMatrix(); glTranslatef(0.5f, -0.7f, -0.8f); glScalef(0.1,0.2, 5.2); glColor3f(2.43f, 1.23f, 0.71f); auxSolidSphere( 0.05f); glPopMatrix(); glPopMatrix(); glPopMatrix(); glFinish(); SwapBuffers(::wglGetCurrentDC()); void CLr1View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { CView::OnActivateView(bActivate, pActivateView, pDeactiveView); } void CLr1View::usr_PreInit() { glEnable (GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable (GL_COLOR_MATERIAL); } void CLr1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CString str; str.Format("nChar %d, nFlags %d",nChar,nFlags); //MessageBox(str);//сообщение о номере нажимаемой кнопки switch (nChar) { case 97: // A { wAngle += 0.35f; break; } case 65: // Shift+A { wAngle -= 0.5f; break; } case 115: // S { pox += 0.1f; break; } case 83: // Shift+S { pox-= 0.1f; break; } case 100: // D { poy += 0.1f; break; } case 68: // Shift+D { poy-= 0.1f; break; } case 102: // F { poz += 0.1f; break; } case 70: // Shift+F { poz-= 0.1f; break; } } Invalidate(); CView::OnChar(nChar, nRepCnt, nFlags); } void CLr1View::Onvkl() { glEnable (GL_FOG);// включает туман float tmp_fog_color[4]={0.94f, 0.94, 0.98f, 1.0f}; glFogfv (GL_FOG_COLOR, tmp_fog_color);//цвет тумана glFogi (GL_FOG_MODE, GL_LINEAR);//выбирает тип тумана glFogf (GL_FOG_DENSITY, 1);//насколько густым будет туман glHint (GL_FOG_HINT, GL_NICEST);//создает туман по пикселям glFogf (GL_FOG_START, 0.0f);//глубина с которого начинается туман glFogf (GL_FOG_END, 10.0f);//глубина где заканчивается туман // TODO: Add your command handler code here } |
23.06.2011, 22:41 | |
Helpmaster
Member
Регистрация: 08.03.2016
Сообщений: 0
|
Вам скорее всего будет интересно прочитать похожие темы Помогите исправить ошибку в программе Ошибки в программе Помогите, пожалуйста, исправить программку на Паскале Помогите исправить косяки Найти ошибки в программе |
25.06.2011, 07:14 | #2 (permalink) |
support
Регистрация: 19.08.2007
Адрес: Зея
Сообщений: 15,797
Записей в дневнике: 71
Сказал(а) спасибо: 166
Поблагодарили 203 раз(а) в 86 сообщениях
Репутация: 75760
|
Вы хоть опишите, что программа делать должна, а что - нет. Иначе любой анализ листинга сравним с попаданием пальцем в небо.
__________________
Убить всех человеков! |
Ads | |
Member
Регистрация: 31.10.2006
Сообщений: 40200
Записей в дневнике: 0
Сказал(а) спасибо: 0
Поблагодарили 0 раз(а) в 0 сообщениях
Репутация: 55070
|
|
|