C programming

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
because my assignment got extra weight,i need to calculate the normal of the face.

vertex* vertex_array;
Face * face_array;

these are array i thought of

I am looking back at my java assignment 3 years ago:

somewhere along the line:

static int custCount = 0;
static Customer customers[] = new Customer[custCount];

it has code that can copy an array to another array

this was done before I did the actually proceed to do the linkedlist example

if this can be done I will be glad.

currently i am looking at this:

realloc - C++ Reference

update but strangely,when I do a vertex * array i check the size it is 4,
all i did is simply : vertex_array = (struct vertex*)malloc(0);

Like I have mentioned, discard away your Java semantics in C. Most of them will not work because C doesn't have all these features in the language. If you keep on locking yourself in what Java has offered and you are looking for equivalence in C, you will never be able to do C.

Realloc is to either expand the size of the allocated memory if it can be done, or copy the contents of existing memory block into a larger and return you a new pointer to new memory block and dealloc the previous one.

You are not encourage to use realloc as the means of expanding memory size since this is a very costly process and there are better data structures out there to serve your needs than to keep on resize your memory block.

Code:
vertex *array;

"array" is a pointer to a "vertex" type. As such, it is a variable that will contain memory addresses. 4 bytes = 32bits is correct on a 32bits arch system.

Unless you use the name of the array, then the compiler will resolve the 'sizeof' the name of the array as the size of the number of elements * sizeof(element type)

'sizeof' is not a runtime function, it is a compile type operator upon the type.
As such, if you are using dynamic memory allocation, 'sizeof' operator cannot resolve the size of the dynamic array, because it doesn't have any information of the size of the array before it's executed. At the same time, there is no compile time information about a dynamic memory allocation for 'sizeof' operator to work properly.

Code:
int *j;
j = malloc(10 * sizeof(int));
printf("%lu\n", sizeof(j));

Take note that while it is possible to address each element of the j pointer as such
Code:
printf("nth element value = %d\n", j[n]);
printf("nth element value = %d\n", *(j + n));

It actual fact, that doesn't make 'j' an array. It is just what you think. The square bracket notations are just sugar syntax for pointer arithmetic. They give programmer the idea of an array addressing technique, but in actual fact, it's nothing more than pointer addressing technique.

The 'sizeof' j is the size of the pointer, which is 4 bytes in 32bits system and and 8 bytes in 64bits system.

However the sizeof(*j) is most likely always 4bytes unless the C compiler choose otherwise for 'int' datatype to be of some other size.

sizeof(*j) in english is "size of where j is pointing to". Since 'j' is pointing to a 32bits integer, therefore the size is known at compile time to be 4bytes.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
I guess for next I need to implement a triangle mesh data structure,instead of storing all of them into array.

Triangle mesh - Wikipedia, the free encyclopedia

A triangle mesh is a type of polygon mesh in computer graphics. It comprises a set of triangles (typically in three dimensions) that are connected by their common edges or corners.

I guess,the 3 vertex that joins up together form the faces,and gradually it form the triangular mesh.

got to find out what is incident and adjacent to one another.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
I guess for next I need to implement a triangle mesh data structure,instead of storing all of them into array.

Triangle mesh - Wikipedia, the free encyclopedia

A triangle mesh is a type of polygon mesh in computer graphics. It comprises a set of triangles (typically in three dimensions) that are connected by their common edges or corners.

I guess,the 3 vertex that joins up together form the faces,and gradually it form the triangular mesh.

got to find out what is incident and adjacent to one another.

Well generally various file formats uses sets of triangular faces to form 3D models, such as STL. It's one of the simplest form to describe a non-geometric 3D object. You will find some file formats allow for parameterised geometric description of objects like Sphere, Cube etc. It is also possible to describe quadrilateral having 4 vertices all coincidental on the same plane.

Time to bring out your past knowledge on Vectors, cross products and dot products etc.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
Well generally various file formats uses sets of triangular faces to form 3D models, such as STL. It's one of the simplest form to describe a non-geometric 3D object. You will find some file formats allow for parameterised geometric description of objects like Sphere, Cube etc. It is also possible to describe quadrilateral having 4 vertices all coincidental on the same plane.

Time to bring out your past knowledge on Vectors, cross products and dot products etc.

vector,dot product, cross product I all know already,

need to figure out the triangle mesh data structure,

but my polygon mesh is just triangle,

i need help in explain half edge data structure,

it says I have to use it to implement triangle mesh,too difficult for me!
 
Last edited:

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
by the way first time I tried out the C program,i learn that functions must be placed on top of the main,

CTRL-C to stop the command lines

not much clue on what is clear colour buffer bits

I also know that mode got projection and perspective mode,

i wonder how I can integrate my assignment into this.

#include <iostream>
#include <GL/glut.h>

static int win;


void init(void){
//execute initialization procedure
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}

void Line_Segment(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0,0.0);
glBegin(GL_LINES);
glVertex2i( 180, 145 );
glVertex2i( 10, 145 );
glEnd();
glFlush();
}

int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
/*initialize glut window size and position*/
glutInitWindowSize(50,100);
glutInitWindowPosition(400,300);
win = glutCreateWindow("An Example OpenGL Program");//create display windows
// enter the main loop
init();
glutDisplayFunc(Line_Segment);
glutMainLoop();
}
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
vector,dot product, cross product I all know already,

need to figure out the triangle mesh data structure,

but my polygon mesh is just triangle,

i need help in explain half edge data structure,

it says I have to use it to implement triangle mesh,too difficult for me!

flipcode - The Half-Edge Data Structure

I doubt I can help much with using Half-Edge structures since I don't major in CG and its relevance. You will need to do more research on how to use this data structure properly to answer queries on a mesh.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
by the way first time I tried out the C program,i learn that functions must be placed on top of the main,

CTRL-C to stop the command lines

not much clue on what is clear colour buffer bits

I also know that mode got projection and perspective mode,

i wonder how I can integrate my assignment into this.

Your enquiries stretch across multiple domains.

First about C program structures. C/C++ programs of certain size and beyond normally don't just consist of 1 piece of source file. It is made up by a good number of source code files. Typically they exists as both header and source files.

Normally header files end with ".h" and source files end with ".c" in their names.
Header files consists of mainly declarations may it be function declaration, data structures declarations, global variables, types definitions and so forth. There are times inline functions are also found in header files.

There is not explicit rule to forbid what can or cannot be in the header files as long as they are syntactically correct of a C program. The reason why they exists is to exercise interfaces concepts across a project.

In header files, you will often see only declaration of functions and no implementation as such

Code:
#ifndef MYHEADER
#define MYHEADER

int sum(int, int);
int div(int, int);

#endif

The main source code can be as such
Code:
#include <stdio.h>
#include <stdlib.h>
#include "myheader.h"

int sum(int a, int b) {
  return a + b;
}

int div(int a, int b) {
  return a / b;
}

int main(int argc, char **argv) {
  printf("%d\n", sum(10, 3));
  return 0;
}

You probably wonder what is the value of having a header file with declaration of the functions and then you find the implementation source code also seems like redeclaring again. It seems rather redundant here because the problem is so small.

Imagine it is a project of 1000 source code files. One of these source files, 1 of them uses functions found in 3 different other source files. So your question about how do C handle the fact that all functions must be declare before it is used. Does it mean the functions need to be re-written through out the project ? Obviously it seems silly to do so. Why C set such a constraint ? It's mainly due to how compilation process handle typing and understanding which tokens are functions and which are operators and which are just plain text, and how the implementation of a function is linked between numerous caller functions that uses this one function.

Surely if the "sum" function is to be used across 10 other functions, then compiler need to know where to link from the other 10 functions to this one function right ? There is an egg and chicken problem. Why Java doesn't have this problem ? Well lets just say Java is a much later programming language, and it actually takes a lot more cycles and memory to compile a Java project corresponding to C given it compute the linkage on the fly in the memory using placeholders. Due to the constraint how C programming language is designed, the compiler can identify the type of the functions and validate if the function exist at a much earlier stage than Java.

Therefore instead of redeclaring "sum" numerous times across the project, other source files only require "include" the header file where "sum" function is declared. The C compiler can identify from the declaration that token "sum" is referring to a function that takes in 2 integer type parameters and one integer return type.
During compilation where type is decipher in C, there is no requirement to know the actual parameter name since it is just a placeholder to be used in the function implementation. Only the types are required and crucial to type checking, data space allocation in stacks for parameters to be passed from caller function to callee function and so forth. It's a complicated subject when coming to programming language compilation.

Normally you stick with perspective mode since it is how 3D space are mapped to 2D planes in real world situation. You use projection mode if you are dealing with applications that are CAD related or require visualisation with no perspective distortion when mapping from 3D to 2D.
Remember that what you see on the screen is a 2D plane. It is a 3D->2D rendering of your virtual 3D space.

Because of the 3D->2D mapping, there are various buffers during the process of conversion. Depth buffer or commonly known as Z-buffer store which pixel when rendered on 2D plane of a 3D plane is nearer to you. Imagine you have 2 faces that intersection each other as such
e010_01.gif


So how can the rendering process understand which part of the face is underneath the wood plane and which part is above ? As far as the mesh is concern, there is no extra edge to represent the intersection line between the 2 planes. There are only 7 vertices and 2 planes. Performing intersection operations is mathematically expensive process. Hence when converting from 3D point to 2D, raytracing take into consideration the distance from the screen to the intersection point of a plane that it is rendering. Consider the image above, part of the triangle is beneath the board. When the raytracing project a ray perpendicular to the screen hit part of the triangle that is beneath the board, the colour of either white or red is placed in the colour buffer. At the same time, the z-buffer gets the depth value of the 2D pixel. When it's time to render the wooden plane, eventually it will reach the same pixel that will place the brown colour on the colour buffer, but it will not do so unless the depth of the brown pixel is nearer to the screen than the previous pixel colour which correspond to a further z-buffer pixel value. That's how the illusion of intersection between the planes is achieved. Read this http://www.glprogramming.com/red/chapter10.html#name7

I think you really need more study on Computer Graphics subject since these are fundamentals of rendering process. That's why doing 3D projects is never really about OpenGL, it's about the concepts that map to the required functions in OpenGL to achieve the target.

I can't easily advice you on how to do a 3D project, you need to know what you want to do in the first place
 
Last edited:

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
struct HE_vert {
float x, y, z; // the vertex coordinates
HE_edge* edge; // one of the half-edges emanating from the vertex
};


void output(HE_vert* v){
printf("%f,%f,%f/n",v->x,v->y,v->z);
};

today I learn that must v->x instead of v.x otherwise will have class error

by the way how do I create vector in c?or how about matrix?just 3x3 array?

one more things,

visual studio,

seems to have a lot of this errors,

1>..\Lab1\MeshViewer.cpp(24): error C2143: syntax error : missing ';' before '*'
1>..\Lab1\MeshViewer.cpp(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Lab1\MeshViewer.cpp(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Lab1\MeshViewer.cpp(30): error C2143: syntax error : missing ';' before '*'
1>..\Lab1\MeshViewer.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Lab1\MeshViewer.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Along the way,

this is the first time I am using visual studio debugger,
I chance upon an error it ask me to debug the program using visual studio,it seems useful with all the auto and call stacks.
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
struct HE_vert {
float x, y, z; // the vertex coordinates
HE_edge* edge; // one of the half-edges emanating from the vertex
};


void output(HE_vert* v){
printf("%f,%f,%f/n",v->x,v->y,v->z);
};

today I learn that must v->x instead of v.x otherwise will have class error

Please take note that when you are using "struct" in a C++ compiler, it is analogous to a class with all its members private. It is not the same as a "struct" in C. You may want to read some of the gotchas at Differences Between C and C++ - Cprogramming.com

If possible, use a C compiler such as GCC, LCC-Win. If you want to use Visual C++, either mandate using /Tc compiler option or make sure your source code ends with ".c" extension.

The Type of a structure is "struct <type_identifier>" in C, not just the identifier alone. Please be strict about this. Hence when you wanted to declare a pointer to a struct in C, it should be "struct HE_vert vertex". Even in C++, pointers to structure must be "struct <type_identifier> *<identifier>", not "<type_identifier> *<identifier>"

Your "output" function declaration is syntactically wrong.

v->x is the same as (*v).x.

the 'dot' operator is to access the member of a structure. 'v' is not a structure. v is a pointer to a structure. Hence to get a structure type, you need to dereference 'v' as such *v. *v is of Type structure. The reason to wrap it around the round parenthesis is because 'dot' operator has a higher precedence than '*'(dereference operator). *v.x would be dereferencing 'x', the member of 'v' instead.

I hope this is clear to you.

by the way how do I create vector in c?or how about matrix?just 3x3 array?

What "vector" are you talking about, are you talking about the equivalence of a Java Vector class, or you are referring to the mathematical Vector type? If it is Java vector, then C doesn't have it. The closest is a block of memory called array. You will need to design your own extensible array with the help of "realloc" function, or get an external library that does it for you.

If it's a maethematical Vector that you are referring to, the following structure should serve your needs
Code:
struct _point {
  float x, y z;
};
struct _vec {
  struct _point p1, p2;
};

Another way of describing a mathematical Vector representing a matrix (x, y, z). It has no reference point though. If you want a reference point, you can always add one like this
Code:
struct _point {
  float x, y z;
};
struct _vec {
  struct _point ref_vert, direction;
};

one more things,

visual studio,

seems to have a lot of this errors,

1>..\Lab1\MeshViewer.cpp(24): error C2143: syntax error : missing ';' before '*'
1>..\Lab1\MeshViewer.cpp(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Lab1\MeshViewer.cpp(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Lab1\MeshViewer.cpp(30): error C2143: syntax error : missing ';' before '*'
1>..\Lab1\MeshViewer.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>..\Lab1\MeshViewer.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Can't help to identify your errors since I don't know what is the corresponding source code lines.

Along the way,

this is the first time I am using visual studio debugger,
I chance upon an error it ask me to debug the program using visual studio,it seems useful with all the auto and call stacks.

Well good you know of another good tool around. In GCC, you will find the command line equivalence called gdb. There are tons of much better tools available in Linux to help with your debugging.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
When I change to .c,

i got a couple of these

1>..\Lab1\MeshViewer.c(66): error C2143: syntax error : missing '{' before '*'
1>..\Lab1\MeshViewer.c(78): error C2143: syntax error : missing '{' before '*'
1>..\Lab1\MeshViewer.c(84): error C2065: 'vertex' : undeclared identifier
1>..\Lab1\MeshViewer.c(84): error C2059: syntax error : ')'
1>..\Lab1\MeshViewer.c(85): error C2065: 'face' : undeclared identifier
1>..\Lab1\MeshViewer.c(85): error C2059: syntax error : ')'

what are these?

I have access to lynda.com for free,because of the C tutorial.

Watch the Online Video Course C/C++ Essential Training

Have any one used them before and what is the feedback?

says I got an arrays of vertex and faces already,

I know rendering the vertex is just calling the glVertex3f and render them

but for face how?
 
Last edited:

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
when I tried to call the linesegment it works,
however after i call displayfunc cones on main block,it doesn't even show anything???

#include <GL/glut.h>
#include <stdio.h>

void init(void)
{
glClearColor(1.0 , 1.0 , 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
void lineSegment(void){
glClear(GL_COLOR_BUFFER_BIT); // clear display windows
glColor3f(0.0, 0.4,0.2);
glBegin(GL_LINES);
glVertex2i(180,45);
glVertex2i(10,145);
glEnd();
glFlush();
}

void cones(void){
/*cones*/
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glTranslatef(1.0,-0.5,0.5);
glPopMatrix();
glFlush();
}

void main(int argc,char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(50,100);
glutInitWindowSize(400,300);
glutCreateWindow("An Example Open GL Program");
init();
glutDisplayFunc(lineSegment);
glutDisplayFunc(cones);
glutMainLoop();
}
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
when I tried to call the linesegment it works,
however after i call displayfunc cones on main block,it doesn't even show anything???

Well obviously. That's because the way you use "glutDisplayFunc" is wrong.

Put this in mind. GLUT is a framework. GLUT is not OpenGL. It's a utility to help you create that windowed environment where you can perform your OpenGL operations in the window provided. GLUT doesn't know what is to be drawn in the window. You can draw a circle in it or a complex scene. Hence the idea of "glutDisplayFunc" is called function delegation.

GLUT assume you provide an implementation that will fill up the window with meaningful contents. Hence "glutDisplayFunc" is the way to take in a function that the developer will implement.

The most recent "glutDisplayFunc" will tell GLUT to use "cones" function to perform the job of display on the window, not the "lineSegment" function anymore. Your "cones" function is not performing any drawing at all, just clear the colour buffer and perform a translation only.

What do you want the screen to show in this case ? GLUT is an event driven architecture, exactly like how Windows GUI development is done
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
Now the codes below are a full working OpenGL program that I did for fun and also to show you a couple of things.

You can rotate on one-axis by holding your mouse button over the window and drag left and right.
I don't want to spend too much effort, but still want to show you how you can make your OpenGL project more interesting and more interactive.

This program allows you to read in PLY 3D file format of any 3D model you can download from the Internet and display them on the screen. However, you will need the PLY C library, which you can download from RPly: ANSI C library for PLY file format input and output

This is my compilation command, so you try and adapt to your own environment
Code:
gcc -framework GLUT -framework OPENGL -I/opt/X11/include -I. demo.c rply.c -o demo

To run the program
Code:
./demo horse.ply

For your ease of trying out what I did, I have packaged the source code and also the library and one sample PLY 3D model which you can download from trial.zip

Below is a screenshot of what you will see
241ko5w.png


demo.c
Code:
#include "rply.h"
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>

typedef struct _point {
  double x, y, z;
} Point;

typedef struct _face {
  unsigned int v1, v2, v3;
} Face;

Point *vertices = NULL;
Face *faces     = NULL;
int nfaces      = 0;
int nvertices   = 0;
int rx = 0, ry = 0, rz = 0;
double cx = 0, cy = 0, cz = 10;
int mousestate  = 1;
int mouseoldx   = 0;
int mouseoldy   = 0;

void init(void)
{
  glClearColor(0.0 , 0.0 , 0.0, 1.0);
  glMatrixMode(GL_PROJECTION);
  gluPerspective(10, 1, 0.1, 100);
}


void displayModel(void){


  glClear(GL_COLOR_BUFFER_BIT); // clear display windows

  glPushMatrix();
  gluLookAt(cx, cy, cz, 0, 0, 0, 0, 1, 0);
  
  glScalef(5, 5, 5);

  //GLUquadric *q = gluNewQuadric();
  //gluSphere(q, 1.0, 10, 10);
  int i;
  for (i = 0; i < nfaces; i++) {
    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_TRIANGLES);
    glVertex3d(vertices[faces[i].v1].x, vertices[faces[i].v1].y, vertices[faces[i].v1].z);
    glVertex3d(vertices[faces[i].v2].x, vertices[faces[i].v2].y, vertices[faces[i].v2].z);
    glVertex3d(vertices[faces[i].v3].x, vertices[faces[i].v3].y, vertices[faces[i].v3].z);
    glEnd();
  }

  glPopMatrix();

  glutSwapBuffers();
}

void mouseCB(int button, int state, int x, int y) {

  if (button == 0) {
    mouseoldx = x;
    mouseoldy = y;
    if (state == 0) {
      // press
    }
    else {
      // release
      glutPostRedisplay();
    }
    mousestate = state;
  }
}

void mouseMoveCB(int x, int y) {
  if (mousestate == 0) { //press
    ry = (ry + (x - mouseoldx)) % 360;
    rx = (rx + (y - mouseoldy)) % 360;
    cz = 10 * sin((ry + 90)* M_PI / 180);
    cx = 10 * sin(ry * M_PI / 180);
    glutPostRedisplay();
  }
  mouseoldx = x;
  mouseoldy = y;
}

int plycb_vertex(p_ply_argument arg) {
    long mode;
    Point **ppt;
    ply_get_argument_user_data(arg, (void*)&ppt, &mode);
    switch(mode) {
      case 1: //x
        (*ppt)->x = ply_get_argument_value(arg);
        break;
      case 2: //y
        (*ppt)->y = ply_get_argument_value(arg);
        break;
      case 3: //z
        (*ppt)->z = ply_get_argument_value(arg);
        (*ppt)++;
        break;
    }
    return 1;
}

int plycb_face(p_ply_argument arg) {
    long length, value_index;
    ply_get_argument_property(arg, NULL, &length, &value_index);

    Face **pface;
    ply_get_argument_user_data(arg, (void*)&pface, NULL);

    switch (value_index) {
      case 0:
        (*pface)->v1 = (unsigned int)ply_get_argument_value(arg);
      case 1: 
        (*pface)->v2 = (unsigned int)ply_get_argument_value(arg);
        break;
      case 2:
        (*pface)->v3 = (unsigned int)ply_get_argument_value(arg);
        (*pface)++;
        break;
    }
    return 1;
}

int main(int argc, char** argv){

  // open the 3D model
  p_ply fh;
  fh = ply_open(argv[1], NULL, 0, NULL);
  if (!fh) return 1;

  // read headers and set the callbacks
  Point *curr_vert = NULL;
  Face *curr_face  = NULL;
  ply_read_header(fh);
  nvertices = ply_set_read_cb(fh, "vertex", "x", plycb_vertex, &curr_vert, 1);
  ply_set_read_cb(fh, "vertex", "y", plycb_vertex, &curr_vert, 2);
  ply_set_read_cb(fh, "vertex", "z", plycb_vertex, &curr_vert, 3);
  nfaces    = ply_set_read_cb(fh, "face", "vertex_indices", plycb_face, &curr_face, 0);
  // create the array to contain the vertices and faces
  vertices = (Point*)malloc(sizeof(Point) * nvertices);
  faces    = (Face*)malloc(sizeof(Face) * nfaces);
  curr_vert = vertices;
  curr_face = faces;
  ply_read(fh);
  ply_close(fh);

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowPosition(50,100);
  glutInitWindowSize(1000,1000);
  glutCreateWindow("PLY Reader");
  init();
  glutMouseFunc(mouseCB);
  glutMotionFunc(mouseMoveCB);
  glutDisplayFunc(displayModel);
  glutMainLoop();

  return 0;
}
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
Just a few more pieces of information for you.
Why is the horse flat ? That's because the faces have no NORMALS. NORMALS are the facing of the planes. It is not necessary that the actual facing of the planes must be perpendicular to the planes. If you have heard of bump mapping in 3D rendering or in games, you will understand that it is possible to create fake 3D like texture on an object with large number of faces without creating the actual faces. This is done by twisting the normals so that the raytracer will shade the face using different values of reflection.

Without the normals, the lighting in OpenGL will not be able to render the shades of the faces. That's why they all appear flat white. This will be your homework if you want a much better looking 3D model.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
hi,if i take out the linesegment for glutdisplayfunction will it work?

#36,important for me,because I need to motion and mouse motion
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,300
hi,if i take out the linesegment for glutdisplayfunction will it work?

#36,important for me,because I need to motion and mouse motion

You can try take out. Then you look at your cones function, is it doing anything useful ? There is nothing really so wrong about what you did, you can always delegate the display function to another function, the question is "Is that what you want?"

There is nothing wrong with multiple display functions you know ? But why are you doing this for this case ?
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
You can try take out. Then you look at your cones function, is it doing anything useful ? There is nothing really so wrong about what you did, you can always delegate the display function to another function, the question is "Is that what you want?"

There is nothing wrong with multiple display functions you know ? But why are you doing this for this case ?

so i just need to remove one of them
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top