Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include<GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> #include <windows.h> #include<math.h> #include "BmpLoader.h" const int width = 1000; const int height = 1000; GLfloat eyeX = 0; GLfloat eyeY = 6; GLfloat eyeZ = -13; GLfloat lookX = 0; GLfloat lookY = 5; GLfloat lookZ = 0; GLfloat alpha = 0.0, theta = 0.0, axis_x=0.0, axis_y=0.0 , f_spin=0.0; GLboolean bRotate = false, uRotate = false; bool press1 = false; bool press2 = false; bool press4 = false; bool flagRot = false; float rot = 0; unsigned int ID; float px=0,py=30,pz=30,spot_cutoff = 30; static GLfloat v_cube[8][3] = { {0,0,0}, {0,0,1}, {0,1,0}, {0,1,1}, {1,0,0}, {1,0,1}, {1,1,0}, {1,1,1} }; static GLubyte c_ind[6][4] = { {3,1,5,7}, //front {6,4,0,2}, //back {2,3,7,6}, //top {1,0,4,5}, //bottom {7,5,4,6}, //right {2,0,1,3} //left }; static void getNormal3p(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2, GLfloat x3, GLfloat y3, GLfloat z3) { GLfloat Ux, Uy, Uz, Vx, Vy, Vz, Nx, Ny, Nz; Ux = x2-x1; Uy = y2-y1; Uz = z2-z1; Vx = x3-x1; Vy = y3-y1; Vz = z3-z1; Nx = Uy*Vz - Uz*Vy; Ny = Uz*Vx - Ux*Vz; Nz = Ux*Vy - Uy*Vx; glNormal3f(Nx,Ny,Nz); } void set_material(float R=0.5, float G=0.5, float B=0.5, bool e=false , bool l = false) { GLfloat mat_no[] = {0,0,0, 1.0}; GLfloat mat_amb[] = {R,G,B,1}; GLfloat mat_diff[] = {R,G,B,1}; GLfloat mat_spec[] = {1,1,1,1}; GLfloat mat_sh[] = {30}; GLfloat mat_em[] = {1,1,1,1}; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_amb); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec); glMaterialfv(GL_FRONT, GL_SHININESS, mat_sh); if(e && l) { glMaterialfv(GL_FRONT, GL_EMISSION, mat_em); } else { glMaterialfv(GL_FRONT, GL_EMISSION, mat_no); } } void cube(float R=0.5, float G=0.5, float B=0.5, bool e=false, bool l = false) { set_material(R,G,B,l); glBegin(GL_QUADS); for (GLint i = 0; i <6; i++) { getNormal3p(v_cube[c_ind[i][0]][0], v_cube[c_ind[i][0]][1], v_cube[c_ind[i][0]][2], v_cube[c_ind[i][1]][0], v_cube[c_ind[i][1]][1], v_cube[c_ind[i][1]][2], v_cube[c_ind[i][2]][0], v_cube[c_ind[i][2]][1], v_cube[c_ind[i][2]][2]); glTexCoord2f(0,1); glVertex3fv(&v_cube[c_ind[i][0]][0]); glTexCoord2f(0,0); glVertex3fv(&v_cube[c_ind[i][1]][0]); glTexCoord2f(1,0); glVertex3fv(&v_cube[c_ind[i][2]][0]); glTexCoord2f(1,1); glVertex3fv(&v_cube[c_ind[i][3]][0]); } glEnd(); } void axes() { float length = 10; float width = 0.3; // X-axis glPushMatrix(); glTranslatef(length/2,0,0); glScalef(length,width,width); glTranslatef(-0.5,-0.5,-0.5); cube(0.8,0.1,0.1); glPopMatrix(); // Y-axis glPushMatrix(); glTranslatef(0,length/2,0); glScalef(width,length,width); glTranslatef(-0.5,-0.5,-0.5); cube(0.1,0.8,0.1); glPopMatrix(); // Z-axis glPushMatrix(); glTranslatef(0,0,length/2); glScalef(width,width,length); glTranslatef(-0.5,-0.5,-0.5); cube(0.1,0.1,0.8); glPopMatrix(); } void rodshape1() { float t_length = 6; float t_width = 0.5; glPushMatrix(); //glTranslatef(-14.5,7,0); glTranslatef(-14.5,7,0); glPushMatrix(); glScalef(t_width,t_width,t_length); glTranslatef(-0.5,0,-0.5); cube(1,1,1,true,press1); glPopMatrix(); glPushMatrix(); glTranslatef(0,0,t_length/2+t_width/2); glScalef(t_width,t_width,t_width); glTranslatef(-0.5,0,-0.5); cube(0.2,0.2,0.2); glPopMatrix(); glPushMatrix(); glTranslatef(0,0,-t_length/2-t_width/2); glScalef(t_width,t_width,t_width); glTranslatef(-0.5,0,-0.5); cube(0.2,0.2,0.2); glPopMatrix(); glPopMatrix(); } void rodshape2() { float t_length = 6; float t_width = 0.5; glPushMatrix(); //glTranslatef(-14.5,7,0); glTranslatef(14,7,10); glPushMatrix(); glScalef(t_width,t_width,t_length); glTranslatef(-0.5,0,-0.5); cube(1,1,1,true,press2); glPopMatrix(); glPushMatrix(); glTranslatef(0,0,t_length/2+t_width/2); glScalef(t_width,t_width,t_width); glTranslatef(-0.5,0,-0.5); cube(0.2,0.2,0.2); glPopMatrix(); glPushMatrix(); glTranslatef(0,0,-t_length/2-t_width/2); glScalef(t_width,t_width,t_width); glTranslatef(-0.5,0,-0.5); cube(0.2,0.2,0.2); glPopMatrix(); glPopMatrix(); } void spotlightshape() { float s_height = 0.25; float s_width = 2; float s_length = 2; glPushMatrix(); glTranslatef(7,9,7); /* glPushMatrix(); glScalef(s_width,s_height,s_length); glTranslatef(-0.5,0,-0.5); cube(1,1,1); glPopMatrix(); */ glPushMatrix(); glScalef(s_width,s_height,s_length); glTranslatef(-0.5,0,-0.5); cube(1,1,1,true,press4); glPopMatrix(); glPopMatrix(); } void light1() { //light GLfloat l1_no[] = {0, 0, 0, 1.0}; GLfloat l1_amb[] = {0.1, 0.1, 0.1, 1.0}; GLfloat l1_dif[] = {1,1,1,1}; GLfloat l1_spec[] = {1,1,1,1}; GLfloat l1_pos[] = {-14.5,7,0,1.0}; //GLfloat l_pos[] = {-14.5,-7,10,1.0}; glEnable(GL_LIGHT0); if(press1) { glLightfv(GL_LIGHT0, GL_AMBIENT, l1_amb); } else { glLightfv(GL_LIGHT0, GL_AMBIENT, l1_no); } if(press1) { glLightfv(GL_LIGHT0, GL_DIFFUSE, l1_dif); } else { glLightfv(GL_LIGHT0, GL_DIFFUSE, l1_no); } if(press1) { glLightfv(GL_LIGHT0, GL_SPECULAR, l1_spec); } else { glLightfv(GL_LIGHT0, GL_SPECULAR, l1_no); } glLightfv(GL_LIGHT0, GL_POSITION, l1_pos); } void light2() { //light GLfloat l2_no[] = {0, 0, 0, 1.0}; GLfloat l2_amb[] = {0.1, 0.1, 0.1, 1.0}; GLfloat l2_dif[] = {1,1,1,1}; GLfloat l2_spec[] = {1,1,1,1}; //GLfloat l_pos[] = {-14.5,7,0,1.0}; GLfloat l2_pos[] = {14,-7,10,1.0}; glEnable(GL_LIGHT1); if(press2) { glLightfv(GL_LIGHT1, GL_AMBIENT, l2_amb); } else { glLightfv(GL_LIGHT1, GL_AMBIENT, l2_no); } if(press2) { glLightfv(GL_LIGHT1, GL_DIFFUSE, l2_dif); } else { glLightfv(GL_LIGHT1, GL_DIFFUSE, l2_no); } if(press2) { glLightfv(GL_LIGHT1, GL_SPECULAR, l2_spec); } else { glLightfv(GL_LIGHT1, GL_SPECULAR, l2_no); } glLightfv(GL_LIGHT1, GL_POSITION, l2_pos); } void light3() { //light GLfloat l3_no[] = {0, 0, 0, 1.0}; GLfloat l3_amb[] = {0.5, 0.5, 0.5, 1.0}; GLfloat l3_dif[] = {1,1,1,1}; GLfloat l3_spec[] = {1,1,1,1}; GLfloat l3_pos[] = {px,py,pz,1.0}; //GLfloat l_pos[] = {14,-7,10,1.0}; glEnable(GL_LIGHT2); if(press4) { glLightfv(GL_LIGHT2, GL_AMBIENT, l3_amb); } else { glLightfv(GL_LIGHT2, GL_AMBIENT, l3_no); } if(press4) { glLightfv(GL_LIGHT2, GL_DIFFUSE, l3_dif); } else { glLightfv(GL_LIGHT2, GL_DIFFUSE, l3_no); } if(press4) { glLightfv(GL_LIGHT2, GL_SPECULAR, l3_spec); } else { glLightfv(GL_LIGHT2, GL_SPECULAR, l3_no); } glLightfv(GL_LIGHT2, GL_POSITION, l3_pos); // spot light extra GLfloat l3_spt[] = {0,0,-1,1}; GLfloat spt_ct[] = {spot_cutoff}; glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, l3_spt); glLightfv(GL_LIGHT2, GL_SPOT_CUTOFF, spt_ct); } void LoadTexture(const char*filename) { glGenTextures(1, &ID); glBindTexture(GL_TEXTURE_2D, ID); glPixelStorei(GL_UNPACK_ALIGNMENT, ID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); BmpLoader bl(filename); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, bl.iWidth, bl.iHeight, GL_RGB, GL_UNSIGNED_BYTE, bl.textureData ); } static void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-3, 3, -3, 3, 2.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX,eyeY,eyeZ, lookX,lookY,lookZ, 0,1,0); //glViewport(0, 0, width, height); glRotatef(rot, 0,1,0); axes(); ///Main Road glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,1); glPushMatrix(); glScalef(10,0.2,50); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Grass glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,2); glPushMatrix(); glScalef(1000,0.1,1000); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Fence Left glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,3); glPushMatrix(); glTranslatef(30,0,25); glScalef(50,5,0.1); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Fence Right glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,3); glPushMatrix(); glTranslatef(-30,0,25); glScalef(50,5,0.1); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Building Front Right glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,4); glPushMatrix(); glTranslatef(-25,0,35); glScalef(40,40,0.1); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Building Front Left glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,4); glPushMatrix(); glTranslatef(25,0,35); glScalef(40,40,0.1); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Building Right glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,4); glPushMatrix(); glTranslatef(-45,0,65); glScalef(0.1,40,60); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Building Left glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,4); glPushMatrix(); glTranslatef(45,0,65); glScalef(0.1,40,60); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Building Back Left glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,4); glPushMatrix(); glTranslatef(25,0,95); glScalef(40,40,0.1); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); ///Building Back Right glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,4); glPushMatrix(); glTranslatef(-25,0,95); glScalef(40,40,0.1); glTranslatef(-0.5,-0.5,-0.5); cube(1,1,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); glutSwapBuffers(); } void animate() { glutPostRedisplay(); } static void key(unsigned char key, int x, int y) { switch (key) { case 27 : case 'q': exit(0); break; case 'w': eyeZ++; lookZ++; break; case 's': eyeZ--; lookZ--; break; case 'a': eyeX++; lookX++; break; case 'd': eyeX--; lookX--; break; case 'u': eyeY++; lookY++; break; case 'j': eyeY--; lookY--; break; case '.': rot--; break; case ',': rot++; break; } glutPostRedisplay(); } static void idle(void) { glutPostRedisplay(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(width,height); glutInitWindowPosition(10,10); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glEnable(GL_LIGHTING); glutCreateWindow("1607006"); glutDisplayFunc(display); glutKeyboardFunc(key); glutIdleFunc(animate); //glutSpecialFunc(collision); //glutIdleFunc(idle); //glutReshapeFunc(res); // glClearColor(1,1,1,1); glEnable(GL_DEPTH_TEST); glShadeModel( GL_SMOOTH ); glEnable(GL_NORMALIZE); glEnable(GL_BLEND); printf(" Use 'w' to look up, 's' to look down, 'd' to look right, and 'a' to look left.\n"); printf(" Press '1' for right light turn on,\n Press '2' for left light turn on, \n Press '3' to turn on both light, \n Press '4' to turn on spotlight.\n"); LoadTexture("C:\\Users\\road.bmp"); LoadTexture("C:\\Users\\grass.bmp"); LoadTexture("C:\\Users\\fence.bmp"); LoadTexture("C:\\Users\\window.bmp"); glutMainLoop(); return EXIT_SUCCESS; }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
MAGA250
1 hour ago | 1.48 KB
Nightlight - Imprisoning Pitch
10 hours ago | 0.54 KB
Ombric - Astral Projection
10 hours ago | 0.77 KB
Katherine/Nightlight - Reindeer
11 hours ago | 1.03 KB
Djinni - Swords
11 hours ago | 0.44 KB
Djinni - Limits
11 hours ago | 0.62 KB
Djinni - Throw
11 hours ago | 1.44 KB
Djinni - Boulders
11 hours ago | 0.49 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!