offline
- umpirsky
- Počasni građanin
- Pridružio: 01 Apr 2005
- Poruke: 797
- Gde živiš: Niš
|
Zaboravio sam kako se izdvaja kod od ostatka teksta!
Ali evo koda:
// GrafikaLab4View.cpp : implementation of the CGrafikaLab4View class
//
#include "stdafx.h"
#include "GrafikaLab4.h"
#include "GrafikaLab4Doc.h"
#include "GrafikaLab4View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glaux.h>
#include <math.h>
/////////////////////////////////////////////////////////////////////////////
// CGrafikaLab4View
IMPLEMENT_DYNCREATE(CGrafikaLab4View, CView)
BEGIN_MESSAGE_MAP(CGrafikaLab4View, CView)
//{{AFX_MSG_MAP(CGrafikaLab4View)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGrafikaLab4View construction/destruction
CGrafikaLab4View::CGrafikaLab4View()
{
// TODO: add construction code here
}
CGrafikaLab4View::~CGrafikaLab4View()
{
}
BOOL CGrafikaLab4View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGrafikaLab4View drawing
void CGrafikaLab4View::OnDraw(CDC* pDC)
{
CGrafikaLab4Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
BOOL bResult = wglMakeCurrent(pDC->m_hDC, m_hrc);
DrawScene();
SwapBuffers(pDC->m_hDC);
wglMakeCurrent(NULL, NULL);
}
/////////////////////////////////////////////////////////////////////////////
// CGrafikaLab4View printing
BOOL CGrafikaLab4View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGrafikaLab4View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGrafikaLab4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGrafikaLab4View diagnostics
#ifdef _DEBUG
void CGrafikaLab4View::AssertValid() const
{
CView::AssertValid();
}
void CGrafikaLab4View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGrafikaLab4Doc* CGrafikaLab4View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGrafikaLab4Doc)));
return (CGrafikaLab4Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGrafikaLab4View message handlers
int CGrafikaLab4View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CClientDC dc(this) ;
PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
int nPixelFormat = ChoosePixelFormat(dc.m_hDC, &pfd);
if (nPixelFormat == 0)
{
TRACE("ChoosePixelFormat Failed %d\r\n",GetLastError()) ;
return -1 ;
}
TRACE("Pixel Format %d\r\n",nPixelFormat) ;
BOOL bResult = SetPixelFormat (dc.m_hDC, nPixelFormat, &pfd);
if (!bResult)
{
TRACE("SetPixelFormat Failed %d\r\n",GetLastError());
return -1;
}
m_hrc = wglCreateContext(dc.m_hDC); // HGLRC m_hrc;
if (!m_hrc)
{
TRACE("wglCreateContext Failed %x\r\n", GetLastError()) ;
return -1;
}
return 0;
}
void CGrafikaLab4View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CClientDC dc(this) ;
BOOL bResult = wglMakeCurrent(dc.m_hDC,m_hrc);
PrepareScene();
wglMakeCurrent(NULL,NULL);
}
void CGrafikaLab4View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if ( (cx <= 0) || (cy <= 0) )
return ;
CClientDC dc(this) ;
// Make the rendering context m_hrc current
BOOL bResult = wglMakeCurrent(dc.m_hDC, m_hrc);
if (!bResult)
{
TRACE("wglMakeCurrent Failed %x\r\n", GetLastError() ) ;
return ;
}
// Set up the mapping of 3-space to screen space
Reshape(cx,cy);
// No rendering context will be current.
wglMakeCurrent(NULL, NULL);
}
BOOL CGrafikaLab4View::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}
void CGrafikaLab4View::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
wglMakeCurrent(NULL,NULL) ;
if (m_hrc)
{
wglDeleteContext(m_hrc) ;
m_hrc = NULL ;
}
}
void CGrafikaLab4View::PrepareScene()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void CGrafikaLab4View::DrawScene()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glLoadIdentity(); //clear matrix
gluLookAt(10,10,10,0,0,0,0,1,0);
DrawWalls();
DrawTable();
glFlush();
}
void CGrafikaLab4View::Reshape(int w, int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60,w/h,1.5,20);
glMatrixMode(GL_MODELVIEW);
}
void CGrafikaLab4View::DrawBox(double a, double b, double c)
{
glBegin(GL_QUAD_STRIP);
glVertex3f(0,0,0);
glVertex3f(0,b,0);
glVertex3f(a,0,0);
glVertex3f(a,b,0);
glVertex3f(a,0,c);
glVertex3f(a,b,c);
glVertex3f(0,0,c);
glVertex3f(0,b,c);
glVertex3f(0,0,0);
glVertex3f(0,b,0);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0,0,0);
glVertex3f(a,0,0);
glVertex3f(a,0,c);
glVertex3f(0,0,c);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0,b,0);
glVertex3f(a,b,0);
glVertex3f(a,b,c);
glVertex3f(0,b,c);
glEnd();
}
void CGrafikaLab4View::DrawTable()
{
//nogice
glColor3f(0,1,0);
glPushMatrix();
glTranslatef(1,0,1);
DrawBox(0.08,5,0.08);
glTranslatef(4,0,0);
DrawBox(0.08,5,0.08);
glTranslatef(0,0,3);
DrawBox(0.08,5,0.08);
glTranslatef(-4,0,0);
DrawBox(0.08,5,0.08);
glPopMatrix();
//donja daska
glColor3f(0.85,0.33,0.33);
glPushMatrix();
glTranslatef(1.08,4,1.08);
DrawBox(4-0.08,1,3-0.08);
glPopMatrix();
//gornja daska
glColor3f(0.75,0.23,0.53);
glPushMatrix();
glTranslatef(0.5,5,0.5);
DrawBox(5-0.08,0.3,4-0.08);
glPopMatrix();
}
void CGrafikaLab4View::DrawWall()
{
glBegin(GL_QUADS);
glVertex3f(0,0,0);
glVertex3f(100,0,0);
glVertex3f(100,100,0);
glVertex3f(0,100,0);
glEnd();
}
void CGrafikaLab4View::DrawWalls()
{
glColor3f(0.8,0.8,0.8);
DrawWall();
glColor3f(0.55,0.55,0.55);
glPushMatrix();
glRotatef(90,1,0,0);
DrawWall();
glPopMatrix();
glColor3f(0.95,0.95,0.95);
glPushMatrix();
glRotatef(-90,0,1,0);
DrawWall();
glPopMatrix();
}
Mada i sa svim ostalim kodovima se isto desava.
Ali presao sam da radim u VS 2005 .Net i tamo nema problema, sto me chudi s obzirom da sam isti problem imao i kad pokrenem exe van studija!!!
|