Skip to content

Commit 263fc1e

Browse files
committed
texture methods
1 parent ef95257 commit 263fc1e

File tree

7 files changed

+166
-4
lines changed

7 files changed

+166
-4
lines changed

OpenGL_T5/OpenGL_T5.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
1FE3E3A719A0A5B100DF3ABB /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FE3E3A619A0A5B100DF3ABB /* main.cpp */; };
1111
1FE3E3A919A0A5B100DF3ABB /* OpenGL_T5.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1FE3E3A819A0A5B100DF3ABB /* OpenGL_T5.1 */; };
12+
1FE3E3B119A0A60800DF3ABB /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FE3E3AF19A0A60800DF3ABB /* GLUT.framework */; };
13+
1FE3E3B219A0A60800DF3ABB /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FE3E3B019A0A60800DF3ABB /* OpenGL.framework */; };
1214
/* End PBXBuildFile section */
1315

1416
/* Begin PBXCopyFilesBuildPhase section */
@@ -28,13 +30,18 @@
2830
1FE3E3A319A0A5B100DF3ABB /* OpenGL_T5 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OpenGL_T5; sourceTree = BUILT_PRODUCTS_DIR; };
2931
1FE3E3A619A0A5B100DF3ABB /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
3032
1FE3E3A819A0A5B100DF3ABB /* OpenGL_T5.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = OpenGL_T5.1; sourceTree = "<group>"; };
33+
1FE3E3AF19A0A60800DF3ABB /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/GLUT.framework; sourceTree = DEVELOPER_DIR; };
34+
1FE3E3B019A0A60800DF3ABB /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/OpenGL.framework; sourceTree = DEVELOPER_DIR; };
35+
1FE3E3B319A0A79800DF3ABB /* imageloader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = imageloader.h; sourceTree = "<group>"; };
3136
/* End PBXFileReference section */
3237

3338
/* Begin PBXFrameworksBuildPhase section */
3439
1FE3E3A019A0A5B100DF3ABB /* Frameworks */ = {
3540
isa = PBXFrameworksBuildPhase;
3641
buildActionMask = 2147483647;
3742
files = (
43+
1FE3E3B119A0A60800DF3ABB /* GLUT.framework in Frameworks */,
44+
1FE3E3B219A0A60800DF3ABB /* OpenGL.framework in Frameworks */,
3845
);
3946
runOnlyForDeploymentPostprocessing = 0;
4047
};
@@ -44,6 +51,8 @@
4451
1FE3E39A19A0A5B100DF3ABB = {
4552
isa = PBXGroup;
4653
children = (
54+
1FE3E3AF19A0A60800DF3ABB /* GLUT.framework */,
55+
1FE3E3B019A0A60800DF3ABB /* OpenGL.framework */,
4756
1FE3E3A519A0A5B100DF3ABB /* OpenGL_T5 */,
4857
1FE3E3A419A0A5B100DF3ABB /* Products */,
4958
);
@@ -62,6 +71,7 @@
6271
children = (
6372
1FE3E3A619A0A5B100DF3ABB /* main.cpp */,
6473
1FE3E3A819A0A5B100DF3ABB /* OpenGL_T5.1 */,
74+
1FE3E3B319A0A79800DF3ABB /* imageloader.h */,
6575
);
6676
path = OpenGL_T5;
6777
sourceTree = "<group>";
@@ -197,14 +207,18 @@
197207
1FE3E3AD19A0A5B100DF3ABB /* Debug */ = {
198208
isa = XCBuildConfiguration;
199209
buildSettings = {
210+
MACOSX_DEPLOYMENT_TARGET = 10.8;
200211
PRODUCT_NAME = "$(TARGET_NAME)";
212+
SDKROOT = macosx10.8;
201213
};
202214
name = Debug;
203215
};
204216
1FE3E3AE19A0A5B100DF3ABB /* Release */ = {
205217
isa = XCBuildConfiguration;
206218
buildSettings = {
219+
MACOSX_DEPLOYMENT_TARGET = 10.8;
207220
PRODUCT_NAME = "$(TARGET_NAME)";
221+
SDKROOT = macosx10.8;
208222
};
209223
name = Release;
210224
};

OpenGL_T5/OpenGL_T5.xcodeproj/project.xcworkspace/xcshareddata/OpenGL_T5.xccheckout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
66
<false/>
77
<key>IDESourceControlProjectIdentifier</key>
8-
<string>06069645-6B46-4F3A-ABC9-16CF36344B4F</string>
8+
<string>20249D2C-ABA3-4068-B954-E018DACC5F6A</string>
99
<key>IDESourceControlProjectName</key>
1010
<string>OpenGL_T5</string>
1111
<key>IDESourceControlProjectOriginsDictionary</key>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
</Bucket>

OpenGL_T5/OpenGL_T5/imageloader.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// imageloader.h
3+
// OpenGL_T5
4+
//
5+
// Created by Lokesh Basu on 17/08/14.
6+
// Copyright (c) 2014 Samsung. All rights reserved.
7+
//
8+
9+
#ifndef OpenGL_T5_imageloader_h
10+
#define OpenGL_T5_imageloader_h
11+
12+
13+
class Image
14+
{
15+
public:
16+
Image(char *ps, int w, int h);
17+
~Image();
18+
19+
char *pixels;
20+
int width;
21+
int height;
22+
};
23+
24+
Image *loadBMP(const char *filename);
25+
26+
#endif

OpenGL_T5/OpenGL_T5/main.cpp

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,130 @@
66
// Copyright (c) 2014 Samsung. All rights reserved.
77
//
88

9+
#include <GLUT/glut.h>
10+
#include <OpenGL/gl.h>
11+
#include <OpenGL/glu.h>
12+
#include <stdlib.h>
913
#include <iostream>
14+
#include "imageloader.h"
1015

11-
int main(int argc, const char * argv[])
16+
using namespace std;
17+
18+
void handleKeyPress(unsigned char key, int x, int y)
19+
{
20+
switch (key)
21+
{
22+
case 27:
23+
exit(0);
24+
}
25+
}
26+
27+
GLuint loadTexture(Image *image)
28+
{
29+
GLuint textureId;
30+
glGenTextures(1, &textureId); //make room for our texture
31+
glBindTexture(GL_TEXTURE_2D, textureId); //tell OpenGL which texture to edit
32+
//map the image to the texture
33+
glTexImage2D(GL_TEXTURE_2D, //always GL_TEXTURE_2D
34+
0, //0 for now
35+
GL_RGB, //format OpenGL uses for image
36+
image->width, //width
37+
image->height, //height
38+
0, //the border of the image
39+
GL_RGB, //GL_RGB because pixels are stored in RGB format
40+
GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE because pixels are stored as unsigned numbers
41+
image->pixels); //the actual pixel data
42+
43+
44+
return textureId; //return the id of the texture
45+
}
46+
47+
GLuint _textureId; //The id of the texture
48+
49+
void initRendering()
50+
{
51+
glEnable(GL_DEPTH_TEST);
52+
glEnable(GL_COLOR_MATERIAL);
53+
glEnable(GL_LIGHTING); //enable lighting
54+
glEnable(GL_LIGHT0); //enable light #0
55+
glEnable(GL_NORMALIZE); //automatically normalize normals
56+
57+
Image *image = loadBMP("splash.bmp");
58+
_textureId = loadTexture(image);
59+
delete image;
60+
}
61+
62+
// called when window is resized
63+
void handleResize(int w, int h)
64+
{
65+
// tells opengl how to convert form coordinates to pixel values
66+
glViewport(0, 0, w, h);
67+
68+
glMatrixMode(GL_PROJECTION); //switch to setting the camera perspective
69+
70+
// setting the camera perspective
71+
glLoadIdentity(); // reset the camera
72+
gluPerspective(45.0 // the camera angle
73+
, (double)w/(double)h // the width to height ratio
74+
, 1 // the near z clipping co-ordinate
75+
, 200); // the far z clipping co-ordinate
76+
}
77+
78+
float _angle = -70.0f;
79+
80+
// drwas the 3D scene
81+
void drawScene()
1282
{
83+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84+
85+
glMatrixMode(GL_MODELVIEW);
86+
glLoadIdentity();
87+
88+
glTranslatef(0.0f, 0.0f, -8.0f);
89+
90+
//add ambient light
91+
GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f};
92+
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
93+
94+
GLfloat directedLight[] = {0.7f, 0.7f, 0.7f, 1.0f};
95+
GLfloat directedLightPos[] = {-10.0f, 15.0f, 20.0f, 1.0f};
96+
glLightfv(GL_LIGHT0, GL_DIFFUSE, directedLight);
97+
glLightfv(GL_LIGHT0, GL_POSITION, directedLightPos);
98+
99+
glEnable(GL_TEXTURE_2D);
100+
glBindTexture(GL_TEXTURE_2D, _textureId);
101+
102+
}
13103

14-
// insert code here...
15-
std::cout << "Hello, World!\n";
104+
void update(int value)
105+
{
106+
_angle += 2.0f;
107+
if (_angle > 360) {
108+
_angle -= 360;
109+
}
110+
111+
glutPostRedisplay();
112+
glutTimerFunc(25, update, 0);
113+
}
114+
115+
int main(int argc, char * argv[])
116+
{
117+
// initialize glut
118+
glutInit(&argc, argv);
119+
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
120+
glutInitWindowSize(400, 400); // set the window size
121+
122+
// create the window
123+
glutCreateWindow("Lighting");
124+
initRendering(); // initialize rendering
125+
126+
// set handler function for drawing, keypress and window resizes
127+
glutDisplayFunc(drawScene);
128+
glutKeyboardFunc(handleKeyPress);
129+
glutReshapeFunc(handleResize);
130+
131+
glutTimerFunc(25, update, 0);
132+
glutMainLoop(); // start the main loop. glutMainLoop doesn't return.
16133
return 0;
17134
}
18135

OpenGL_T5/OpenGL_T5/splash.bmp

440 KB
Binary file not shown.

0 commit comments

Comments
 (0)