Mac OSX build OpenGL Super Treasure 5 (Lan Baoshu) development environment (run the first triangle program)

Source: Internet
Author: User

1. Download the resources of the OpenGL Super Treasure 5 (Lan Baoshu), the link is as follows: Http://pan.baidu.com/s/1c02PtYC, extract SB5 folder, there are books of course source code and Gltools Library.

2. Tap Xcode-->preferences-->locations-->sources Trees, then click the "+" button to add Name:gltools_include, Display Name: Gltools include folder, Path: ~/desktop/sb5/src/gltools/include (i unzipped the SB5 folder on the desktop, readers can add according to their own situation).

Create a new cocoa project under 3.Xcode, name Triangle, delete appdelegate.* two files and main.m files under project.

4. Click on the item-->targets-->build settings-->header Search Paths, add $ (gltools_include), then click on the Item-->targets-- >build Phases-->link Binary with Libraries, click "+" to add, Glut.framework,opengl.framework, click Add Other to add the desktop/sb5/src/ GLTOOLS/LIBGLTOOLS.A file

5. Right-click the project-->new file-->c++ file, add a Triangle.cpp (no header file required), copy the following code:

////Triangle.cpp//Triangle////Created by Tank on 15/8/11.//Copyright (c) 2015 jinx. All rights reserved.////Triangle.cpp//Our first OpenGL program, that would just draw a triangle on the screen.#include<GLTools.h>//OpenGL Toolkit#include <GLShaderManager.h>//Shader Manager Class#ifdef __apple__#include<glut/glut.h>//OS X version of GLUT#else#defineFreeglut_static#include<GL/glut.h>//Windows Freeglut equivalent#endifGlbatch Trianglebatch; Glshadermanager Shadermanager;/////////////////////////////////////////////////////////////////////////////////Window has changed size, or has just been created. In either case, we need//To use the window dimensions to set the viewport and the projection matrix.voidChangesize (intWinth) {Glviewport (0,0, W, h);}/////////////////////////////////////////////////////////////////////////////////This function does any needed initialization on the rendering context.//This is the first opportunity to does any OpenGL related tasks.voidSETUPRC () {//Blue BackgroundGlclearcolor (0.0f,0.0f,1.0f,1.0f );        Shadermanager.initializestockshaders (); //Load up a triangleGlfloat vverts[] = {-0.5f,0.0f,0.0f,        0.5f,0.0f,0.0f,                          0.0f,0.5f,0.0f }; Trianglebatch.begin (Gl_triangles,3);    trianglebatch.copyvertexdata3f (Vverts); Trianglebatch.end ();}/////////////////////////////////////////////////////////////////////////////////called to draw scenevoidRenderscene (void){    //Clear the window with current clearing colorGlclear (Gl_color_buffer_bit | Gl_depth_buffer_bit |gl_stencil_buffer_bit); Glfloat vred[]= {1.0f,0.0f,0.0f,1.0f };    Shadermanager.usestockshader (glt_shader_identity, vRed);        Trianglebatch.draw (); //Perform the buffer swap to display back bufferglutswapbuffers ();}/////////////////////////////////////////////////////////////////////////////////Main entry point for GLUT based programsintMainintargcChar*argv[]) {Gltsetworkingdirectory (argv[0]); Glutinit (&argc, argv); Glutinitdisplaymode (glut_double| Glut_rgba | glut_depth |glut_stencil); Glutinitwindowsize ( -, -); Glutcreatewindow ("Triangle");    Glutreshapefunc (changesize);        Glutdisplayfunc (Renderscene); Glenum Err=Glewinit (); if(Glew_ok! =err) {fprintf (stderr,"glew Error:%s\n", glewgeterrorstring (err)); return 1;        } SETUPRC ();    Glutmainloop (); return 0;}

6.cmd + R runs, you can see:

OK, the first triangle successfully appeared (PS: I first write a blog, cough cough, a lot of imperfect, forgive me oh).

=======================================================

Original articles, reproduced please specify http://www.cnblogs.com/cheergo/, mail [email protected], welcome you and I start to communicate!

=======================================================

Mac OSX build OpenGL Super Treasure 5 (Lan Baoshu) development environment (run the first triangle program)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.