Open GL Create 4 Views Like 3ds max or maya - c++

How can I Create a 4 views (LEFT/TOP/PERSPECTIVE/FRONT) in Open GL ??
I Have Used this :
int main(int c,char ** argv)
{
glutInit(&c,argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH |GLUT_RGB );
glutInitWindowSize(w,h);
MainWin =glutCreateWindow("Teapot Window");
glutDisplayFunc(display);
LeftWin = glutCreateSubWindow(MainWin,0,0,s_window_w,s_window_h);
glutDisplayFunc(displayLeft);
glutReshapeFunc(reshapeLeft);
TopWin = glutCreateSubWindow(MainWin,s_window_w+3,0,s_window_w,s_window_h);
glutDisplayFunc(displayTop);
glutReshapeFunc(reshapeTop);
PerspectiveWin = glutCreateSubWindow(MainWin,0,s_window_h+3,s_window_w,s_window_h);
glutDisplayFunc(displayPerspective);
glutReshapeFunc(reshapePerspective);
FrontWin = glutCreateSubWindow(MainWin,s_window_w+3,s_window_h+3,s_window_w,s_window_h);
glutDisplayFunc(displayFront);
glutReshapeFunc(reshapeFront);
glutMainLoop();
return 0;
}
Then I have make the projection for top and left and like this :
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5f,0.5f,-0.35f,0.35f,1,500);
When I use the top lines for the front also , the output is something like this :
Where is my fault ?
thanks in advance
Why the Front view is empty and the perspective and left view are same ??
For perspective projection i had used glFrustum ....
So Am I going wrong ?
Please help on creating multiple views like 3ds max or maya ...
below is the code for display functions:
void displayLeft()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,-1,0,0,0,0,1,0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,light_pos);
glShadeModel(GL_SMOOTH);
glClearColor(0.2f,0.3f,0.4f,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glTranslatef(teapot_x,teapot_y,teapot_z);
glRotatef(teapot_angle,0,1,0);
glColor3f(0,1,0);
glutSolidTeapot(0.2f);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void displayTop()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,-1,0,0,0,0,0,0,-1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,light_pos);
glShadeModel(GL_SMOOTH);
glClearColor(0.2f,0.3f,0.4f,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glTranslatef(teapot_x,teapot_y,teapot_z);
glRotatef(teapot_angle,0,1,0);
glColor3f(0,1,0);
glutSolidTeapot(0.2f);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void displayFront()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,0,0,0,0,1,0,0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,light_pos);
glShadeModel(GL_SMOOTH);
glClearColor(0.2f,0.3f,0.4f,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glTranslatef(teapot_x,teapot_y,teapot_z);
glRotatef(teapot_angle,0,1,0);
glColor3f(0,1,0);
glutSolidTeapot(0.2f);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void displayPerspective()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,-1,0,0,0,0,1,0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,light_pos);
glShadeModel(GL_SMOOTH);
glClearColor(0.2f,0.3f,0.4f,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glTranslatef(teapot_x,teapot_y,teapot_z);
glRotatef(0,0,1,0);
glColor3f(0,1,0);
glutSolidTeapot(0.2f);
glPopMatrix();
glFlush();
glutSwapBuffers();
}

Use glViewport and glScissor to cut out panes of the window. Then for each pane perform the rendering as usual. Setting the projection matrix is actually a drawing state operation, so it belongs into the display function, not reshape.
Your display function should become something like
void ViewportScissor(int x, int y, int width, int height)
{
glViewport(x, y, width, height);
glScissor(x, y, width, height);
}
void display(void)
{
int const win_width = glutGet(GLUT_WINDOW_WIDTH);
int const win_height = glutGet(GLUT_WINDOW_HEIGHT);
glDisable(GL_SCISSOR);
glClear(…);
glEnable(GL_SCISSOR);
ViewportScissor(0, 0, win_width/2, win_height/2);
glMatrixMode(GL_PROJECTION);
setup_frontview_projection();
glMatrixMode(GL_MODELVIEW);
setup_frontview();
draw_scene();
ViewportScissor(win_width/2, 0, win_width/2, win_height/2);
glMatrixMode(GL_PROJECTION);
setup_rightview_projection();
glMatrixMode(GL_MODELVIEW);
setup_rightview();
draw_scene();
ViewportScissor(0, win_height/2, win_width/2, win_height/2);
glMatrixMode(GL_PROJECTION);
setup_topview_projection();
glMatrixMode(GL_MODELVIEW);
setup_topview();
draw_scene();
ViewportScissor(win_width/2, win_height/2, win_width/2, win_height/2);
glMatrixMode(GL_PROJECTION);
setup_freecamview_projection();
glMatrixMode(GL_MODELVIEW);
setup_freecamview();
draw_scene();
glutSwapBuffers();
}
Adding splitter lines/frames is left as an exercise for the reader.

Related

How can I display two shapes instead of one by using C++ OpenGL Glut?

I started to use OpenGL / glut for C++ and I am stuck on being able to display two objects in the window rather than one. So, for the first shape it draws a house-like shape with a square and triangle on the top, with anti-aliasing. The second shape, is supposed to be the same, but does not have anti-aliasing. For now, the second shape just has two dots as opposed to the entire shape. When I have both of the withoutAntiAliasing and withAntiAliasing methods inside of the void render() method, only one shows. How exactly can I make it so that both of the methods described can be shown in the window? Code is below:
#include <GL/glut.h>
void init()
{
glClearColor(1.0, 1.0, 1.0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 250.0, 0.0, 250.0);
}
void withAntiAliasing()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_LINE_LOOP);
glVertex2i(155, 150);
glVertex2i(125, 125);
glVertex2f(108.5, 162);
glVertex2f(136, 185);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(100, 155.9);
glVertex2f(145, 192.5);
glVertex2i(115, 185);
glEnd();
glFlush();
}
void withoutAntiAliasing()
{
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
glBegin(GL_POINTS);
glColor3f(0, 0, 0);
glVertex2i(170, 170);
glColor3f(0, 0, 0);
glVertex2i(150, 150);
glEnd();
glFlush();
}
void render()
{
glColor3f(0.0, 0.0, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
withoutAntiAliasing();
withAntiAliasing();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Hey");
init();
glutDisplayFunc(render);
glutMainLoop();
}
If you want to draw lines, you must use Line primitives instead of Point primitives.
The first mesh is not displayed because you clear the framebuffer before drawing the second mesh.
Move glClear and glFlush in the render function and use the primitive type GL_LINE_LOOP:
void withAntiAliasing()
{
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_LINE_LOOP);
glVertex2i(155, 150);
glVertex2i(125, 125);
glVertex2f(108.5, 162);
glVertex2f(136, 185);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(100, 155.9);
glVertex2f(145, 192.5);
glVertex2i(115, 185);
glEnd();
}
void withoutAntiAliasing()
{
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
glBegin(GL_LINE_LOOP);
glColor3f(0, 0, 0);
glVertex2i(170, 170);
glColor3f(0, 0, 0);
glVertex2i(150, 150);
glEnd();
}
void render()
{
glColor3f(0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
withoutAntiAliasing();
withAntiAliasing();
glFlush();
}

creating a 3d room in openGL c++

I am trying to create a 3d room in openGL. I am getting the right and bottom walls right but the back wall is not being displayed. I want to create a 3d room with camera view set to certain angle and place a table and teapot in the room.
Code:
#include<GL/glut.h>
void wall(double thickness) // function to create the walls with given thickness
{
glPushMatrix();
glTranslated(0.5,0.5*thickness,0.5);
glScaled(1.0,thickness,1.0);
glutSolidCube(1.0);
glPopMatrix();
}
void displaySolid(){ //function to create a 3d room
GLfloat mat_ambient[]={0.7f,0.7f,0.7f,0.1f};
GLfloat mat_diffuse[]={0.5f,0.5f,0.5f,1.0f};
GLfloat mat_specular[]={1.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloat light_Intensity[]={0.7f,0.7f,0.7f,1.0f};
GLfloat light_Position[]={2.0f,6.0f,3.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_Position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_Intensity);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double winlet=1.0;
glOrtho(-winlet*64/48,winlet*64/48.0,-winlet*64/48,winlet*64/48,0.6,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2.3,1.38,2.0,0.0,0.25,0.0,0.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslated(0.08,0.08,0.08);
glPushMatrix();
glTranslated(0.6,0.38,0.5);
glRotated(30,0,1,0);
glPopMatrix();
glPushMatrix();
glTranslated(0.25,0.42,0.35);
glPopMatrix();
glPushMatrix();
glTranslated(0.4,0,0.4);
glPopMatrix();
wall(0.2);
glPushMatrix();
glRotated(-90.0,1.0,0.0,0.0);
wall(0.02);
glPopMatrix();
glFlush();
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("the pot");
glutDisplayFunc(displaySolid);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glClearColor(0.1,0.1,0.1,0.0);
glViewport(0,0,640,480);
glutMainLoop();
}
//end
This how ever is giving a black screen on the back side of the 3D cube room.I have set the lightning effect to LIGHT0, yet i am not able to see the side wall.
The wall function had been called only twice as pointed out.So Here's the fix.
void displaySolid(){
GLfloat mat_ambient[]={0.7f,0.7f,0.7f,0.1f};
GLfloat mat_diffuse[]={0.5f,0.5f,0.5f,1.0f};
GLfloat mat_specular[]={1.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloat light_Intensity[]={0.7f,0.7f,0.7f,1.0f};
GLfloat light_Position[]={2.0f,6.0f,3.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_Position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_Intensity);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double winlet=1.0;
glOrtho(-winlet*64/48,winlet*64/48.0,-winlet*64/48,winlet*64/48,0.6,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2.3,1.38,2.0,0.0,0.25,0.0,0.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslated(0.08,0.08,0.08);
glPushMatrix();
glTranslated(0.6,0.38,0.5);
glRotated(30,0,1,0);
glutSolidTeapot(0.08);
glPopMatrix();
glPushMatrix();
glTranslated(0.25,0.42,0.35);
glPopMatrix();
glPushMatrix();
glTranslated(0.4,0,0.4);
glPopMatrix();
wall(0.2);
glPushMatrix();
glRotated(-90.0,1.0,0.0,0.0);
wall(0.02);
glPopMatrix();
glRotated(90.0,0.0,0.0,180.0);
wall(0.02);
glPopMatrix();
glFlush();
}
This is how the final 3d room looks like:

Opengl 2d resizing

My origin is not at top left corner, when I resize my window. And the 2d coordinates are not in pixel coordinates:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
rnd::initDraw();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, mainPanelx, mainPanely, 0.0, -1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
//glPushMatrix(); ----Not sure if I need this
glLoadIdentity();
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0);
glVertex2f(0.0, 0.0);
glVertex2f(10.0, 0.0);
glVertex2f(10.0, 10.0);
glVertex2f(0.0, 10.0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glutSwapBuffers();
Resize function:
void resize(int width, int height)
{
if (height == 0) height = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* note we divide our width by our height to get the aspect ratio */
gluPerspective(45.0, width / height, 1.0, 400.0);
glMatrixMode(GL_MODELVIEW);
mainPanelx = width;
mainPanely = height;
std::cout<<mainPanelx<<", "<<mainPanely<<"\n";
}
How do i get the origin constant at the top left corner of my window and how do i get the 2d coordinates in pixel coordinates?
You forgot to call glViewport in your resize function.
This means OpenGL will still render to the old sized viewport.

How to draw multiple cubes in OpenGL

I want to draw several cubes using glutSolidCube in some points in space. The examples I have found just call glutSolidCube and it works, but the only way a cube gets drawn for me is if the line is enclosed in glBegin(GL_POLYGON), which isn't required in the examples I've seen, and I only get one cube instead of several. What I have is:
glColor3f(1, 0, 0);
glLoadIdentity();
glTranslatef(5,2,1);
glutSolidCube(1);
glLoadIdentity();
glTranslatef(10,8,0);
glutSolidCube(1);
glLoadIdentity();
glTranslatef(3,7,9);
glutSolidCube(1);
glLoadIdentity();
glTranslatef(1,4,6);
glutSolidCube(1);
When I run this nothing happens. I know there's not a problem with the points being outside my view because if I draw vertices at the same points, I can see them. As far as I can tell from the examples and documentation I've read, I'm not doing anything incorrect. Can someone tell me what I'm doing wrong or give me a snippet of code that draws multiple cubes?
Try this:
glColor3f(1, 0, 0);
glPushMatrix();
glTranslatef(5,2,1);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(10,8,0);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(3,7,9);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(1,4,6);
glutSolidCube(1);
glPopMatrix();
Without re-setting the model view matrix with glLoadIdentity(). Note that to start with you need to call glOrtho() or glPerspective() to set the camera once.
#include <GL/glut.h>
void init()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
double aspect = (double)viewport[2] / (double)viewport[3];
gluPerspective(60, aspect, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// move back a bit
glTranslatef( 0, 0, -35 );
static float angle = 0;
angle += 1.0f;
glPushMatrix();
glTranslatef(0,0,0);
glRotatef(angle, 0.1, 0.2, 0.5);
glColor3ub(255,0,255);
glutSolidCube(5);
glPopMatrix();
glPushMatrix();
glTranslatef(10,-10,0);
glRotatef(angle, 0.1, 0.2, 0.5);
glColor3ub(255,0,0);
glutSolidCube(5);
glPopMatrix();
glPushMatrix();
glTranslatef(10,10,0);
glRotatef(angle, 0.1, 0.2, 0.5);
glColor3ub(0,255,0);
glutSolidCube(5);
glPopMatrix();
glPushMatrix();
glTranslatef(-10,10,0);
glRotatef(angle, 0.1, 0.2, 0.5);
glColor3ub(0,0,255);
glutSolidCube(5);
glPopMatrix();
glPushMatrix();
glTranslatef(-10,-10,0);
glRotatef(angle, 0.1, 0.2, 0.5);
glColor3ub(255,255,0);
glutSolidCube(5);
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
}
void timer(int extra)
{
glutPostRedisplay();
glutTimerFunc(16, timer, 0);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("CUBES");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(0, timer, 0);
init();
glutMainLoop();
return 0;
}

Why doesn't glCopyTexSubImage2D copy my square correctly?

here is the output: http://i43.tinypic.com/9a5zyx.png
if things were working the way i wanted, the colors in the left square would match the colors in the right square. thanks for any help regarding the subject
#include <gl/glfw.h>
const char* title="test";
GLuint img;
unsigned int w=64,h=64;
int screenwidth,screenheight;
void enable2d()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glViewport(0,0,screenwidth,screenheight);
glOrtho(0,screenwidth,screenheight,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_LIGHTING_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
}
void drawmytex()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,img);
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex2i(0,0);
glTexCoord2i(1,0);
glVertex2i(w,0);
glTexCoord2i(1,1);
glVertex2i(w,h);
glTexCoord2i(0,1);
glVertex2i(0,h);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void drawquad(int x,int y)
{
glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex2i(x,y);
glColor3f(1.0f,0.0f,1.0f);
glVertex2i(x+w,y);
glColor3f(0.0f,1.0f,1.0f);
glVertex2i(x+w,y+h);
glColor3f(0.0f,0.0f,1.0f);
glVertex2i(x,y+h);
glEnd();
}
void texcopy()
{
if (!glIsTexture(img))
glDeleteTextures(1,&img);
glGenTextures(1,&img);
glBindTexture(GL_TEXTURE_2D,img);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,h,0,-1,1);
glViewport(0,0,w,h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
drawquad(0,0);
glBindTexture(GL_TEXTURE_2D,img);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
//glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,w,h,0);
glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,screenwidth,screenheight,0,-1,1);
glViewport(0,0,screenwidth,screenheight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main()
{
int running;
glfwInit();
running=glfwOpenWindow(640,480,0,0,0,0,0,0,GLFW_WINDOW);
if (!running)
{
glfwTerminate();
return 0;
}
glfwSetWindowTitle(title);
glfwEnable(GLFW_STICKY_KEYS);
glfwGetWindowSize(&screenwidth,&screenheight);
enable2d();
texcopy();
do
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
drawquad(64,0);
drawmytex();
glfwSwapBuffers();
running=!glfwGetKey(GLFW_KEY_ESC)&&glfwGetWindowParam(GLFW_OPENED);
GLenum error=glGetError();
if (error!=GL_NO_ERROR)running=error;
glfwSleep(.017);
}
while (running==1);
glDeleteTextures(1,&img);
glfwTerminate();
return running;
}
Try adding 'glColor3f(1,1,1);' in your 'drawmytex' function. I suspect that your texture is modulated (multiplied) with the current color, if so, the problem is not the texture copy but the way you display it.