Exemple #1
0
//---------- Main program
int main(int argc, char **argv) {

	glewExperimental = GL_TRUE;
	glutInit(&argc, argv);

	//Setting up  The Display
	//   -RGB color model + Alpha Channel = GLUT_RGBA
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);

	// Configure Window Position
	int iScreenWidth = glutGet(GLUT_SCREEN_WIDTH);
	int iScreenHeight = glutGet(GLUT_SCREEN_HEIGHT);

	glutInitDisplayMode( GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH );

	glutInitWindowPosition( 0,0 );
	glutInitWindowSize( 800, 600 );

	g_iGLUTWindowHandle = glutCreateWindow( "OpenGL" );

	SetupGL();

	// Loop require by OpenGL
	glutMainLoop();
	return 0;

}
Exemple #2
0
//---------- Main program
int main(int argc, char **argv) {

    glutInit(&argc, argv);

    //Setting up  The Display
    //   -RGB color model + Alpha Channel = GLUT_RGBA
    glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);

    // Configure Window Position
    int iScreenWidth = glutGet(GLUT_SCREEN_WIDTH);
    int iScreenHeight = glutGet(GLUT_SCREEN_HEIGHT);

    int windowHeight = 512;
    int windowWidth = 512;

    int windowXPos = (iScreenWidth - windowWidth)/2;
    int windowYPos = (iScreenHeight - windowHeight)/2;

    glutInitDisplayMode( GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH );

    glutInitWindowPosition( windowXPos, windowYPos);
    glutInitWindowSize( windowWidth, windowHeight);

    g_iGLUTWindowHandle = glutCreateWindow( "OpenGL" );

    SetupGL();

    //Call to the drawing function
    glutDisplayFunc(DisplayGL);
    glutReshapeFunc(ReshapeGL);
    // Loop require by OpenGL
    glutMainLoop();
    return 0;
}
	// initialize application
	bool Engine::InitializeApp(HINSTANCE hInstance, integer nCmdShow, std::wstring strClassName, std::wstring strAppName) {
		mhInst = hInstance;

		WNDCLASSEX wc;
		ZeroMemory(&wc, sizeof(wc));
		wc.cbSize = sizeof(wc);
		wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
		wc.lpfnWndProc = WndProc;
		wc.hInstance = hInstance;
		wc.lpszClassName = strClassName.c_str();
		if (!RegisterClassEx(&wc))
			return false;

		mhWnd = CreateWindow(strClassName.c_str(), strAppName.c_str(), WS_OVERLAPPEDWINDOW,
			CW_USEDEFAULT, CW_USEDEFAULT, mnWndWidth, mnWndHeight,
			NULL, (HMENU)NULL, hInstance, NULL);
		if (mhWnd == NULL)
			return false;

		ShowWindow(mhWnd, nCmdShow);

		if (!EnableGLContext())
			return false;

		glewInit();

		SetupGL();
		return true;
	}
void ModelDrawer::Render(IView *v, const Vector3& teamColor)
{
	if (!glewInitialized) 
		SetupGL();

	if (!model->root)
		return;

	int S3ORendering=0;
	MdlObject *root = model->root;

	if (v->IsSelecting ())
		glDisable(GL_TEXTURE_2D);
	else if (v->GetRenderMode () == M3D_TEX)
		S3ORendering = SetupTextureMapping (v, teamColor);

	Matrix ident;
	ident.identity();
	RenderObject(root, v, model->mapping);

	if (S3ORendering > 0) {
		if (S3ORendering == 2)
			CleanupS3OAdvDrawing ();
		else if (S3ORendering == 1)
			CleanupS3OBasicDrawing ();
		glDisable (GL_TEXTURE_2D);
	}

	if (!v->IsSelecting ())
		RenderSelection (v);

	// draw radius
	if (v->GetConfig (CFG_DRAWRADIUS) != 0.0f)
	{
		glPushMatrix();
		glTranslatef(model->mid.x, model->mid.y, model->mid.z);
		glScalef(model->radius,model->radius,model->radius);
		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
		glColor3ub(255,255,255);
		glDisable(GL_LIGHTING);
		glDisable(GL_CULL_FACE);
		glDisable(GL_TEXTURE_2D);
		glCallList(sphereList);
		glPopMatrix();
	}

	// draw height
	if (v->GetConfig (CFG_DRAWHEIGHT) != 0.0f)
	{
		glLineWidth (5.0f);

		glColor3ub (255,255,0);
		glBegin (GL_LINES);
		glVertex3i(0,0,0);
		glVertex3f(0.0f,model->height,0.0f);
		glEnd();

		glLineWidth (1.0f);
	}
}
void SimpleGLWindow::Initialize(u32 flags) {
	RECT rect;
	GetWindowRect(hWnd_, &rect);

	SetFlags(flags);
	SetupGL();
	ResizeGL(rect.right-rect.left,rect.bottom-rect.top);
	CreateProgram();
	GenerateChecker();
}
void Setup(){
	SetupGL();

	view1=Menu(ScreenQuad::MAIN,ProjectionType::ORTHOGONAL,
		PolygonMode::FILL,0,0,-10,0,1,0);
	//gluLookAt(0, 0, -10, 0, 0, 0, 0, 1, 0);
	view2=Viewport(ScreenQuad::GAME,ProjectionType::ORTHOGONAL,
		PolygonMode::FILL, -12, 9, -20, 0, 1, 0);
	
	loader=SceneLoader("test.txt");
}
Exemple #7
0
bool Engine::InitializeGLContext()
{
    SetupGLAttributes();

    Assert(SetupGL() && "OpenGL initialized");

    ModuleMgr.InitializeGL();
    //bitan je redosled
    XMLParser::Instance()->ParseFonts();
    tahomaFont_ = FontManager::Instance()->GetByName("tahoma16");

}
//=============================================================================
//Initializes the GL application
//=============================================================================
boolean GLApp::Init(IShell *shell, IDisplay *display)
{
	m_pIShell = shell;
	m_pIDisplay = display;

	//create GL interfaces
	if(ISHELL_CreateInstance(m_pIShell, AEECLSID_GL, (void**)&m_pIGL) != SUCCESS) 
	{
		return FALSE;
	}
	else 
	{
		IGL_Init(m_pIGL);
	}

	if(ISHELL_CreateInstance(m_pIShell, AEECLSID_EGL, (void**)&m_pIEGL) != SUCCESS) 
	{
		return FALSE;
	}
	else 
	{
		IEGL_Init(m_pIEGL);
	}

	//get device frame buffer info
	if(IDisplay_GetDeviceBitmap(display, &m_pDBitmap) != SUCCESS)
	{
		CleanUp();
		return FALSE;
	}

	if(IBitmap_GetInfo(m_pDBitmap, &m_DBitmapInfo, sizeof(AEEBitmapInfo)) != SUCCESS)
	{
		CleanUp();
		return FALSE;
	}

	if(!SetupEGL(display))
		return FALSE;

	if(!SetupGL())
		return FALSE;

	//setup shapes
	m_Cube.Init(shell);

	return TRUE;
}
Exemple #9
0
int main(int argc, char** argv)
{
	glutInit(&argc, argv);

	char c;
	std::string kappaFile = "";

	while ((c = getarg(argc, argv)) != EOF)
	{
		switch (c)
		{
		
		case 'f':
			kappaFile = arg;
			break;

		case 'h':
			PrintInputHelp();
			return 0;

		default:
			fprintf(stderr, "-%c is an invalid option, please use the -h option for help.\n", c);
			return 0;
		}
	}

	glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH);

	// Centering the window on the screen
	int screenWidth = glutGet(GLUT_SCREEN_WIDTH);
	int screenHeight = glutGet(GLUT_SCREEN_HEIGHT);
	glutInitWindowPosition(screenWidth / 2 - windowsWidth / 2, screenHeight / 2 - windowsHeight / 2);
	glutInitWindowSize(windowsWidth, windowsHeight);
	
	// Setup program
	auto glProject = new GlProject(windowsWidth, windowsHeight, glutCreateWindow("CheckerBoard"), kappaFile);

	// If setup was successful, start main loop.
	if(glProject->SetupGL())
		glutMainLoop();

	return 0;
}
Exemple #10
0
int MakeWindow(int argument_count, void* data)
{
    int error = 0;
    //if (argument_count != 3) return 1;

    int width, height;
    const char* szClassName;

    VALUE r_width = GetRecord("width", gCurrentContext);
    VALUE r_height = GetRecord("height", gCurrentContext);
    VALUE r_title = GetRecord("name", gCurrentContext);
    VALUE r_fullscreen = GetRecord("fullscreen", gCurrentContext);

    width = TypeInt(r_width);
    height = TypeInt(r_height);
    szClassName = (r_title.type == VAL_STRING) ? r_title.data.string : "Untitled";

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
    SDL_ShowCursor(0);
    SDL_SetVideoMode(width, height, 24, SDL_OPENGL |
        SDL_GL_DOUBLEBUFFER |
        SDL_HWPALETTE |
        SDL_HWSURFACE |
        SDL_HWACCEL |
        (TypeInt(r_fullscreen) ? SDL_FULLSCREEN : 0)
/* | SDL_FULLSCREEN */
        );
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_WM_SetCaption(szClassName, szClassName);
    SetupGL(width, height);

    game_is_running = 1;

    gLastExpression.type = VAL_NIL;
    gLastExpression.data.primitive = 0;
    return error;
}
Exemple #11
0
void World::Render()
{
	if(cameraType == CT_3RD)
		UpdateCamera3rd();
	else if(cameraType == CT_1ST)
		UpdateCamera1st();

	SetupGL();

	btScalar m[16];
	btMatrix3x3	rot;
	rot.setIdentity();
	const int numObjects = dynamicsWorld->getNumCollisionObjects();
	btVector3 wireColor(1,0,0);

	//render all objs
	for(int i=0; i<numObjects; i++)
	{
		btCollisionObject* colObj=dynamicsWorld->getCollisionObjectArray()[i];
		btRigidBody* body=btRigidBody::upcast(colObj);

		if(body&&body->getMotionState())
		{
			btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
			myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
			rot = myMotionState->m_graphicsWorldTrans.getBasis();
		}
		else
		{
			colObj->getWorldTransform().getOpenGLMatrix(m);
			rot = colObj->getWorldTransform().getBasis();
		}
		btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
		if(i&1) wireColor=btVector3(0.f,0.0f,1.f);
		///color differently for active, sleeping, wantsdeactivation states
		if (colObj->getActivationState() == 1) //active
		{
			if (i & 1)
			{
				wireColor += btVector3 (1.f,0.f,0.f);
			}
			else
			{			
				wireColor += btVector3 (.5f,0.f,0.f);
			}
		}
		if(colObj->getActivationState()==2) //ISLAND_SLEEPING
		{
			if(i&1)
			{
				wireColor += btVector3 (0.f,1.f, 0.f);
			}
			else
			{
				wireColor += btVector3 (0.f,0.5f,0.f);
			}
		}

		btVector3 aabbMin,aabbMax;
		dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin, aabbMax);
		
		aabbMin-=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
		aabbMax+=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);

		//set texture for terrain
		if(body == groundRigidBody)
		{
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, groundTexture);

			static const GLfloat	planex[]={0.1f,0.f,0.f,21.f};
			//static const GLfloat	planey[]={0,0.025,0,0};
			static const GLfloat	planez[]={0.f,0.f,0.1f,21.f};

			glTexGenfv(GL_S,GL_OBJECT_PLANE,planex);
			glTexGenfv(GL_T,GL_OBJECT_PLANE,planez);
			glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
			glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
			glEnable(GL_TEXTURE_GEN_S);
			glEnable(GL_TEXTURE_GEN_T);

			wireColor = btVector3(1.f, 1.f, 1.f);
		}

		shapeDrawer->drawOpenGL(m, colObj->getCollisionShape(), wireColor, 0, aabbMin, aabbMax);

		if(body == groundRigidBody)
		{
			glBindTexture(GL_TEXTURE_2D, 0);
			glDisable(GL_TEXTURE_2D);
			glDisable(GL_TEXTURE_GEN_S);
			glDisable(GL_TEXTURE_GEN_T);
		}
	}

	//draw wheels
	if(cameraType != CT_1ST)
		vehicle->Render(shapeDrawer);
}
Exemple #12
0
static int LoadGL(const char *driver)
{
    int colorbits = Cvar_ClampInteger(gl_colorbits, 0, 32);
    int depthbits = Cvar_ClampInteger(gl_depthbits, 0, 32);
    int stencilbits = Cvar_ClampInteger(gl_stencilbits, 0, 8);
    int multisamples = Cvar_ClampInteger(gl_multisamples, 0, 32);
    int ret;

    // figure out if we're running on a minidriver or not
    if (!Q_stricmp(driver, "opengl32") ||
        !Q_stricmp(driver, "opengl32.dll")) {
        glw.minidriver = qfalse;
    } else {
        Com_Printf("...running a minidriver: %s\n", driver);
        glw.minidriver = qtrue;
    }

    // load the OpenGL library and bind to it
    if (!WGL_Init(driver)) {
        ReportLastError("WGL_Init");
        return FAIL_SOFT;
    }

    // check if basic WGL entry points are present
    if (!qwglCreateContext || !qwglMakeCurrent || !qwglDeleteContext) {
        Com_EPrintf("Required WGL entry points are missing\n");
        goto fail;
    }

    if (glw.minidriver) {
        // check if MCD entry points are present if using a minidriver
        if (!qwglChoosePixelFormat || !qwglSetPixelFormat ||
            !qwglDescribePixelFormat || !qwglSwapBuffers) {
            Com_EPrintf("Required MCD entry points are missing\n");
            goto fail;
        }
    }

    // check for WGL_ARB_multisample by creating a fake window
    if (multisamples > 1) {
        unsigned extensions = GetFakeWindowExtensions();

        if (extensions & QWGL_ARB_multisample) {
            if (qwglChoosePixelFormatARB) {
                Com_Printf("...enabling WGL_ARB_multisample\n");
            } else {
                Com_Printf("...ignoring WGL_ARB_multisample, WGL_ARB_pixel_format not found\n");
                Cvar_Set("gl_multisamples", "0");
                multisamples = 0;
            }
        } else {
            Com_Printf("WGL_ARB_multisample not found\n");
            Cvar_Set("gl_multisamples", "0");
            multisamples = 0;
        }
    }

    // create window, choose PFD, setup OpenGL context
    ret = SetupGL(colorbits, depthbits, stencilbits, multisamples);

    // attempt to recover
    if (ret == FAIL_SOFT && (colorbits || depthbits || stencilbits || multisamples > 1)) {
        Cvar_Set("gl_multisamples", "0");
        ret = SetupGL(0, 0, 0, 0);
    }

    if (ret)
        goto fail;

    return FAIL_OK;

fail:
    // it failed, clean up
    WGL_Shutdown();
    return FAIL_SOFT;
}
Exemple #13
0
void Renderer::Display( sf::RenderWindow& window ) {
	// Refresh VBO data if out of sync
	if( !m_vbo_synced ) {
		RefreshVBO( window );

		m_vbo_synced = true;
	}

	// Thanks to color / texture modulation we can draw the entire
	// frame in a single pass by pseudo-disabling the texturing with
	// the help of a white texture ( 1.f * something = something ).
	// Further, we stick all referenced textures into our giant atlas
	// so we don't have to rebind during the draw.

	SetupGL( window );

	m_texture_atlas.bind();

	glBindBuffer( GL_ARRAY_BUFFER, m_vertex_vbo );
	glVertexPointer( 3, GL_FLOAT, 0, 0 );

	glBindBuffer( GL_ARRAY_BUFFER, m_color_vbo );
	glColorPointer( 4, GL_UNSIGNED_BYTE, 0, 0 );

	glBindBuffer( GL_ARRAY_BUFFER, m_texture_vbo );
	glTexCoordPointer( 2, GL_FLOAT, 0, 0 );

	// Not needed, constantly kept enabled by SFML... -_-
	//glEnableClientState( GL_VERTEX_ARRAY );
	//glEnableClientState( GL_COLOR_ARRAY );
	//glEnableClientState( GL_TEXTURE_COORD_ARRAY );

	std::size_t scissor_pairs_size = m_viewport_pairs.size();

	glEnable( GL_SCISSOR_TEST );

	for( std::size_t index = 0; index < scissor_pairs_size; ++index ) {
		const ViewportPair& scissor_pair = m_viewport_pairs[index];

		RendererViewport::Ptr viewport = scissor_pair.first;

		if( viewport && ( viewport != m_default_viewport ) ) {
			sf::Vector2f destination_origin = viewport->GetDestinationOrigin();
			sf::Vector2f size = viewport->GetSize();

			glScissor(
				static_cast<int>( destination_origin.x ),
				window.getSize().y - static_cast<int>( destination_origin.y + size.y ),
				static_cast<int>( size.x ),
				static_cast<int>( size.y )
			);
		}
		else {
			glScissor( 0, 0, window.getSize().x, window.getSize().y );
		}

		if( index < scissor_pairs_size - 1 ) {
			glDrawArrays( GL_TRIANGLES, scissor_pair.second, m_viewport_pairs[index + 1].second - scissor_pair.second );
		}
		else {
			glDrawArrays( GL_TRIANGLES, scissor_pair.second, m_last_vertex_count - scissor_pair.second );
		}
	}

	glDisable( GL_SCISSOR_TEST );

	//glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	//glDisableClientState( GL_COLOR_ARRAY );
	//glDisableClientState( GL_VERTEX_ARRAY );

	// Needed otherwise SFML will blow up...
	glBindBuffer( GL_ARRAY_BUFFER, 0 );

	RestoreGL( window );
}
Exemple #14
0
bool Engine::Create(std::string title,
                    short int width,
                    short int height,
                    char bits,
                    Uint32 sdlFlags,
                    Uint32 videoFlags,
                    double fps,
                    bool fullscreen,
                    std::string maindir)
{

    Assert ( width > 0 );
    Assert ( height > 0 );
    Assert ( bits > 8 );
    Assert ( title != "" ); //I think it should work


    videoFlags_ = videoFlags;
    sdlFlags_   = sdlFlags;
    width_      = width;
    height_     = height;
    name_       = title;
    bits_       = bits;
    fullscreen_ = fullscreen;
    mainDir_    = maindir;

    if (SDL_Init(sdlFlags_) < 0)
    {
        std::cout << "Couldn't initialize SDL - " << SDL_GetError() << std::endl;
        return false;
    }

    SetupGLAttributes();

    if(SDL_SetVideoMode(width_, height_, bits_, videoFlags_) == NULL)
    {
        std::cout << "Couldn't set GL mode >> " << SDL_GetError() << std::endl;
        SDL_Quit();
        return false;
    }

    SDL_WM_SetCaption ( name_.c_str( ) , NULL );

    Assert(SetupGL() && "OpenGL initialization");
    std::cout<<"OpenGL initialized"<<std::endl;

    if(!Initialize())
    {
        return false;
    }

    SDL_EnableUNICODE(1);
    SDL_EnableKeyRepeat(200,200);

    Resize(width_, height_);

    screen_ = SDL_GetVideoSurface();

    if(fullscreen_)
        ToggleFullscreen();

    tahomaFont_ = FontManager::Instance()->GetByName("tahoma16");

    timer_ = new PrecisionTimer(fps);
    timer_->SmoothUpdatesOn();
    timer_->Start();

    return true;
}