Example #1
0
int Engine::Init(std::string title)
{
	// Start SDL 
	if(SDL_Init( SDL_INIT_VIDEO ) == -1)
		return -1;

	// Setup double Buffering
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	//kill sdl on exiting
	atexit(SDL_Quit);

	// setup screen (with OpenGL)
	screen = SDL_SetVideoMode(ScreenWidth, ScreenHeight, BitsPerPixel, SDL_OPENGL);

	if(screen == NULL)
		return -1;

	// set the window title
	SDL_WM_SetCaption(title.c_str(), NULL);

	//Initialise OpenGL
	InitGL();

	//Intialise Audio
	soundManager = new SoundManager();

	// seed random
	srand(time(NULL));

	return 0;
}
Example #2
0
void Pcb3D_GLCanvas::Redraw( void )
/**********************************/
{
    SetCurrent();

	InitGL();

    glMatrixMode(GL_MODELVIEW);    /* position viewer */
    /* transformations */
    GLfloat mat[4][4];
	glTranslatef(Draw3d_dx, Draw3d_dy, 0.0F);

    build_rotmatrix( mat, g_Parm_3D_Visu.m_Quat );
    glMultMatrixf( &mat[0][0] );

    glRotatef(g_Parm_3D_Visu.m_Rot[0], 1.0, 0.0, 0.0);
	glRotatef(g_Parm_3D_Visu.m_Rot[1], 0.0, 1.0, 0.0);
    glRotatef(g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0);

	if( m_gllist ) glCallList( m_gllist );
	else
	{
		m_gllist = CreateDrawGL_List();
//		m_gllist = DisplayCubeforTest();
	}

	glFlush();
	SwapBuffers();
 }
Example #3
0
int main(int argc, char* argv[]){	

	cout << PROGRAM_NAME << " - " << VERSION << endl
		<< "BYU CS 455 - Fall 2012" << endl << endl
		<< "Created by:" << endl
		<< "\tJosh Davis" << endl
		<< "\tTyler Gill" << endl
		<< "\tMorgan Strong" << endl
		<< "\tJames Williams" << endl << endl;
	
	glutInit(&argc, argv);
	/* setting up double buffering rbg and depth for this */
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(windowWidth, windowHeight);
	glutInitWindowPosition(100, 100);
	/* this name needs to match the name of the window in DrawGLScene */
	glutCreateWindow(windowName);

	InitGL();

	/* the draw function will draw once and no more */
	glutDisplayFunc(DrawGLScene);
	/* this is the idle function it gets called as much as possible */
	glutIdleFunc(IdleGLScene);
	/* This is called everytime the window is altered */
	glutReshapeFunc(ReSizeGLScene);
	/* this gets called on a keyboard event */
	//glutKeyboardFunc(GLKeyDown);

	//glutSpecialFunc(SpecialKeys);

	//glutSpecialUpFunc(SpecialKeysUp);

	// Game initialization
	ObjectMan* man = ObjectMan::GetInstance();
	InputMan* inman = InputMan::GetInstance();

	cout << "Running Game..." << endl << endl;

	/* Gets the loop rolling */
	try{
		/* 
		 * This loop wont return ever so we are going to play some tricks
		 * to make it look like it exits when it is actually done. That is why
		 * we use the try catch.
		 */
		// TODO: Override the x button on the window.
		glutMainLoop();
	}
	catch(const char* msg){
		printf(msg);

		HWND hwnd = FindWindow("glut", windowName);
		ShowWindow(hwnd, SW_HIDE);
		Sleep(500);
	}

	return 0;
}
Example #4
0
	void CoreMac::Init(const ax::Size& frame_size)
	{
//		std::cout << "Init axCoreMac." << std::endl;
		InitManagers();
		InitGL();
		ResizeFrame(frame_size);
		//    _size = frame_size;
	}
Example #5
0
Player::Player(World& world, glm::vec3 position, glm::vec2 rotation, float speed)
    : Entity(world,
        AABB(position, glm::vec3(-0.4, 0, -0.4), glm::vec3(0.4, 1.8, 0.4)),
        rotation, speed),
    m_blockSelected(glm::vec3(), glm::vec3(), glm::vec3())
{
    InitGL();
}
BOOL CIdleOpenGLWnd::OnCreate(LPCREATESTRUCT lpcs)
{
	if (!MSG_FORWARD_WM_CREATE(COpenGLWnd, lpcs))
		return FALSE;

	m_hrc = InitGL();
	return TRUE;
}
Example #7
0
bool InitEverything(SDL_GLContext& g_Context, SDL_Window*& g_Window, std::unique_ptr<Scene>& pScene) {
	if (InitSDL())
		if (InitGL(g_Context, g_Window))
			if (InitSound())
				if (InitPython())
					if (InitScene(pScene))
						return true;
	return false;
}
Example #8
0
void View2::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	LEFT_DOWN=false;
	RIGHT_DOWN=false;

	InitGL();
}
Example #9
0
int main(int argc, char **argv) {

	if (argc < 6) {
		printf("usage: leitura arqin.raw width height slices dslices colormap\n");
		exit(1);
	}

	glutInit(&argc, argv);
	//glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(640, 640);
	glutCreateWindow("Teste de Vizualizacao com textura 3D");

	glutDisplayFunc(&DrawGLScene);
	glutIdleFunc(&DrawGLScene);
	glutReshapeFunc(&ReSizeGLScene);
	glutKeyboardFunc(&keyPressed);

	glutMotionFunc(MoveMouseBotaoPressionado);
	glutPassiveMotionFunc(MoveMouse);
	glutMouseFunc(GerenciaMouse);

	raw = readRAW(argc, argv);

	GLenum err = glewInit();
	if (GLEW_OK != err) {
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}
	if (glewIsSupported("GL_VERSION_2_1"))
		printf("Ready for OpenGL 2.1\n");
	else {
		printf("OpenGL 2.1 not supported\n");
		exit(1);
	}
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader
			&& GL_EXT_geometry_shader4)
		printf("Ready for GLSL - vertex, fragment, and geometry units\n");
	else {
		printf("Not totally ready :( \n");
		exit(1);
	}

	if(argc==7) colorMapRead(argv[6],cm);
	else {
		createColorMap(cm);
		//colorMapWrite("teste.map", cm);
		//colorMapRead("teste.map", cm);
	}

	InitGL(640, 640);

	/* Start Event Processing Engine */
	glutMainLoop();

	return 1;
}
Example #10
0
int main( int argc, char* argv[] )
{
    g_InitialCameraPosition = glm::vec3( 0, 0, 10 );
    g_Camera.SetPosition( g_InitialCameraPosition );
    g_Camera.SetRotation( g_InitialCameraRotation );

    InitGL(argc, argv);
    InitGLEW();

    // Load some shaders.
    GLuint vertexShader = LoadShader( GL_VERTEX_SHADER, "../data/shaders/simpleShader.vert" );
    GLuint fragmentShader = LoadShader( GL_FRAGMENT_SHADER, "../data/shaders/simpleShader.frag" );

    std::vector<GLuint> shaders;
    shaders.push_back(vertexShader);
    shaders.push_back(fragmentShader);

    // Create the shader program.
    g_ShaderProgram = CreateShaderProgram( shaders );
    assert( g_ShaderProgram != 0 );

    GLint positionAtribID = glGetAttribLocation( g_ShaderProgram, "in_position" );
    GLint colorAtribID = glGetAttribLocation( g_ShaderProgram, "in_color" );
    g_uniformMVP = glGetUniformLocation( g_ShaderProgram, "MVP" );

    // Create a VAO for the cube.
    glGenVertexArrays( 1, &g_vaoCube );
    glBindVertexArray( g_vaoCube );

    GLuint vertexBuffer, indexBuffer;
    glGenBuffers( 1, &vertexBuffer );
    glGenBuffers( 1, &indexBuffer );

    glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(g_Vertices), g_Vertices, GL_STATIC_DRAW );

    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(g_Indices), g_Indices, GL_STATIC_DRAW );

    glVertexAttribPointer( positionAtribID, 3, GL_FLOAT, false, sizeof(VertexXYZColor),
                            reinterpret_cast<const GLvoid*>(offsetof(VertexXYZColor,m_Pos)) );
    glEnableVertexAttribArray( positionAtribID );

    glVertexAttribPointer( colorAtribID, 3, GL_FLOAT, false, sizeof(VertexXYZColor),
                            reinterpret_cast<const GLvoid*>(offsetof(VertexXYZColor,m_Color)));
    glEnableVertexAttribArray( colorAtribID );

    // Make sure we disable and unbind everything to prevent rendering issues later.
    glBindVertexArray( 0 );
    glBindBuffer( GL_ARRAY_BUFFER, 0 );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
    glDisableVertexAttribArray( positionAtribID );
    glDisableVertexAttribArray( colorAtribID );

    glutMainLoop();
}
Example #11
0
//---------------------------------------------------------------------------
int CFabAtHomeView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
//---------------------------------------------------------------------------
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	InitGL();	// initialize OpenGL
	
	return 0;
}
Example #12
0
int main(int argc, char* argv[])
{
	g_PreviousTime = std::clock();
	std::string windowname = "test";

	InitGL(argc, argv, windowname); //create window with name
	glutMainLoop(); //enter openGL's main loop

	return 0;
}
int main(int argc,char **argv)
{
  srandom(123456789);
  init_particles();
  InitGL(argc, argv);
  InitCL(); 
  glutDisplayFunc(mydisplayfunc);
  glutKeyboardFunc(getout);
  glutMainLoop();
}
Example #14
0
// The ubiquituous main function.
int main ( int argc, char** argv )   // Create Main Function For Bringing It All Together
{
	// get the the filename from the commandline.
	/*if (argc!=2)
	{
		printf("usage: %s trackfilname\n", argv[0]);
		system("PAUSE");
		exit(1);
	}*/

	/* load the track, this routine aborts if it fails */
	g_Track.loadSplineFrom("track");



	/*** The following are commands for setting up GL      ***/
	/*** No OpenGl call should be before this sequence!!!! ***/

	/* Initialize glut */
	glutInit(&argc,argv);
	/* Set up window modes */
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	/* Set window position (where it will appear when it opens) */
	glutInitWindowPosition(0,0);
	/* Set size of window */
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	/* Create the window */
	glutCreateWindow    ( "CMPSC 458: Rollercoaster" ); // Window Title (argv[0] for current directory as title)
	/**** Call to our initialization routine****/
	InitGL ();
	/* tells glut to use a particular display function to redraw */
	glutDisplayFunc(display);
	/** allow the user to quit using the right mouse button menu **/
	/* Set menu function callback */
	g_iMenuId = glutCreateMenu(menufunc);
	/* Set identifier for menu */
	glutSetMenu(g_iMenuId);
	/* Add quit option to menu */
	glutAddMenuEntry("Quit",0);
	/* Add any other menu functions you may want here.  The format is:
	* glutAddMenuEntry(MenuEntry, EntryIndex)
	* The index is used in the menufunc to determine what option was selected
	*/
	/* Attach menu to right button clicks */
	glutAttachMenu(GLUT_RIGHT_BUTTON);
	/* Set idle function.  You can change this to call code for your animation,
	* or place your animation code in doIdle */
	glutIdleFunc(doIdle);
	/* callback for keyboard input */
	glutKeyboardFunc(keyboardfunc);

	glutMainLoop        ( );          // Initialize The Main Loop

	return 0;
}
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;
	angle = 0.0f;
	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_OPENGLWIN32PROJECT, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_OPENGLWIN32PROJECT));
	
	InitGL();
	glClear(GL_COLOR_BUFFER_BIT);
	bExit = false;
	//main game loop
	while (!bExit)
	{
		
		
		// Main message loop:
		PeekMessage(&msg, hWnd, NULL, NULL, PM_REMOVE);
		if (msg.message == WM_QUIT)
		{
			bExit = true;
		}
		else
		{
			//draw functions
			Render();

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		
	}

	

	return (int) msg.wParam;
}
Example #16
0
NaGsView::NaGsView(CWnd* pWnd, NaGsDisplayContext* ctx) : m_ptrWnd(pWnd), m_theContext(ctx)
{
	m_xRot = -45.0f;
	m_zRot = -45.0f;
	m_yRot = 0;
	m_xTrans = m_yTrans = m_zTrans = 0.0f;

	m_myCamera = new NaDbCamera();

	m_myViewType = GLAXONVIEW;
	m_myProjType = GLORTHOGRAPHIC;

	m_nRange = 500;

	m_bkRed = 134 / 255.0;
	m_bkGreen = 193 / 255.0;
	m_bkBlue = 239 / 255.0;

	m_displayMode = GLSHADED;

	m_antialias = false;

	//1
	m_colorv[0].amb[0] =  0.0F;	m_colorv[0].amb[1] =  0.0F;	m_colorv[0].amb[2] =  0.0F;
	m_colorv[0].diff[0] =  0.1F;	m_colorv[0].diff[1] =  0.6F;	m_colorv[0].diff[2] =  0.3F;
	m_colorv[0].spec[0] =  1.0F;	m_colorv[0].spec[1] =  1.0F;	m_colorv[0].spec[2] =  1.0F;
	m_colorv[0].ratio =  0.75F;
	m_colorv[0].indexes[0] =  0;	m_colorv[0].indexes[1] =  0;	m_colorv[0].indexes[2] =  0;

	//2
	m_colorv[1].amb[0] =  0.0F;	m_colorv[1].amb[1] =  0.0F;	m_colorv[1].amb[2] =  0.0F;
	m_colorv[1].diff[0] =  0.0F;	m_colorv[1].diff[1] =  0.2F;	m_colorv[1].diff[2] =  0.5F;
	m_colorv[1].spec[0] =  1.0F;	m_colorv[1].spec[1] =  1.0F;	m_colorv[1].spec[2] =  1.0F;
	m_colorv[1].ratio =  0.75F;
	m_colorv[1].indexes[0] =  0;	m_colorv[1].indexes[1] =  0;	m_colorv[1].indexes[2] =  0;

	//3
	m_colorv[2].amb[0] =  0.0F;	m_colorv[2].amb[1] =  0.05F;	m_colorv[2].amb[2] =  0.05F;
	m_colorv[2].diff[0] =  0.6F;	m_colorv[2].diff[1] =  0.0F;	m_colorv[2].diff[2] =  0.8F ;
	m_colorv[2].spec[0] =  1.0F;	m_colorv[2].spec[1] =  1.0F;	m_colorv[2].spec[2] =  1.0F ;
	m_colorv[2].ratio =  0.75F;
	m_colorv[2].indexes[0] =  0;	m_colorv[2].indexes[1] =  0;	m_colorv[2].indexes[2] =  0 ;

	m_ZoomON = false;
	m_PanON = false;
	m_RotON = false;

	m_gridOn = false;

	myTrihedron = new NaDbTrihedron;
	myGrid = new NaDbGrid;

	InitGL();

}
Example #17
0
// In this function, we save the instance handle, then create and display the main program window.
BOOL SingleFace::InitInstance(HINSTANCE hInstance, PWSTR lpCmdLine, int nCmdShow)
{
    m_hInst = hInstance; // Store instance handle in our global variable

    ParseCmdString(lpCmdLine);

    WCHAR szTitle[MaxLoadStringChars];                  // The title bar text
    LoadString(m_hInst, IDS_APP_TITLE, szTitle, ARRAYSIZE(szTitle));

    static const PCWSTR RES_MAP[] = { L"80x60", L"320x240", L"640x480", L"1280x960" };
    static const PCWSTR IMG_MAP[] = { L"PLAYERID", L"RGB", L"YUV", L"YUV_RAW", L"DEPTH" };

    // Add mode params in title
    WCHAR szTitleComplete[MAX_PATH];
    swprintf_s(szTitleComplete, L"%s -- Depth:%s:%s Color:%s:%s NearMode:%s, SeatedSkeleton:%s", szTitle,
        IMG_MAP[m_depthType], (m_depthRes < 0)? L"ERROR": RES_MAP[m_depthRes], IMG_MAP[m_colorType], (m_colorRes < 0)? L"ERROR": RES_MAP[m_colorRes], m_bNearMode? L"ON": L"OFF",
        m_bSeatedSkeletonMode?L"ON": L"OFF");

    WCHAR szWindowClass[MaxLoadStringChars];            // the main window class name
    LoadString(m_hInst, IDC_SINGLEFACE, szWindowClass, ARRAYSIZE(szWindowClass));

    RegisterClass(szWindowClass);

    m_hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SINGLEFACE));

    m_pImageBuffer = FTCreateImage();
    m_pVideoBuffer = FTCreateImage();

    m_hWnd = CreateWindow(szWindowClass, szTitleComplete, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, WINDOWWIDTH, WINDOWHEIGHT, NULL, NULL, m_hInst, this);
    if (!m_hWnd)
    {
        return FALSE;
    }

    ShowWindow(m_hWnd, nCmdShow);
    UpdateWindow(m_hWnd);

#ifdef USEOPENGL
	m_GLContext.init(m_hWnd);
	InitGL();
#endif

    return SUCCEEDED(m_FTHelper.Init(m_hWnd,
        FTHelperCallingBack,
        this,
        m_depthType,
        m_depthRes,
        m_bNearMode,
        TRUE, // if near mode doesn't work, fall back to default mode
        m_colorType,
        m_colorRes,
        m_bSeatedSkeletonMode));
}
int main(int argc, char** argv) {
	OptParse(argv);

	if(InitGL()) return -1;

	Render();

	glfwTerminate();

	return 0;
}
Example #19
0
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg) {
		case WM_CREATE:
			GetCursorPos(&initpoint);
			InitGL(hwnd);
			oldticks = GetTickCount();
			TimerID = timeSetEvent (timerdelay, 0, TimeProc, (DWORD)hwnd, TIME_PERIODIC);
			break;
		case WM_PAINT:
		{
			DWORD ticks = oldticks;
			POINT currpoint;
			oldticks = GetTickCount();
			DrawScene(hwnd, dc, oldticks - ticks);
			if(fullscreen)
			{
				GetCursorPos(&currpoint);
				if(abs(currpoint.x - initpoint.x) + (abs(currpoint.y - initpoint.y)) > 10)
					PostMessage(hwnd, WM_CLOSE, 0, 0);
			}
			break;
		}
		case WM_DESTROY:
			timeKillEvent(TimerID);
			gluDeleteQuadric(cylinder);
			wglMakeCurrent(0, 0);
			wglDeleteContext(hrc);
			ReleaseDC(hwnd, dc);
			DeleteDC(dc);
			if (fullscreen)
				ShowCursor(TRUE);
			PostQuitMessage(0);
			break;
		case WM_NOTIFY:
		case WM_SYSKEYDOWN:
			PostMessage(hwnd, WM_CLOSE, 0, 0);
			break;
		case WM_SIZE:
		{
			int width = LOWORD(lParam);
			int height = HIWORD(lParam);
			float fscale;
			glViewport(0, 0, width, height);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			fscale = 0.8/(float)lvls;
			glScalef(fscale, fscale, fscale);
			break;
		}

	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Example #20
0
static void realize_sub( GtkWidget* w )
{
    GdkGLContext* glContext = gtk_widget_get_gl_context( w );
    GdkGLDrawable* glDrawable = GDK_GL_DRAWABLE( gtk_widget_get_gl_window( w ) );

	if( !gdk_gl_drawable_gl_begin( glDrawable, glContext ) )
        g_assert_not_reached();

    InitGL();
    gdk_gl_drawable_gl_end( glDrawable );
}
Example #21
0
//---------------------------------------------------------------------------------
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, 	_In_opt_ HINSTANCE hPrevInstance,	_In_ LPWSTR    lpCmdLine, _In_ int       nCmdShow)
{	
	int argc = 0;	char* argv = "";

	// Exit handler to check memory on exit.
	const int result_1 = std::atexit(CheckMemCallback);

	std::wstring commandLine(lpCmdLine);
	gEditorMode = commandLine.find(L"-Editor") != std::string::npos;

	// Setup glut.
	glutInit(&argc, &argv);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	glutInitWindowPosition(100, 100);
	int glutWind = glutCreateWindow(APP_WINDOW_TITLE);	
	HDC dc = wglGetCurrentDC();
	MAIN_WINDOW_HANDLE = WindowFromDC(dc);
	glutIdleFunc(Idle);
	glutDisplayFunc(Display);       // Register callback handler for window re-paint event	
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
	InitGL();                       // Our own OpenGL initialization

	// Init sounds system.
	CSimpleSound::GetInstance().Initialize(MAIN_WINDOW_HANDLE);
	
	// Call user defined init.
	if (gEditorMode)
	{
		EditorInit();
	}
	else
	{
		Init();
	}

	// Enter glut the event-processing loop				
	glutMainLoop();
	
	// Call user shutdown.
	if (gEditorMode)
	{
		EditorShutdown();
	}
	else
	{
		Shutdown();
	}

	// Shutdown sound system.
	CSimpleSound::GetInstance().Shutdown();

	// And we are done.
	return 0;
}
Example #22
0
int main (int argc, char ** argv)
{
	glutInit(&argc, argv);
	InitGL();

	timerCallback(0);
	glutKeyboardFunc(Key);
	glutSpecialFunc(SpecialKey);
	glutDisplayFunc(Draw);
	glutMainLoop();
	return 0;
}
Example #23
0
int main(int argc, char *argv[])
{
	if (SDL_Init(SDL_INIT_VIDEO) != 0)
	{
		printf("Unable to init SDL: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}

	atexit(SDL_Quit);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

	if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_OPENGL) == NULL)
	{
		printf("Unable to set video mode: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}

	SDL_WM_SetCaption("SDL - OpenGl framework", "OpenGL");

	InitGL();

	// game loop
	bool loopcontinue = true;
	SDL_Event event;

	while (loopcontinue)
	{
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_ESCAPE)
					loopcontinue = false;
			
				kbd_event(event.key.keysym.sym);	
				break;

			case SDL_QUIT:
				loopcontinue = false;
				break;
			}
		}

		RenderScene();

		SDL_GL_SwapBuffers();
	}
}
Example #24
0
void GLEngine::Init(HWND hWnd)
{
	logging::add_file_log("log.txt");
	m_hdc = GetDC(hWnd);
	
	m_viewManager = CreateManager();
	m_Object = m_viewManager->CreateObject();
	
	RECT rc;
	GetWindowRect(hWnd, &rc);
	m_camera.SetCenter(rc.left+(rc.right-rc.left)/2,rc.top+(rc.bottom-rc.top)/2);

	GLuint		PixelFormat;
	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
		1,											// Version Number
		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
		PFD_TYPE_RGBA,								// Request An RGBA Format
		16,										// Select Our Color Depth
		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
		0,											// No Alpha Buffer
		0,											// Shift Bit Ignored
		0,											// No Accumulation Buffer
		0, 0, 0, 0,									// Accumulation Bits Ignored
		16,											// 16Bit Z-Buffer (Depth Buffer)  
		0,											// No Stencil Buffer
		0,											// No Auxiliary Buffer
		PFD_MAIN_PLANE,								// Main Drawing Layer
		0,											// Reserved
		0, 0, 0										// Layer Masks Ignored
	};

	PixelFormat=ChoosePixelFormat(m_hdc, &pfd);	// Did Windows Find A Matching Pixel Format?

	BOOL res = SetPixelFormat(m_hdc, PixelFormat, &pfd);		// Are We Able To Set The Pixel Format?	

	m_hglrc = wglCreateContext(m_hdc);
	if(!m_hglrc)
	{
		BOOST_LOG_TRIVIAL(error) << "Error wglCreateContext: " << __LINE__;
		DWORD error = GetLastError();
	}

	if(!wglMakeCurrent(m_hdc, m_hglrc))
		BOOST_LOG_TRIVIAL(error) << "Error wglMakeCurrent: " << __LINE__;

	ResizeScene(800, 600);	
	InitGL();
	InitTextures();
}
Example #25
0
static gboolean configure( GtkWidget* da, GdkEventConfigure* event, gpointer user_data )
{
	GdkGLContext *GLcontext = gtk_widget_get_gl_context( da );
	GdkGLDrawable *GLdrawable = GDK_GL_DRAWABLE( gtk_widget_get_gl_window( da ) );

	if( !gdk_gl_drawable_gl_begin( GLdrawable, GLcontext ) )
        g_assert_not_reached();

    InitGL();
    gdk_gl_drawable_gl_end( GLdrawable );
    return TRUE;
}
Example #26
0
int main (int argc, char **argv)
{
   glutInit (&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (750, 750);               // TODO : Reference
   
   glutCreateWindow (argv[0]);                  // TODO : Reference
   
   /* This function is called only once the OpenGL window is created. */
   InitGL (750, 750);
   
   /******************************* INITIALIZATION *****************************************************/
   /* Keeping these outside a function i.e in global space results in errors. These initializations therfore need to be
    * within the definiton of a function. */  
   start.center.x = 0.0;

   // start.center.y = 0.0;  /* For cylinder and sphere */
   start.center.y = 0.0;      /*  For cone */
   start.center.z = 0.0;
   start.edge_len = 5.0;

   static GLfloat colorf[4] = {0.5, 0.8, 0.2, 1.0};
   static GLfloat colorb[4] = {0.2, 0.5, 0.5, 1.0};
   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,colorf);
   glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE,colorb);
   /****************************************************************************************************/

   /* Set the display function */
   glutDisplayFunc (&DrawGLScene);

   glutIdleFunc(&DrawGLScene);

   /* Set the reshape function */
   glutReshapeFunc (&ResizeGLScene);

   /* Set the keyboard function */
   glutKeyboardFunc (&keyboardPress);
   

   glEnable(GL_CULL_FACE);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);

   glLightfv (GL_LIGHT0, GL_POSITION, lightpos);
   glLightfv (GL_LIGHT0, GL_AMBIENT, lightcol);
   glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

   glMatrixMode(GL_MODELVIEW);
   
   glutMainLoop ();
   return 0;	
}
Example #27
0
int main(int argc, char **argv)
{
	struct aiLogStream stream;
    
    initGame();
    
	glutInitWindowSize(windowWidth, windowHeight);
	glutInitWindowPosition(100,100);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

	glutInit(&argc, argv);
    
	glutCreateWindow("Progetto OpenGL - Informatica Grafica");
	glutDisplayFunc(display);
	glutIdleFunc(display);
	glutKeyboardFunc(handleKeypress);
    glutPassiveMotionFunc(mouseMovement); //check for mouse movement
	glutMotionFunc(mouseMovement);
    glutReshapeFunc(handleResize);
    
    glutMouseFunc(handleMouseKeypress);
    
	// get a handle to the predefined STDOUT log stream and attach
	// it to the logging system. It will be active for all further
	// calls to aiImportFile(Ex) and aiApplyPostProcessing.
    
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	aiAttachLogStream(&stream);
    
	// ... exactly the same, but this stream will now write the
	// log file to assimp_log.txt
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	aiAttachLogStream(&stream);
	

	if (!InitGL()) {
		fprintf(stderr,"Initialization failed");
		return FALSE;
	}
    
	glutGet(GLUT_ELAPSED_TIME);
	glutMainLoop();
    
    cleanUp();
    
	// We added a log stream to the library, it's our job to disable it
	// again. This will definitely release the last resources allocated
	// by Assimp.
	aiDetachAllLogStreams();
    
	return 0;
}
Example #28
0
int main(int argc, char *argv[]) {	
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA);
glutInitWindowSize (kWindowWidth, kWindowHeight); 
glutInitWindowPosition (100, 100);
glutCreateWindow ("3D Rotation");	
InitGL(); 
glutDisplayFunc(DrawGLScene); 
glutReshapeFunc(ReSizeGLScene); 
/*new*/glutIdleFunc(idle);
glutMainLoop();
return 0;
}
Example #29
0
SDLScreen::SDLScreen()
{
	assert( m_sgSDLScreen == NULL );
	m_sgSDLScreen = this;

	act_alpha = 255;
	ratio = 1.0f;
	light_factor = 1.0f;
	m_kScreen = NULL;
	Init( Config::GetWidth(), Config::GetHeight(), Config::GetBPP() );
	ResizeWindow( Config::GetWidth(), Config::GetHeight() );
	InitGL();
}
Example #30
0
int main(int argc, char **argv) 
{  
	/* load our world from disk */
	SetupWorld();

	/* Initialize GLUT state - glut will take any command line arguments that pertain to it or 
	   X Windows - look at its documentation at http://reality.sgi.com/mjk/spec3/spec3.html */  
	glutInit(&argc, argv);  

	/* Select type of Display mode:   
	   Double buffer 
	   RGBA color
	   Depth buffer 
	   Alpha blending */  
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);  

	/* get a 640 x 480 window */
	glutInitWindowSize(640, 480);  

	/* the window starts at the upper left corner of the screen */
	glutInitWindowPosition(0, 0);  

	/* Open a window */  
	window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99");  

	/* Register the function to do all our OpenGL drawing. */
	glutDisplayFunc(&DrawGLScene);  

	/* Go fullscreen.  This is as soon as possible. */
	glutFullScreen();

	/* Even if there are no events, redraw our gl scene. */
	glutIdleFunc(&DrawGLScene); 

	/* Register the function called when our window is resized. */
	glutReshapeFunc(&ReSizeGLScene);

	/* Register the function called when the keyboard is pressed. */
	glutKeyboardFunc(&keyPressed);

	/* Register the function called when special keys (arrows, page down, etc) are pressed. */
	glutSpecialFunc(&specialKeyPressed);

	/* Initialize our window. */
	InitGL(640, 480);

	/* Start Event Processing Engine */  
	glutMainLoop();  

	return 1;
}